1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | };
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | var __assign = (this && this.__assign) || function () {
|
16 | __assign = Object.assign || function(t) {
|
17 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
18 | s = arguments[i];
|
19 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
20 | t[p] = s[p];
|
21 | }
|
22 | return t;
|
23 | };
|
24 | return __assign.apply(this, arguments);
|
25 | };
|
26 | var __rest = (this && this.__rest) || function (s, e) {
|
27 | var t = {};
|
28 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
29 | t[p] = s[p];
|
30 | if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
31 | for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
32 | t[p[i]] = s[p[i]];
|
33 | return t;
|
34 | };
|
35 | var __importStar = (this && this.__importStar) || function (mod) {
|
36 | if (mod && mod.__esModule) return mod;
|
37 | var result = {};
|
38 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
39 | result["default"] = mod;
|
40 | return result;
|
41 | };
|
42 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
43 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
44 | };
|
45 | Object.defineProperty(exports, "__esModule", { value: true });
|
46 | var PropTypes = __importStar(require("prop-types"));
|
47 | var React = __importStar(require("react"));
|
48 | var DateTextField_1 = __importDefault(require("../_shared/DateTextField"));
|
49 | var ModalDialog_1 = __importDefault(require("../_shared/ModalDialog"));
|
50 | var ModalWrapper = (function (_super) {
|
51 | __extends(ModalWrapper, _super);
|
52 | function ModalWrapper() {
|
53 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
54 | _this.state = {
|
55 | open: false,
|
56 | };
|
57 | _this.handleKeyDown = function (event) {
|
58 | switch (event.key) {
|
59 | case 'Enter':
|
60 | _this.handleAccept();
|
61 | break;
|
62 | default:
|
63 |
|
64 | return;
|
65 | }
|
66 |
|
67 | event.preventDefault();
|
68 | };
|
69 | _this.handleSetTodayDate = function () {
|
70 | if (_this.props.onSetToday) {
|
71 | _this.props.onSetToday();
|
72 | }
|
73 | };
|
74 | _this.open = function () {
|
75 | _this.setState({ open: true });
|
76 | if (_this.props.onOpen) {
|
77 | _this.props.onOpen();
|
78 | }
|
79 | };
|
80 | _this.close = function () {
|
81 | _this.setState({ open: false });
|
82 | if (_this.props.onClose) {
|
83 | _this.props.onClose();
|
84 | }
|
85 | };
|
86 | _this.handleAccept = function () {
|
87 | _this.close();
|
88 | if (_this.props.onAccept) {
|
89 | _this.props.onAccept();
|
90 | }
|
91 | };
|
92 | _this.handleDismiss = function () {
|
93 | _this.close();
|
94 | if (_this.props.onDismiss) {
|
95 | _this.props.onDismiss();
|
96 | }
|
97 | };
|
98 | _this.handleClear = function () {
|
99 | _this.close();
|
100 | if (_this.props.onClear) {
|
101 | _this.props.onClear();
|
102 | }
|
103 | };
|
104 | return _this;
|
105 | }
|
106 | ModalWrapper.getDerivedStateFromProps = function (nextProps) {
|
107 |
|
108 | if (nextProps.isAccepted) {
|
109 | if (nextProps.onClose) {
|
110 | nextProps.onClose();
|
111 | }
|
112 | return {
|
113 | open: false,
|
114 | };
|
115 | }
|
116 | return null;
|
117 | };
|
118 | ModalWrapper.prototype.render = function () {
|
119 | var _a = this.props, value = _a.value, format = _a.format, children = _a.children, onAccept = _a.onAccept, onDismiss = _a.onDismiss, invalidLabel = _a.invalidLabel, labelFunc = _a.labelFunc, okLabel = _a.okLabel, cancelLabel = _a.cancelLabel, clearLabel = _a.clearLabel, clearable = _a.clearable, todayLabel = _a.todayLabel, showTodayButton = _a.showTodayButton, onOpen = _a.onOpen, onClose = _a.onClose, onSetToday = _a.onSetToday, isAccepted = _a.isAccepted, DialogProps = _a.DialogProps, showTabs = _a.showTabs, wider = _a.wider, other = __rest(_a, ["value", "format", "children", "onAccept", "onDismiss", "invalidLabel", "labelFunc", "okLabel", "cancelLabel", "clearLabel", "clearable", "todayLabel", "showTodayButton", "onOpen", "onClose", "onSetToday", "isAccepted", "DialogProps", "showTabs", "wider"]);
|
120 | return (React.createElement(React.Fragment, null,
|
121 | React.createElement(DateTextField_1.default, __assign({ value: value, format: format, onClick: this.open, invalidLabel: invalidLabel, labelFunc: labelFunc, clearable: clearable }, other)),
|
122 | React.createElement(ModalDialog_1.default, __assign({ wider: wider, showTabs: showTabs, open: this.state.open, onKeyDownInner: this.handleKeyDown, onClear: this.handleClear, onAccept: this.handleAccept, onDismiss: this.handleDismiss, onSetToday: this.handleSetTodayDate, clearLabel: clearLabel, todayLabel: todayLabel, okLabel: okLabel, cancelLabel: cancelLabel, clearable: clearable, showTodayButton: showTodayButton, children: children }, DialogProps))));
|
123 | };
|
124 | ModalWrapper.propTypes = {
|
125 | okLabel: PropTypes.node,
|
126 | cancelLabel: PropTypes.node,
|
127 | clearLabel: PropTypes.node,
|
128 | clearable: PropTypes.bool,
|
129 | todayLabel: PropTypes.node,
|
130 | showTodayButton: PropTypes.bool,
|
131 | onOpen: PropTypes.func,
|
132 | DialogProps: PropTypes.object,
|
133 | onClose: PropTypes.func,
|
134 | };
|
135 | ModalWrapper.defaultProps = {
|
136 | value: new Date(),
|
137 | okLabel: 'OK',
|
138 | cancelLabel: 'Cancel',
|
139 | clearLabel: 'Clear',
|
140 | todayLabel: 'Today',
|
141 | clearable: false,
|
142 | showTodayButton: false,
|
143 | isAccepted: false,
|
144 | };
|
145 | return ModalWrapper;
|
146 | }(React.PureComponent));
|
147 | exports.default = ModalWrapper;
|