Date Picker Button
The Date Picker Button is a Popover widget which allows for either a single date or a date range selection.
There are two types of date ranges: static and dynamic. The difference between them is that dynamic date ranges are relative to today's date, while static date ranges are fixed regardless of time. If users choose one of the specified date ranges on the period selector sidebar, except of Custom
, they start working with dynamic date ranges. Interacting directly on the calendar lets deal with static date ranges.
Example
Variants
Calendar type
You can choose between Static dates
and Rolling period
calendar type using calendarType
prop. Default is Rolling period
.
Static dates
is as the name suggests is the fixed date range, whereas Rolling period
is period range from the currentDate.
note
Please note that the in Custom Dates in Datepicker with Rolling period is just the visual representation.
To use the rolling featuer with custom date, please use the hook created in Datascape
Custom Current Date
You can pass currentDate
. Its value will be assigned to "today" and relative dates will be calculated relatively to it.
Custom Dates Formatting
You can use a customDateFormat
property to format dates inside trigger button as you will.
Date and time formatting and hourly periods
You can use showTime
property to show dates with date-time format.
Also, when showTime
is provided, we include hourly relative periods in popover side menu.
Current hourly relative periods supported are: last-hour
, two-hours-ago
and last-24-hours
.
Data-TestId
We have the support for custom data-test using the prop: dataTestId
.
Disabled
You can use prop disabled
to disabled the selection.
Hide Clear Button
You can hide the clear button with isClearButtonHidden
prop.
onClear callback
you can use onClear to run a function when clear button is clicked
Relative Date Options Formatting
You can use a relativeDateOptions
property to manage the Date Options.
The props accepts only array of Period
, an ENUM from DatePickerButton utils.
Full width trigger
You can use isFullWidthTrigger
property to allow the trigger to take the available width.
Translate
You can use a getElementLabel
property to define the text for all available elements within the DatePicker.
This function will be called with one of the following values as an argument:
type DatePickerButtonTextElements =
| 'last-hour'
| 'two-hours-ago'
| 'today'
| 'yesterday'
| 'last-7-days'
| 'last-14-days'
| 'last-30-days'
| 'last-3-months'
| 'this-month'
| 'last-month'
| 'this-week'
| 'last-week'
| 'custom'
| 'start-date-label'
| 'end-date-label'
| 'cancel-button'
| 'apply-button'
| 'clear-button'
| 'static'
| 'static-dates'
| 'static-dates-description'
| 'rolling'
| 'rolling-period'
| 'rolling-period-description';
Each value matches the element within the DatePicker
, e.g. 'apply-button' specifies the label for the Apply button
etc.
Also, you will need to use the locale
prop to set a localized version of the Months and Date Range values.
Do:
- Always provide locale code with the
locale
prop to the component when using thegetElementLabel
prop.
info
Supported languages:
English (Default), Chinese, French, German, Japanese, Korean, Portuguese, Russian, Spanish, Turkish, Vietnamese
Props
Name | Type | Default |
---|---|---|
startDate The beginning date of the selected date range. Should be provided when working with a static date range. If 'period' prop provided it will be ignored. |
| null |
endDate The end date of the selected date range. Should be provided when working with a static date range. If 'period' prop provided it will be ignored. |
| null |
period Allows to set a dynamic date range. If provided 'startDate' and 'endDate' props will be ignored.
To work with static date ranges it should be undefined.
Please use values from Period enum for this prop: Today, Yesterday, Last7Days, Last14Days, Last30Days, Last3Months, LastMonth, LastWeek, ThisMonth, ThisWeek. |
| — |
relativeDateOptions Allows to provide Date Options, if empty provide all options |
| [] |
onApply The handler will be called after clicking Apply button |
| — |
onClear The handler will be called after clicking Clear button |
| — |
getElementLabel Use this prop to override the default elements texts and labels.
DatePickerButtonTextElements contains elements:
| 'period-today'
| 'period-yesterday'
| 'period-last-7-days'
| 'period-last-14-days'
| 'period-last-30-days'
| 'period-last-3-months'
| 'custom'
| 'start-date-label'
| 'end-date-label'
| 'cancel-button'
| 'apply-button'
| 'clear-button'
| 'this-month'
| 'last-month'
| 'this-week'
| 'last-week'
| 'static'
| 'static-dates'
| 'static-dates-description'
| 'rolling'
| 'rolling-period'
| 'rolling-period-description' |
| — |
customDateFormat Use this function to format dates inside trigger button |
| — |
minDate The earliest date the user can select |
| — |
maxDate The latest date the user can select |
| — |
currentDate The custom date to be used as the current date. If undefined, the machine current date is used. |
| — |
currentMonthPosition Use this prop to set the position of the current month |
| "right" |
aria-label Provide at least one label(visual or non-visual) property for better accessibility. Check Accessibility page for more info: Link |
| — |
zIndex Add z-index rule to the pop-over window |
| "auto" |
locale Use this prop to set localization for the date values |
| "'en' as LocaleCode" |
showTime Include time in date format |
| false |
isClearButtonHidden Determines whether the clear button is hidden |
| false |
disabled Allow to disable the selection |
| false |
calendarType Type of Calender |
| — |
dataTestId Data-testId |
| "datepicker" |
isFullWidthTrigger Allows the trigger to take the available width |
| — |
data-{foo} Data attributes can be used by testing libraries to retrieve components or assert their existence |
| — |
* - the prop is required. |