• Docs
  • Blog
    • 0.24.0

    • Switch to dark mode
    Get Started
    Components
    Styling
    Theming

    Concepts

    OverviewCompositionTesting

    Layout

    Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridLink OverlayScrollableStackWrap

    Components

    AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

    Utilities

    Feature FlagsForLocal StoragePortalShowsplitPropsTheme

    Date Picker

    A date picker component for selecting single or range dates.

    • npm
    • source
    • recipe
    • Ark
    import {
    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

    SMTWTFS
    30
    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
    2
    3
    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.

    SMTWTFS
    30
    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
    2
    3
    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.

    Note

    The `defaultValue` prop is only used when the component is first rendered. If you need to update the value dynamically, use the `value` prop instead.

    SMTWTFS
    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.

    SMTWTFS
    30
    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
    2
    3
    Jan
    Feb
    Mar
    Apr
    May
    Jun
    Jul
    Aug
    Sep
    Oct
    Nov
    Dec
    2020
    2021
    2022
    2023
    2024
    2025
    2026
    2027
    2028
    2029
    2030
    2031
    SMTWTFS
    30
    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
    2
    3
    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);

    Note

    View the CalendarDate documentation for more details on how to use it.

    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'])

    Note

    View the parseDate documentation for more details on how to use it.

    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());

    Note

    View the today documentation for more details on how to use it.

    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"

    Note

    View the DateFormatter documentation for more details on how to use it.

    Primitives

    You can utilize the primitive components or the css prop to customize the date picker.

    ComponentDescription
    DatePickerRootThe main container for the date-picker items.
    DatePickerLabelThe label for the date-picker.
    DatePickerControlThe control for the date-picker.
    DatePickerInputThe input field and trigger for the date-picker.
    DatePickerTriggerThe trigger for the date-picker.
    DatePickerClearTriggerThe trigger to clear the date-picker.
    DatePickerPositionerThe positioner for the date-picker.
    DatePickerContentThe content of the date-picker calendar.
    DatePickerYearSelectThe select input for the year in the date-picker.
    DatePickerMonthSelectThe select input for the month in the date-picker.
    DatePickerViewThe container (view) of the calendar.
    DatePickerContextThe context provider for the date-picker calendar.
    DatePickerViewControlThe triggers that update the calendar in the view.
    DatePickerPrevTriggerThe trigger to navigate to the previous view.
    DatePickerNextTriggerThe trigger to navigate to the next view.
    DatePickerViewTriggerThe trigger to navigate to a specific view.
    DatePickerRangeTextThe text that displays the range of dates selected.
    DatePickerTableThe table that contains the calendar.
    DatePickerTableRowThe row of the calendar table.
    DatePickerTableHeadThe header of the calendar table.
    DatePickerTableHeaderThe header cell of the calendar table.
    DatePickerTableBodyThe body of the calendar table.
    DatePickerTableCellThe cell of the calendar table.
    DatePickerTableTriggerThe trigger of the cell in the calendar table.

    Data Attributes

    The Primitives additionally use the following data attributes for custom styling:

    NameValueDescription
    data-scopedate-pickerThe scope of the components.
    data-partrootThe root container part.
    data-partlabelThe label part.
    data-partcontrolThe control part.
    data-partinputThe input part.
    data-parttriggerThe trigger part.
    data-partclearTriggerThe clear trigger part.
    data-partpositionerThe positioner part.
    data-partcontentThe content part.
    data-partviewControlThe view control part.
    data-partprevTriggerThe previous trigger part.
    data-partnextTriggerThe next trigger part.
    data-partviewTriggerThe view trigger part.
    data-partrangeTextThe range text part.
    data-partyearSelectThe year select part.
    data-partmonthSelectThe month select part.
    data-partviewThe view part.
    data-parttableThe table part.
    data-parttableHeadThe table head part.
    data-parttableBodyThe table body part.
    data-parttableRowThe table row part.
    data-parttableHeaderThe table header part.
    data-parttableCellThe table cell part.
    data-parttableCellTriggerThe 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:

    NameDefaultDescription
    withModalfalseWhether the Picker is used within a Dialog.

    Parts

    The DatePickerParts API is an Object containing the full family of components.

    Note

    It is best to only use the DatePickerParts if you are building a custom solution. Importing Object based components will ship every property it includes into your bundle, regardless if you use it or not.

    NameDescription
    RootThe DatePickerRoot component and main container for the date-picker items.
    LabelThe DatePickerLabel component and label for the date-picker.
    ControlThe DatePickerControl component and control for the date-picker.
    InputThe DatePickerInput component and input field and trigger for the date-picker.
    TriggerThe DatePickerRoot component and trigger for the date-picker.
    ClearTriggerThe DatePickerClearTrigger component and trigger to clear the date-picker.
    PositionerThe DatePickerPositioner component and positioner for the date-picker.
    ContentThe DatePickerContent component and content of the date-picker calendar.
    YearSelectThe DatePickerYearSelect component and select input for the year in the date-picker.
    MonthSelectThe DatePickerMonthSelect component and select input for the month in the date-picker.
    ViewThe DatePickerView component and container (view) of the calendar.
    ContextThe DatePickerContext component and context provider for the date-picker calendar.
    ViewControlThe DatePickerViewControl component and triggers that update the calendar in the view.
    PrevTriggerThe DatePickerPrevTrigger component and trigger to navigate to the previous view.
    NextTriggerThe DatePickerNextTrigger component and trigger to navigate to the next view.
    ViewTriggerThe DatePickerViewTrigger component and trigger to navigate to a specific view.
    RangeTextThe DatePickerRangeText component and text that displays the range of dates selected.
    TableThe DatePickerTable component and table that contains the calendar.
    TableRowThe DatePickerTableRow component and row of the calendar table.
    TableHeadThe DatePickerTableHead component and header of the calendar table.
    TableHeaderThe DatePickerTableHeader component and header cell of the calendar table.
    TableBodyThe DatePickerTableBody component and body of the calendar table.
    TableCellThe DatePickerTableCell component and cell of the calendar table.
    TableTriggerThe DatePickerTableTrigger component and trigger of the cell in the calendar table.

    On this page

    • Edit this page on Github
    Cerberus Design System | Docs