import React, {useState, useRef} from 'react' import {Button} from './form' import {DateTime} from 'luxon' import InfiniteCalendar from 'react-infinite-calendar'; import Modal from '~/components/modal' import styles from './styles.module.css' // TODO: At some point make the date input better for accessibility // (currently just skips tab index) export default function DateInput({placeholder: _placeholder, label: _label, error, hint, name, value, onChange, onBlur, isValid, minDate, maxDate}){ const label = (_label === undefined) ? name.replace(name[0], name[0].toUpperCase()) : _label const displayedValue = value ? DateTime.fromISO(value).toFormat('LLLL dd, yyyy') : _placeholder const inputRef = useRef() const [modalShown, setModal] = useState(false) const handleDateSelect = date => { onChange({target: {value: DateTime.fromJSDate(date).toISO()}}) handleCancel() } const handleCancel = () => { setModal(false) setTimeout(()=>inputRef.current?.blur(), 0) } return (
{label && }
setModal(true)} type="text" name={name} value={displayedValue} onBlur={onBlur} />
{(hint || error) && {error || (isValid ? '' : hint)}}
) }