UNPKG

@iobroker/adapter-react-v5

Version:

React components to develop ioBroker interfaces with react.

83 lines 4.32 kB
/** * Copyright 2019-2024 Denis Haev (bluefox) <dogafox@gmail.com> * * MIT License * */ // please do not delete React, as without it other projects could not be compiled: ReferenceError: React is not defined import React, { Component } from 'react'; import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, FormControlLabel, Checkbox, } from '@mui/material'; import { Check as IconCheck, Close as IconClose } from '@mui/icons-material'; import { I18n } from '../i18n'; const styles = { suppress: { fontSize: 12, }, suppressRoot: { // it is sx marginTop: '16px', }, }; export class DialogConfirm extends Component { constructor(props) { super(props); if (!this.props.dialogName && this.props.suppressQuestionMinutes) { throw new Error('dialogName required if suppressQuestionMinutes used'); } let suppress = false; if (this.props.suppressQuestionMinutes) { suppress = parseInt((window._localStorage || window.localStorage).getItem(this.props.dialogName), 10) || 0; if (!suppress) { suppress = false; } else if (Date.now() > suppress) { (window._localStorage || window.localStorage).removeItem(this.props.dialogName); suppress = false; } } this.state = { suppress, }; } handleOk() { if (this.state.suppress) { (window._localStorage || window.localStorage).setItem(this.props.dialogName, Date.now() + (this.props.suppressQuestionMinutes || 2) * 60000); } if (this.props.onClose) { this.props.onClose(true); } } handleCancel() { if (this.props.onClose) { this.props.onClose(false); } } render() { if (typeof this.state.suppress === 'number') { setTimeout(() => this.props.onClose && this.props.onClose(true), 100); return null; } return (React.createElement(Dialog, { open: !0, maxWidth: "md", fullWidth: this.props.fullWidth !== undefined ? this.props.fullWidth : true, onClose: (event, reason) => { if (reason !== 'backdropClick' && reason !== 'escapeKeyDown') { this.handleCancel(); } }, "aria-labelledby": "ar_confirmation_dialog_title", "aria-describedby": "ar_confirmation_dialog_description" }, React.createElement(DialogTitle, { id: "ar_confirmation_dialog_title" }, this.props.title || I18n.t('ra_Are you sure?')), React.createElement(DialogContent, null, React.createElement(DialogContentText, { id: "ar_confirmation_dialog_description" }, this.props.icon || null, this.props.text, this.props.suppressQuestionMinutes ? React.createElement("br", null) : null, this.props.suppressQuestionMinutes ? (React.createElement(FormControlLabel, { sx: { '& .FormControlLabel-label': styles.suppress, '&.FormControlLabel-root': styles.suppressRoot, }, control: React.createElement(Checkbox, { id: `ar_dialog_confirm_suppress_${this.props.dialogName || ''}`, checked: !!this.state.suppress, onChange: () => this.setState({ suppress: !this.state.suppress }) }), label: this.props.suppressText || I18n.t('ra_Suppress question for next %s minutes', (this.props.suppressQuestionMinutes || 2).toString()) })) : null)), React.createElement(DialogActions, null, React.createElement(Button, { id: `ar_dialog_confirm_ok_${this.props.dialogName || ''}`, variant: "contained", onClick: () => this.handleOk(), color: "primary", autoFocus: true, startIcon: React.createElement(IconCheck, null) }, this.props.ok || I18n.t('ra_Ok')), React.createElement(Button, { id: `ar_dialog_confirm_cancel_${this.props.dialogName || ''}`, variant: "contained", onClick: () => this.handleCancel(), color: "grey", startIcon: React.createElement(IconClose, null) }, this.props.cancel || I18n.t('ra_Cancel'))))); } } //# sourceMappingURL=Confirm.js.map