Skip to main content

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โ€‹

NameTypeDefaultDescription
labelstringโ€”Optional label displayed above the input
idstringโ€” (required)Unique identifier for the input
registerfunctionโ€” (required)react-hook-form's register method
errorMessagestringundefinedDisplays a validation error below the input
outerContainerClassNamestring""Class name for outer wrapper
inputClassNamestring""Class name applied to the input element
labelClassNamestring""Class name for the label element
errorClassNamestring""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
  • 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 or max attributes via ...rest for date constraints.