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 __importDefault = (this && this.__importDefault) || function (mod) {
|
36 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
37 | };
|
38 | var __importStar = (this && this.__importStar) || function (mod) {
|
39 | if (mod && mod.__esModule) return mod;
|
40 | var result = {};
|
41 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
42 | result["default"] = mod;
|
43 | return result;
|
44 | };
|
45 | Object.defineProperty(exports, "__esModule", { value: true });
|
46 | var Popover_1 = __importDefault(require("@material-ui/core/Popover"));
|
47 | var withStyles_1 = __importDefault(require("@material-ui/core/styles/withStyles"));
|
48 | var clsx_1 = __importDefault(require("clsx"));
|
49 | var PropTypes = __importStar(require("prop-types"));
|
50 | var React = __importStar(require("react"));
|
51 | var react_event_listener_1 = __importDefault(require("react-event-listener"));
|
52 | var DateTextField_1 = __importDefault(require("../_shared/DateTextField"));
|
53 | var dimensions_1 = require("../constants/dimensions");
|
54 | var InlineWrapper = (function (_super) {
|
55 | __extends(InlineWrapper, _super);
|
56 | function InlineWrapper() {
|
57 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
58 | _this.state = {
|
59 | anchorEl: null,
|
60 | };
|
61 | _this.open = function (e) {
|
62 | _this.setState({ anchorEl: e.currentTarget });
|
63 | if (_this.props.onOpen) {
|
64 | _this.props.onOpen();
|
65 | }
|
66 | };
|
67 | _this.close = function () {
|
68 | _this.setState({ anchorEl: null });
|
69 | _this.props.handleAccept();
|
70 | if (_this.props.onClose) {
|
71 | _this.props.onClose();
|
72 | }
|
73 | };
|
74 | _this.handleKeyDown = function (event) {
|
75 | switch (event.key) {
|
76 | case 'Enter': {
|
77 | _this.props.handleAccept();
|
78 | _this.close();
|
79 | break;
|
80 | }
|
81 | default:
|
82 |
|
83 | return;
|
84 | }
|
85 |
|
86 | event.preventDefault();
|
87 | };
|
88 | return _this;
|
89 | }
|
90 | InlineWrapper.getDerivedStateFromProps = function (nextProps) {
|
91 |
|
92 | if (nextProps.isAccepted) {
|
93 | if (nextProps.onClose) {
|
94 | nextProps.onClose();
|
95 | }
|
96 | return {
|
97 | anchorEl: null,
|
98 | };
|
99 | }
|
100 | return null;
|
101 | };
|
102 | InlineWrapper.prototype.render = function () {
|
103 | var _a;
|
104 | var _b = this.props, value = _b.value, format = _b.format, children = _b.children, onOpen = _b.onOpen, onClose = _b.onClose, PopoverProps = _b.PopoverProps, isAccepted = _b.isAccepted, keyboard = _b.keyboard, onlyCalendar = _b.onlyCalendar, classes = _b.classes, handleAccept = _b.handleAccept, wider = _b.wider, other = __rest(_b, ["value", "format", "children", "onOpen", "onClose", "PopoverProps", "isAccepted", "keyboard", "onlyCalendar", "classes", "handleAccept", "wider"]);
|
105 | var isOpen = Boolean(this.state.anchorEl);
|
106 | return (React.createElement(React.Fragment, null,
|
107 | isOpen && React.createElement(react_event_listener_1.default, { target: "window", onKeyDown: this.handleKeyDown }),
|
108 | React.createElement(DateTextField_1.default, __assign({ value: value, format: format, onClick: this.open, keyboard: keyboard }, other)),
|
109 | React.createElement(Popover_1.default, __assign({ id: "picker-popover", open: isOpen, anchorEl: this.state.anchorEl, onClose: this.close, classes: {
|
110 | paper: clsx_1.default(classes.popoverPaper, (_a = {}, _a[classes.popoverPaperWider] = wider, _a)),
|
111 | }, anchorOrigin: {
|
112 | vertical: 'bottom',
|
113 | horizontal: keyboard ? 'right' : 'center',
|
114 | }, transformOrigin: {
|
115 | vertical: 'top',
|
116 | horizontal: keyboard ? 'right' : 'center',
|
117 | }, children: children }, PopoverProps))));
|
118 | };
|
119 | InlineWrapper.propTypes = {
|
120 | onlyCalendar: PropTypes.bool,
|
121 | onOpen: PropTypes.func,
|
122 | onClose: PropTypes.func,
|
123 | PopoverProps: PropTypes.object,
|
124 | };
|
125 | InlineWrapper.defaultProps = {
|
126 | value: new Date(),
|
127 | onlyCalendar: false,
|
128 | isAccepted: false,
|
129 | };
|
130 | return InlineWrapper;
|
131 | }(React.PureComponent));
|
132 | exports.InlineWrapper = InlineWrapper;
|
133 | exports.styles = {
|
134 | popoverPaper: {
|
135 | width: dimensions_1.DIALOG_WIDTH,
|
136 | paddingBottom: 8,
|
137 | },
|
138 | popoverPaperWider: {
|
139 | width: dimensions_1.DIALOG_WIDTH_WIDER,
|
140 | },
|
141 | };
|
142 | exports.default = withStyles_1.default(exports.styles)(InlineWrapper);
|