Back to Reui

Date Selector

content/docs/components/radix/date-selector.mdx

2.0.06.3 KB
Original Source

<ComponentPreview styleName="radix-nova" name="c-date-selector-1" align="start" className="**:[.preview]:h-auto!" />

Installation

<CodeTabs> <TabsList> <TabsTrigger value="cli">CLI</TabsTrigger> <TabsTrigger value="manual">Manual</TabsTrigger> </TabsList> <TabsContent value="cli">
bash
npx shadcn@latest add @reui/r-date-selector
</TabsContent> <TabsContent value="manual"> <Steps>

<Step>Install the following dependencies:</Step>

bash
npm install date-fns react-day-picker radix-ui

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource styleName="radix-nova" name="date-selector" title="components/reui/date-selector.tsx" />

</Steps> </TabsContent> </CodeTabs>

Usage

tsx
import {
  DateSelector,
  type DateSelectorValue,
} from "@/components/reui/r-date-selector"
tsx
const [value, setValue] = useState<DateSelectorValue | undefined>()

return <DateSelector value={value} onChange={setValue} label="Due date" />

Examples

With Popover

<ComponentPreview styleName="radix-nova" name="c-date-selector-2" />

With Dialog

<ComponentPreview styleName="radix-nova" name="c-date-selector-3" />

With i18n Support

<ComponentPreview styleName="radix-nova" name="c-date-selector-4" />

API Reference

DateSelector

The main component for selecting dates and time periods.

PropTypeDefaultDescription
valueDateSelectorValue-The current value of the selector.
onChange(value: DateSelectorValue) => void-Callback fired when the value changes.
allowRangebooleantrueWhether to allow selecting date ranges (using "between" operator).
periodTypesDateSelectorPeriodType[]-List of available period types (day, month, etc.).
defaultPeriodTypeDateSelectorPeriodType"day"The initial period type.
defaultFilterTypeDateSelectorFilterType"is"The initial filter operator.
presetModeDateSelectorFilterType-If set, locks the selector to this specific filter mode.
showInputbooleantrueWhether to show the text input field above the selector.
showTwoMonthsbooleantrueWhether to show two months in the calendar view (desktop only).
labelstring-Optional label to display above the filter toggle.
yearRangenumber10The number of years to show in the year/month/quarter list.
baseYearnumbernew Date().getFullYear()The reference year for the year selection list.
minYearnumber2015The minimum selectable year.
maxYearnumber2026The maximum selectable year.
i18nPartial<DateSelectorI18nConfig>-Custom labels and operators for internationalization.
inputHintstring-Optional hint text to display in the input field when empty and focused.
dayDateFormatstring"MM/dd/yyyy"The format used to display single days.
classNamestring-Additional CSS classes for the container.

Interfaces

DateSelectorValue

The structure of the value returned by the onChange callback.

PropertyTypeDescription
periodDateSelectorPeriodTypeThe selected period type (day, month, quarter, half-year, year).
operatorDateSelectorFilterTypeThe selected operator (is, before, after, between).
startDateDateThe selected start date (for day period).
endDateDateThe selected end date (for day period range).
yearnumberThe selected year.
monthnumberThe selected month (0-11).
quarternumberThe selected quarter (0-3).
halfYearnumberThe selected half-year (0-1).
rangeStart{ year: number; value: number }The start of a period range.
rangeEnd{ year: number; value: number }The end of a period range.