Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | 3x 14x 14x 678x | export interface DateSelectOption {
value: string
label: string
}
export type DateSelectOptions = DateSelectOption[]
export type DateSelectType = 'year' | 'month' | 'day'
export type DateSelectOnChangeEvent = (
e: React.ChangeEvent<HTMLSelectElement>,
type: DateSelectType,
) => void
export interface DateSelectProps {
ariaDescribedby?: string
dateSelectLabelId: string
error?: boolean
id: string
label: string
onChange: DateSelectOnChangeEvent
options: DateSelectOptions
required?: boolean
type: DateSelectType
value: string
}
const DateSelect = ({
ariaDescribedby,
dateSelectLabelId,
error,
id,
label,
onChange,
options,
required,
type,
value,
}: DateSelectProps) => {
const handleOnSelectChange: React.ChangeEventHandler<HTMLSelectElement> = (
e,
) => onChange(e, type)
return (
<div className="flex flex-col space-y-2">
<label
id={`date-select-${id}-${type}-label`}
htmlFor={id}
className="font-bold"
>
{label}
</label>
<select
id={id}
value={value}
onChange={handleOnSelectChange}
aria-describedby={ariaDescribedby}
aria-invalid={error ? true : undefined}
aria-labelledby={`${dateSelectLabelId} date-select-${id}-${type}-label`}
aria-required={required ? true : undefined}
className={`w-40 rounded border px-3 py-1 ${
error ? 'border-accent-error' : 'border-neutral-400'
} bg-white focus:border-sky-500 focus:outline-none focus:ring-sky-500`}
>
<option value="" disabled></option>
{options.map(({ label, value }) => (
<option key={value} value={value}>
{label}
</option>
))}
</select>
</div>
)
}
export default DateSelect
|