UNPKG

4.06 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2015 Palantir Technologies, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.DateTimePicker = void 0;
19var tslib_1 = require("tslib");
20var classnames_1 = tslib_1.__importDefault(require("classnames"));
21var React = tslib_1.__importStar(require("react"));
22var core_1 = require("@blueprintjs/core");
23var Classes = tslib_1.__importStar(require("./common/classes"));
24var DateUtils = tslib_1.__importStar(require("./common/dateUtils"));
25var datePicker_1 = require("./datePicker");
26var timePicker_1 = require("./timePicker");
27/** @deprecated since 3.4.0. Prefer `<DatePicker>` with `timePrecision` and `timePickerProps`. */
28var DateTimePicker = /** @class */ (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 // clear only the date to remove the selected-date style in the calendar
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));
83exports.DateTimePicker = DateTimePicker;
84//# sourceMappingURL=dateTimePicker.js.map
\No newline at end of file