import { lazy, Suspense, useRef } from 'react' import { PopoverDisclosure } from 'reakit' import useDateTimePickerState from './useDateTimePickerState' import { isEmptyValue, IVDateTimePickerProps } from './datePickerUtils' import { DateInput } from './DateInput' import TimeInput from './TimeInput' import classNames from 'classnames' import CloseIcon from '~/icons/compiled/Close' import CalendarIcon from '~/icons/compiled/Calendar' const CalendarPopover = lazy(() => import('./CalendarPopover')) /* * Note, this will not work as the `as` prop of a Formik , * because its `onChange` handler expects an HTML event as its argument. */ export default function IVDateTimePicker(props: IVDateTimePickerProps) { const { isClearable = true, mode = 'datetime' } = props const dateInputRef = useRef(null) const { state, onClear, popover, onDateInputChange, onDateInputKeyDown, onPickerChange, onTimeChange, onDateInputFocus, onDateInputBlur, } = useDateTimePickerState(props) const hasValue = Object.entries(state).filter(([key, value]) => { if (!['hour', 'minute', 'dateInputValue'].includes(key)) return false return !isEmptyValue(value) }).length > 0 return (
{mode !== 'time' && ( { if (props.onBlur) props.onBlur() onDateInputBlur(e) }} onFocus={onDateInputFocus} onKeyDown={onDateInputKeyDown} showPlaceholder={props.showPlaceholder} /> )} {mode !== 'date' && ( )}
{isClearable && !props.disabled && ( )} {mode !== 'time' && !props.disabled && ( <> }> )}
) }