1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.DateTimePicker = void 0;
|
19 | var tslib_1 = require("tslib");
|
20 | var classnames_1 = tslib_1.__importDefault(require("classnames"));
|
21 | var React = tslib_1.__importStar(require("react"));
|
22 | var core_1 = require("@blueprintjs/core");
|
23 | var Classes = tslib_1.__importStar(require("./common/classes"));
|
24 | var DateUtils = tslib_1.__importStar(require("./common/dateUtils"));
|
25 | var datePicker_1 = require("./datePicker");
|
26 | var timePicker_1 = require("./timePicker");
|
27 |
|
28 | var DateTimePicker = (function (_super) {
|
29 | tslib_1.__extends(DateTimePicker, _super);
|
30 | function DateTimePicker(props, context) {
|
31 | var _this = _super.call(this, props, context) || this;
|
32 | _this.handleDateChange = function (dateValue, isUserChange) {
|
33 | var _a, _b;
|
34 | if (_this.props.value === undefined) {
|
35 | _this.setState({ dateValue: dateValue });
|
36 | }
|
37 | var value = DateUtils.getDateTime(dateValue, _this.state.timeValue);
|
38 | (_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, value, isUserChange);
|
39 | };
|
40 | _this.handleTimeChange = function (timeValue) {
|
41 | var _a, _b;
|
42 | if (_this.props.value === undefined) {
|
43 | _this.setState({ timeValue: timeValue });
|
44 | }
|
45 | var value = DateUtils.getDateTime(_this.state.dateValue, timeValue);
|
46 | (_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, value, true);
|
47 | };
|
48 | var initialValue = _this.props.value !== undefined ? _this.props.value : _this.props.defaultValue;
|
49 | _this.state = {
|
50 | dateValue: initialValue,
|
51 | timeValue: initialValue,
|
52 | };
|
53 | return _this;
|
54 | }
|
55 | DateTimePicker.prototype.render = function () {
|
56 | var value = DateUtils.getDateTime(this.state.dateValue, this.state.timeValue);
|
57 | return (React.createElement("div", { className: (0, classnames_1.default)(Classes.DATETIMEPICKER, this.props.className) },
|
58 | React.createElement(datePicker_1.DatePicker, tslib_1.__assign({}, this.props.datePickerProps, { canClearSelection: this.props.canClearSelection, onChange: this.handleDateChange, value: value })),
|
59 | React.createElement(timePicker_1.TimePicker, tslib_1.__assign({}, this.props.timePickerProps, { onChange: this.handleTimeChange, value: this.state.timeValue }))));
|
60 | };
|
61 | DateTimePicker.prototype.componentDidUpdate = function (prevProps) {
|
62 | if (this.props.value === prevProps.value) {
|
63 | return;
|
64 | }
|
65 | else if (this.props.value != null) {
|
66 | this.setState({
|
67 | dateValue: this.props.value,
|
68 | timeValue: this.props.value,
|
69 | });
|
70 | }
|
71 | else {
|
72 |
|
73 | this.setState({ dateValue: null });
|
74 | }
|
75 | };
|
76 | DateTimePicker.defaultProps = {
|
77 | canClearSelection: true,
|
78 | defaultValue: new Date(),
|
79 | };
|
80 | DateTimePicker.displayName = "".concat(core_1.DISPLAYNAME_PREFIX, ".DateTimePicker");
|
81 | return DateTimePicker;
|
82 | }(core_1.AbstractPureComponent2));
|
83 | exports.DateTimePicker = DateTimePicker;
|
84 |
|
\ | No newline at end of file |