CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/components/date-time-picker.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/* A pretty simple API wrapping antd's much more complicated
7
date picking api. Use this if you just need to pick
8
a date and time easily. For more complicated applications,
9
check out
10
11
https://ant.design/components/date-picker/
12
*/
13
14
import { DatePicker } from "antd";
15
import dayjs from "dayjs";
16
17
import { React } from "@cocalc/frontend/app-framework";
18
19
interface Props {
20
placeholder?: string;
21
value?: any;
22
onChange?: (date: dayjs.Dayjs | null, dateString: string) => void;
23
onFocus?: Function;
24
onBlur?: Function;
25
open?: boolean;
26
style?: React.CSSProperties;
27
format?: string; // refer to day.js, see https://ant.design/components/date-picker#components-date-picker-demo-format and https://day.js.org/docs/en/display/format
28
}
29
30
export function DateTimePicker(props: Props) {
31
const {
32
placeholder,
33
value,
34
onChange,
35
onFocus,
36
onBlur,
37
open,
38
style,
39
format = "YYYY-MM-DD HH:mm Z",
40
} = props;
41
42
const props2: any = {
43
showTime: true,
44
format,
45
placeholder,
46
onChange: onChange,
47
style,
48
};
49
50
if (open != null) {
51
props2.open = open;
52
}
53
54
if (value != null) {
55
props2.value = dayjs(value);
56
} else {
57
props2.value = null;
58
}
59
60
if (onFocus != null || onBlur != null) {
61
props2.onOpenChange = (status) => {
62
if (status && onFocus != null) {
63
onFocus();
64
} else if (!status && onBlur != null) {
65
onBlur();
66
}
67
};
68
}
69
70
return <DatePicker changeOnBlur {...props2} />;
71
}
72
73