Concepts
OverviewCompositionTestingLayout
Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrapComponents
AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltipUtilities
Feature FlagsForLocal StoragePortalShowsplitPropsThemeimport { DatePicker, DatePickerLabel, DatePickerInput, DatePickerCalendar} from '@cerberus/react'Usage
The DatePicker component is a controlled component that allows users to select a single date or a range of dates. It consists of a label, input field, and a calendar view.
Single Date Picker
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
26 | 27 | 28 | 29 | 30 | 31 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 1 | 2 | 3 | 4 | 5 | 6 |
Jan | Feb | Mar | Apr |
May | Jun | Jul | Aug |
Sep | Oct | Nov | Dec |
2020 | 2021 | 2022 | 2023 |
2024 | 2025 | 2026 | 2027 |
2028 | 2029 | 2030 | 2031 |
Date Range Picker
To create a date range picker, set the selectionMode prop to range on the DatePicker component and use the RangePickerInput component as the input field.
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
26 | 27 | 28 | 29 | 30 | 31 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 1 | 2 | 3 | 4 | 5 | 6 |
Jan | Feb | Mar | Apr |
May | Jun | Jul | Aug |
Sep | Oct | Nov | Dec |
2020 | 2021 | 2022 | 2023 |
2024 | 2025 | 2026 | 2027 |
2028 | 2029 | 2030 | 2031 |
Using Default Values
You can set the default values for the range date picker by passing the defaultValue prop to the DatePicker component in the form of an Array of two date strings.
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
29 | 30 | 31 | 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 | 1 |
Jan | Feb | Mar | Apr |
May | Jun | Jul | Aug |
Sep | Oct | Nov | Dec |
2020 | 2021 | 2022 | 2023 |
2024 | 2025 | 2026 | 2027 |
2028 | 2029 | 2030 | 2031 |
Custom Styles
You can customize the DatePicker width and other styles using the css prop along with the data-part selector to target specific primitives.
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
26 | 27 | 28 | 29 | 30 | 31 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 1 | 2 | 3 | 4 | 5 | 6 |
Jan | Feb | Mar | Apr |
May | Jun | Jul | Aug |
Sep | Oct | Nov | Dec |
2020 | 2021 | 2022 | 2023 |
2024 | 2025 | 2026 | 2027 |
2028 | 2029 | 2030 | 2031 |
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
26 | 27 | 28 | 29 | 30 | 31 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 1 | 2 | 3 | 4 | 5 | 6 |
Jan | Feb | Mar | Apr |
May | Jun | Jul | Aug |
Sep | Oct | Nov | Dec |
2020 | 2021 | 2022 | 2023 |
2024 | 2025 | 2026 | 2027 |
2028 | 2029 | 2030 | 2031 |
Date Helpers
The DatePicker component relies on different date utilities to handle date parsing and formatting. Here are the options available:
Creating Dates
You can create a structured date Object using the CalendarDate class. This function accepts a date string or an object with year, month, and day properties.
import { CalendarDate } from '@cerberus/react'const date = new CalendarDate(2022, 2, 3);Parsing Dates
You can use the parseDate function to convert an array of date strings into a date object that the DatePicker can understand.
import { parseDate } from '@cerberus/react'const date = parseDate(['2025-01-01', '2025-01-15'])Today's Date
You can use the today function to get the current date in a format that the DatePicker can understand.
import { today, getLocalTimeZone } from '@cerberus/react'
const nyDate = today('America/New_York');const localDate = today(getLocalTimeZone());Formatting Dates
You can use the DateFormatter class to format a date object into a string. This is useful for displaying dates in a human-readable format.
import { DateFormatter } from '@cerberus/react'
const formatter = new DateFormatter('en-US', { dateStyle: 'long', timeZone: 'America/New_York'})const date = formatter.format(new Date()); // "January 1, 2025"Primitives
You can utilize the primitive components or the css prop to customize the date picker.
| Component | Description |
|---|---|
| DatePickerRoot | The main container for the date-picker items. |
| DatePickerLabel | The label for the date-picker. |
| DatePickerControl | The control for the date-picker. |
| DatePickerInput | The input field and trigger for the date-picker. |
| DatePickerTrigger | The trigger for the date-picker. |
| DatePickerClearTrigger | The trigger to clear the date-picker. |
| DatePickerPositioner | The positioner for the date-picker. |
| DatePickerContent | The content of the date-picker calendar. |
| DatePickerYearSelect | The select input for the year in the date-picker. |
| DatePickerMonthSelect | The select input for the month in the date-picker. |
| DatePickerView | The container (view) of the calendar. |
| DatePickerContext | The context provider for the date-picker calendar. |
| DatePickerViewControl | The triggers that update the calendar in the view. |
| DatePickerPrevTrigger | The trigger to navigate to the previous view. |
| DatePickerNextTrigger | The trigger to navigate to the next view. |
| DatePickerViewTrigger | The trigger to navigate to a specific view. |
| DatePickerRangeText | The text that displays the range of dates selected. |
| DatePickerTable | The table that contains the calendar. |
| DatePickerTableRow | The row of the calendar table. |
| DatePickerTableHead | The header of the calendar table. |
| DatePickerTableHeader | The header cell of the calendar table. |
| DatePickerTableBody | The body of the calendar table. |
| DatePickerTableCell | The cell of the calendar table. |
| DatePickerTableTrigger | The trigger of the cell in the calendar table. |
The Primitives additionally use the following data attributes for custom styling:
| Name | Value | Description |
|---|---|---|
data-scope | date-picker | The scope of the components. |
data-part | root | The root container part. |
data-part | label | The label part. |
data-part | control | The control part. |
data-part | input | The input part. |
data-part | trigger | The trigger part. |
data-part | clearTrigger | The clear trigger part. |
data-part | positioner | The positioner part. |
data-part | content | The content part. |
data-part | viewControl | The view control part. |
data-part | prevTrigger | The previous trigger part. |
data-part | nextTrigger | The next trigger part. |
data-part | viewTrigger | The view trigger part. |
data-part | rangeText | The range text part. |
data-part | yearSelect | The year select part. |
data-part | monthSelect | The month select part. |
data-part | view | The view part. |
data-part | table | The table part. |
data-part | tableHead | The table head part. |
data-part | tableBody | The table body part. |
data-part | tableRow | The table row part. |
data-part | tableHeader | The table header part. |
data-part | tableCell | The table cell part. |
data-part | tableCellTrigger | The table cell trigger part. |
API
Props
DatePicker
The DatePicker component accepts all the props of the DatePickerRoot primitive
DatePickerLabel
The DatePickerLabel component accepts all the props of the DatePickerLabel primitive
DatePickerInput
The DatePickerInput component accepts all the props of the DatePickerInputEl primitive
DatePickerCalendar
The DatePickerCalendar component is an abstraction of the primitives and accepts the following props:
| Name | Default | Description |
|---|---|---|
| withModal | false | Whether the Picker is used within a Dialog. |
Parts
The DatePickerParts API is an Object containing the full family of components.
| Name | Description |
|---|---|
| Root | The DatePickerRoot component and main container for the date-picker items. |
| Label | The DatePickerLabel component and label for the date-picker. |
| Control | The DatePickerControl component and control for the date-picker. |
| Input | The DatePickerInput component and input field and trigger for the date-picker. |
| Trigger | The DatePickerRoot component and trigger for the date-picker. |
| ClearTrigger | The DatePickerClearTrigger component and trigger to clear the date-picker. |
| Positioner | The DatePickerPositioner component and positioner for the date-picker. |
| Content | The DatePickerContent component and content of the date-picker calendar. |
| YearSelect | The DatePickerYearSelect component and select input for the year in the date-picker. |
| MonthSelect | The DatePickerMonthSelect component and select input for the month in the date-picker. |
| View | The DatePickerView component and container (view) of the calendar. |
| Context | The DatePickerContext component and context provider for the date-picker calendar. |
| ViewControl | The DatePickerViewControl component and triggers that update the calendar in the view. |
| PrevTrigger | The DatePickerPrevTrigger component and trigger to navigate to the previous view. |
| NextTrigger | The DatePickerNextTrigger component and trigger to navigate to the next view. |
| ViewTrigger | The DatePickerViewTrigger component and trigger to navigate to a specific view. |
| RangeText | The DatePickerRangeText component and text that displays the range of dates selected. |
| Table | The DatePickerTable component and table that contains the calendar. |
| TableRow | The DatePickerTableRow component and row of the calendar table. |
| TableHead | The DatePickerTableHead component and header of the calendar table. |
| TableHeader | The DatePickerTableHeader component and header cell of the calendar table. |
| TableBody | The DatePickerTableBody component and body of the calendar table. |
| TableCell | The DatePickerTableCell component and cell of the calendar table. |
| TableTrigger | The DatePickerTableTrigger component and trigger of the cell in the calendar table. |
On this page