DateField
A styled and form-integrated date picker input built with Tailwind CSS and react-hook-form
. This field handles validation styling, error display, and supports extensive customization via class overrides.
๐ฆ Importโ
import { DateField } from "@sahilphondekar/react-component-library";
๐งฑ Propsโ
Name | Type | Default | Description |
---|---|---|---|
label | string | โ | Optional label displayed above the input |
id | string | โ (required) | Unique identifier for the input |
register | function | โ (required) | react-hook-form 's register method |
errorMessage | string | undefined | Displays a validation error below the input |
outerContainerClassName | string | "" | Class name for outer wrapper |
inputClassName | string | "" | Class name applied to the input element |
labelClassName | string | "" | Class name for the label element |
errorClassName | string | "" | Class name for the error message element |
๐ Styling Notesโ
- Default styling:
w-full px-3 py-2 border rounded-lg text-sm
- Focus ring:
- Blue by default, red if
errorMessage
is provided
- Blue by default, red if
- Error message:
text-red-500 text-sm mt-1
๐งช Exampleโ
<DateField
id="dob"
label="Date of Birth"
register={register("dob", { required: "Date of birth is required" })}
errorMessage={errors.dob?.message}
/>
๐ง Tipsโ
- Works perfectly for birthdate fields, event dates, and date-based filters.
- Consider wrapping it with
min
ormax
attributes via...rest
for date constraints.