Date Input

GitHub

Date picker input with optional label, validation state, and controlled value.

Installation

bash
pnpm dlx shadcn@latest add @cs/date-input

Usage

tsx
import { DateInput } from "@/components/cs/date-input";
tsx
<DateInput name="start-date" label="Start date" />

Multiple dates

Lets people select and deselect several individual dates.

tsx
"use client"

import { useState } from "react"
import { DateInput } from "@/registry/cs/ui/date-input"
import { PreviewPanel } from "./preview-utils"

export default function DateInputMultiplePreview() {
	const [value, setValue] = useState<Date[]>()

	return (
		<PreviewPanel>
			<DateInput
				name="available-dates"
				mode="multiple"
				label="Available dates"
				placeholder="Select dates"
				value={value}
				onValueChange={setValue}
			/>
		</PreviewPanel>
	)
}

Date range

Selects a start and end date in one calendar.

tsx
"use client"

import { useState } from "react"
import type { DateRange } from "react-day-picker"
import { DateInput } from "@/registry/cs/ui/date-input"
import { PreviewPanel } from "./preview-utils"

export default function DateInputRangePreview() {
	const [value, setValue] = useState<DateRange>()

	return (
		<PreviewPanel>
			<DateInput
				name="booking-dates"
				mode="range"
				label="Booking dates"
				placeholder="Select dates"
				value={value}
				onValueChange={setValue}
			/>
		</PreviewPanel>
	)
}

API Reference

DateInput

Date picker input with optional label, validation state, and controlled value.

Props

NameTypeDefaultDescription
buttonClassNamestring-Additional classes applied to the date picker trigger.
calendarClassNamestring-Additional classes applied to the calendar panel.
defaultValueTData-Initial selected date value for uncontrolled usage.
errorstring | null-Validation error message for the field.
labelReactNode-Field label and fallback placeholder.
mode"single""single"Selection mode for a single date.
namestring-Name used for generated hidden form inputs.
onValueChange(date: TData | undefined) => void-Called when the selected date value changes.
orientationComponentProps<typeof Field>["orientation"]-Layout of the field label and date picker.
placeholderstring-Text displayed before a date is selected.
requiredfalse-Allows an empty selection.
valueTData-Controlled selected date value.
valueFormatter(date: Date) => string-Formats selected dates for display in the trigger.