Kaapi UI
← Back to Design System

DatePicker

Basic DatePicker component with form integration.

Single Date Picker


const [selected, setSelected] = useState<Date>();

<DatePicker value={selected} onChange={setSelected} />

Range Date Picker


const [dateRange, setDateRange] = useState<{ start: Date; end: Date } | null>(null);

<DateRangePicker value={dateRange} onChange={setDateRange} />

Form

Choose a start and end date


const formSchema = z.object({
        startDate: z.date({
            error: issue => (issue.input === undefined ? "Required" : "Invalid date"),
        }),
        eventPeriod: z.object(
            {
                start: z.date({
                    error: issue => (issue.input === undefined ? "Required" : "Invalid date"),
                }),
                end: z.date({
                    error: issue => (issue.input === undefined ? "Required" : "Invalid date"),
                }),
            },
            { message: "Both start and end date are required" }
        ),
    });

    const form = useForm<z.infer<typeof formSchema>>({
        resolver: zodResolver(formSchema),
        defaultValues: {
            startDate: undefined,
            eventPeriod: undefined
        },
    });

    function onSubmit(data: z.infer<typeof formSchema>) {
        toast("You submitted the following values", {
            description: (
                <pre className="mt-2 w-[320px] rounded-md bg-neutral-950 p-4">
                    <code className="text-white">{JSON.stringify(data, null, 2)}</code>
                </pre>
            ),
        });
    }

<Form {...form}>
  <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
    <DatePickerForm
      control={form.control}
      name="startDate"
      label="Start Date"
      placeholder="Pick a date"
      isRequired
    />
    <Button type="submit">Submit</Button>
  </form>
</Form>

API Reference

DatePicker

PropsTypeDefaultDescription
value?Date | undefinedundefinedCurrent selected date.
onChange?(date: Date | undefined) ⇒ void-Callback when date is changed.
placeholder?string"Select date"Placeholder when no date is selected.
disabled?booleanfalseDisable the input and button.

DatePickerForm

PropsTypeDefaultDescription
namestring-Field name (react-hook-form).
controlControl<T>-react-hook-form control object.
label?string-Field label.
description?string-Helper text under the field.
isRequired?booleanfalseMark the field as required.

DateRangePicker

PropsTypeDefaultDescription
value?{ start: Date; end: Date } | nullnullCurrently selected range.
onChange?(range: { start: Date; end: Date } | null) ⇒ void-Callback when range is changed.
placeholder?string"Select date range"Placeholder when no range selected.
disabled?booleanfalseDisable the input and button.

DateRangePickerForm

PropsTypeDefaultDescription
namestring-Field name (react-hook-form).
controlControl<T>-react-hook-form control object.
label?string-Field label.
description?string-Helper text under the field.
isRequired?booleanfalseMark the field as required.