UNPKG

3.19 kBJavaScriptView Raw
1/*
2 * Copyright 2015 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import classNames from "classnames";
17import * as React from "react";
18import { AbstractPureComponent2, DISPLAYNAME_PREFIX } from "@blueprintjs/core";
19import * as Classes from "./common/classes";
20import * as DateUtils from "./common/dateUtils";
21import { DatePicker } from "./datePicker";
22import { TimePicker } from "./timePicker";
23/** @deprecated since 3.4.0. Prefer `<DatePicker>` with `timePrecision` and `timePickerProps`. */
24export class DateTimePicker extends AbstractPureComponent2 {
25 static defaultProps = {
26 canClearSelection: true,
27 defaultValue: new Date(),
28 };
29 static displayName = `${DISPLAYNAME_PREFIX}.DateTimePicker`;
30 constructor(props, context) {
31 super(props, context);
32 const initialValue = this.props.value !== undefined ? this.props.value : this.props.defaultValue;
33 this.state = {
34 dateValue: initialValue,
35 timeValue: initialValue,
36 };
37 }
38 render() {
39 const value = DateUtils.getDateTime(this.state.dateValue, this.state.timeValue);
40 return (React.createElement("div", { className: classNames(Classes.DATETIMEPICKER, this.props.className) },
41 React.createElement(DatePicker, { ...this.props.datePickerProps, canClearSelection: this.props.canClearSelection, onChange: this.handleDateChange, value: value }),
42 React.createElement(TimePicker, { ...this.props.timePickerProps, onChange: this.handleTimeChange, value: this.state.timeValue })));
43 }
44 componentDidUpdate(prevProps) {
45 if (this.props.value === prevProps.value) {
46 return;
47 }
48 else if (this.props.value != null) {
49 this.setState({
50 dateValue: this.props.value,
51 timeValue: this.props.value,
52 });
53 }
54 else {
55 // clear only the date to remove the selected-date style in the calendar
56 this.setState({ dateValue: null });
57 }
58 }
59 handleDateChange = (dateValue, isUserChange) => {
60 if (this.props.value === undefined) {
61 this.setState({ dateValue });
62 }
63 const value = DateUtils.getDateTime(dateValue, this.state.timeValue);
64 this.props.onChange?.(value, isUserChange);
65 };
66 handleTimeChange = (timeValue) => {
67 if (this.props.value === undefined) {
68 this.setState({ timeValue });
69 }
70 const value = DateUtils.getDateTime(this.state.dateValue, timeValue);
71 this.props.onChange?.(value, true);
72 };
73}
74//# sourceMappingURL=dateTimePicker.js.map
\No newline at end of file