Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/components/date-time-picker.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/* A pretty simple API wrapping antd's much more complicated6date picking api. Use this if you just need to pick7a date and time easily. For more complicated applications,8check out910https://ant.design/components/date-picker/11*/1213import { DatePicker } from "antd";14import dayjs from "dayjs";1516import { React } from "@cocalc/frontend/app-framework";1718interface Props {19placeholder?: string;20value?: any;21onChange?: (date: dayjs.Dayjs | null, dateString: string) => void;22onFocus?: Function;23onBlur?: Function;24open?: boolean;25style?: React.CSSProperties;26format?: 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/format27}2829export function DateTimePicker(props: Props) {30const {31placeholder,32value,33onChange,34onFocus,35onBlur,36open,37style,38format = "YYYY-MM-DD HH:mm Z",39} = props;4041const props2: any = {42showTime: true,43format,44placeholder,45onChange: onChange,46style,47};4849if (open != null) {50props2.open = open;51}5253if (value != null) {54props2.value = dayjs(value);55} else {56props2.value = null;57}5859if (onFocus != null || onBlur != null) {60props2.onOpenChange = (status) => {61if (status && onFocus != null) {62onFocus();63} else if (!status && onBlur != null) {64onBlur();65}66};67}6869return <DatePicker changeOnBlur {...props2} />;70}717273