Spaces:
Runtime error
Runtime error
Download frontend/src/components/DateInput.tsx from Talosware/talos-access: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/Talosware/talos-access/resolve/main/frontend/src/components/DateInput.tsx
- Command line
-
hf download hf://spaces/Talosware/talos-access/frontend/src/components/DateInput.tsx
-
curl -L -o DateInput.tsx https://huggingface.co/spaces/Talosware/talos-access/resolve/main/frontend/src/components/DateInput.tsx
1.36 kB
| import { InputHTMLAttributes, useState } from 'react'; | |
| import { useHolidays } from '../hooks/useHolidays'; | |
| interface DateInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, 'type' | 'onChange'> { | |
| value: string; | |
| onChange: (newDate: string) => void; | |
| /** If true, allow selecting holiday dates anyway (default false). */ | |
| allowHolidays?: boolean; | |
| } | |
| export default function DateInput({ value, onChange, allowHolidays = false, className = '', ...rest }: DateInputProps) { | |
| const holidays = useHolidays(); | |
| const [warn, setWarn] = useState<string | null>(null); | |
| const handle = (e: React.ChangeEvent<HTMLInputElement>) => { | |
| const v = e.target.value; | |
| setWarn(null); | |
| if (v && !allowHolidays && holidays.has(v)) { | |
| setWarn('Esta fecha es feriado y no puede seleccionarse.'); | |
| // revert: do NOT call onChange, so the input stays at the previous value | |
| e.target.value = value; | |
| return; | |
| } | |
| onChange(v); | |
| }; | |
| const isHoliday = !!value && holidays.has(value); | |
| const errClass = warn || (!allowHolidays && isHoliday) ? 'border-red-300' : ''; | |
| return ( | |
| <div> | |
| <input | |
| type="date" | |
| value={value} | |
| onChange={handle} | |
| className={`${className} ${errClass}`.trim()} | |
| {...rest} | |
| /> | |
| {warn && <p className="text-xs text-red-600 mt-1">{warn}</p>} | |
| </div> | |
| ); | |
| } | |