UNPKG

dash-core-components

Version:

Core component suite for Dash

92 lines (90 loc) 3.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _ConfirmDialog = _interopRequireDefault(require("./ConfirmDialog.react")); var _LoadingElement = _interopRequireDefault(require("../utils/LoadingElement")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } /** * A wrapper component that will display a confirmation dialog * when its child component has been clicked on. * * For example: * ``` * dcc.ConfirmDialogProvider( * html.Button('click me', id='btn'), * message='Danger - Are you sure you want to continue.' * id='confirm') * ``` */ class ConfirmDialogProvider extends _react.default.Component { render() { var _this$props = this.props, displayed = _this$props.displayed, id = _this$props.id, setProps = _this$props.setProps, children = _this$props.children; // Will lose the previous onClick of the child var wrapClick = child => /*#__PURE__*/_react.default.cloneElement(child, { onClick: () => setProps({ displayed: true }) }); return /*#__PURE__*/_react.default.createElement(_LoadingElement.default, { id: id }, Array.isArray(children) ? children.map(wrapClick) : wrapClick(children), /*#__PURE__*/_react.default.createElement(_ConfirmDialog.default, _extends({}, this.props, { displayed: displayed }))); } } exports.default = ConfirmDialogProvider; ConfirmDialogProvider.defaultProps = { submit_n_clicks: 0, submit_n_clicks_timestamp: -1, cancel_n_clicks: 0, cancel_n_clicks_timestamp: -1 }; ConfirmDialogProvider.propTypes = { /** * The ID of this component, used to identify dash components * in callbacks. The ID needs to be unique across all of the * components in an app. */ id: _propTypes.default.string, /** * Message to show in the popup. */ message: _propTypes.default.string, /** * Number of times the submit was clicked */ submit_n_clicks: _propTypes.default.number, /** * Last time the submit button was clicked. */ submit_n_clicks_timestamp: _propTypes.default.number, /** * Number of times the popup was canceled. */ cancel_n_clicks: _propTypes.default.number, /** * Last time the cancel button was clicked. */ cancel_n_clicks_timestamp: _propTypes.default.number, /** * Is the modal currently displayed. */ displayed: _propTypes.default.bool, /** * Dash-assigned callback that gets fired when the value changes. */ setProps: _propTypes.default.func, /** * The children to hijack clicks from and display the popup. */ children: _propTypes.default.any };