UNPKG

4.16 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/**
28 * Date time picker component.
29 *
30 * @see https://blueprintjs.com/docs/#datetime/datetimepicker
31 * @deprecated since 3.4.0. Prefer `<DatePicker>` with `timePrecision` and `timePickerProps`.
32 */
33var DateTimePicker = /** @class */ (function (_super) {
34 tslib_1.__extends(DateTimePicker, _super);
35 function DateTimePicker(props, context) {
36 var _this = _super.call(this, props, context) || this;
37 _this.handleDateChange = function (dateValue, isUserChange) {
38 var _a, _b;
39 if (_this.props.value === undefined) {
40 _this.setState({ dateValue: dateValue });
41 }
42 var value = DateUtils.getDateTime(dateValue, _this.state.timeValue);
43 (_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, value, isUserChange);
44 };
45 _this.handleTimeChange = function (timeValue) {
46 var _a, _b;
47 if (_this.props.value === undefined) {
48 _this.setState({ timeValue: timeValue });
49 }
50 var value = DateUtils.getDateTime(_this.state.dateValue, timeValue);
51 (_b = (_a = _this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, value, true);
52 };
53 var initialValue = _this.props.value !== undefined ? _this.props.value : _this.props.defaultValue;
54 _this.state = {
55 dateValue: initialValue,
56 timeValue: initialValue,
57 };
58 return _this;
59 }
60 DateTimePicker.prototype.render = function () {
61 var value = DateUtils.getDateTime(this.state.dateValue, this.state.timeValue);
62 return (React.createElement("div", { className: (0, classnames_1.default)(Classes.DATETIMEPICKER, this.props.className) },
63 React.createElement(datePicker_1.DatePicker, tslib_1.__assign({}, this.props.datePickerProps, { canClearSelection: this.props.canClearSelection, onChange: this.handleDateChange, value: value })),
64 React.createElement(timePicker_1.TimePicker, tslib_1.__assign({}, this.props.timePickerProps, { onChange: this.handleTimeChange, value: this.state.timeValue }))));
65 };
66 DateTimePicker.prototype.componentDidUpdate = function (prevProps) {
67 if (this.props.value === prevProps.value) {
68 return;
69 }
70 else if (this.props.value != null) {
71 this.setState({
72 dateValue: this.props.value,
73 timeValue: this.props.value,
74 });
75 }
76 else {
77 // clear only the date to remove the selected-date style in the calendar
78 this.setState({ dateValue: null });
79 }
80 };
81 DateTimePicker.defaultProps = {
82 canClearSelection: true,
83 defaultValue: new Date(),
84 };
85 DateTimePicker.displayName = "".concat(core_1.DISPLAYNAME_PREFIX, ".DateTimePicker");
86 return DateTimePicker;
87}(core_1.AbstractPureComponent2));
88exports.DateTimePicker = DateTimePicker;
89//# sourceMappingURL=dateTimePicker.js.map
\No newline at end of file