Skip to main content

Date Picker

The DatePicker component is a styled date selection input with floating label, error states, form integration (React Hook Form), and options to disable past dates. It uses a popover calendar for date selection and formats the chosen date as YYYY-MM-DD.

import { DatePicker } from "tawuniya/components";

👉 View in Storybook

Props​

PropTypeDefaultDescription
labelstring—Floating label displayed inside the button.
idstring—Unique identifier for the component.
errorstring—Error message displayed below the picker.
classNamestring—Additional Tailwind classes for the button container.
disabledbooleanfalseDisables the picker.
disablePastbooleanfalsePrevents selection of past dates.
valuestring—Selected date value (YYYY-MM-DD).
onChange(date: string) => void—Callback triggered when the date changes.
form{ controller: any; control: any; name: string }—Integration with React Hook Form via Controller.
modalbooleantrueThe modality of the popover. When set to false, users can interact with elements outside the popover, and the popover content does not restrict focus or visibility.
iconReact.ReactNode—Custom icon for the date picker button.
minstring—Minimum date that can be selected.
maxstring—Maximum date that can be selected.
formatstringYYYY-MM-DDDate format for display and value.
views("Day" | "Month" | "Year")[]["Day","Month","Year"]Controls which parts of the date to show.
captionLayout("dropdown" | "label" | "dropdown-years" | "dropdown-months")"dropdown"Controls the layout of the month caption.
wrapperClassNamestring—Additional Tailwind classes for the wrapper

Usage​

With Controlled Form​

import { useState } from "react";

import { DatePicker } from "tawuniya/components";
import { DatePicker } from "tawuniya/components";

export default function BasicExample() {
const [date, setDate] = useState("");

return (
<DatePicker label="Select Date" id="date" value={date} onChange={setDate} />
);
}

Disable Past Dates​

<DatePicker label="Meeting Date" id="meeting-date" disablePast />

With Error Message​

<DatePicker label="Birthdate" id="birthdate" error="Birthdate is required" />

With Custom Icon​

<DatePicker icon={<Icon name="calendar-outline" />} />

With React Hook Form​

import { useForm, Controller } from "react-hook-form";
import { DatePicker } from "tawuniya/components";

export default function FormExample() {
const { control, handleSubmit } = useForm({
defaultValues: { appointment: "" },
});

const onSubmit = (data: any) => {
console.log(data);
};

return (
<form onSubmit={handleSubmit(onSubmit)}>
<DatePicker
label="Appointment Date"
id="appointment"
form={{ controller: Controller, control, name: "appointment" }}
/>
<button type="submit">Submit</button>
</form>
);
}

With Min and Max Dates​

<DatePicker
label="Meeting Date"
id="meeting-date"
min="2024-01-01"
max="2024-12-31"
/>

With Custom Format​

<DatePicker label="Meeting Date" id="meeting-date" format="DD/MM/YYYY" />

With Views​

<DatePicker label="Meeting Date" id="meeting-date" views={["Month", "Year"]} />

With Caption Layout​

<DatePicker label="Meeting Date" id="meeting-date" captionLayout="label" />

Notes​

  • The floating label animates upward when a date is selected.
  • If disablePast is true, all dates before today will be disabled in the calendar.
  • Works as a controlled component using value + onChange, or with React Hook Form via the form prop.