Time Range Picker
A simple and reusable component to work with or select a date or a range of dates.
Note: Consumer of this component can customize the labels for header, timezone, cancel button, save button and even
error message via LocaleProvider
Examples
Usage with new API
Custom Range: 13 Nov,2024 02:50 PM – 19 Nov,2024 02:50 PM | UTC
Basic Usage
States
Time Select
Disabled
Error
Format String
Single Month
Overrides
Date and Time Select Overrides
Time Range Picker with localization
Date constraints
NOTE: the valid range is [minDate, maxDate)
since the Calendar
sets seconds and milliseconds on end time to 59.999
.
Consider a scenario where maxDate
has the time 12:30:00.000
and user selects the same as End Time. It gets converted
to 12:30:59.999
which violates maxDate
. Thus, the valid range is not inclusive of maxDate
.
ApiTable
Time Range Picker Props
Name | Type | Default | Description |
---|---|---|---|
autoSizeInput | boolean | false | Adjusts the width according to value |
clearable | boolean | false | Allows to clears value from input |
disableTimezone | boolean | false | Hides the time zone picker |
disabled | boolean | false | Renders component in disabled state. |
displayVariant | 'default' | 'compact' | 'iconButton' | If compact, it tries to minimize the size of input, by showing minimal info about the range upfront | |
excludeDates | array | A list of dates to disable. Array<Date> | |
filterDate | function | A filter function (Date => boolean) that is called to check the disabled state of a day. If false is returned the day is considered to be disabled. | |
fixedHeight | boolean | Defines if 6 rows should always be displayed for all the months. | |
formatString | string | MM/dd/yyyy | String format passed to date-fns. |
intent | 'default' | 'success' | 'warning' | 'error' | Defines the intent of the Input. | |
maxDate | date | A max date that is selectable. | |
minDate | date | A min date that is selectable. | |
monthsShown | number | A number of months rendered in the calendar. | |
onChange | function | Event handler that is called when any update is made to date either by selecting preset, directly selecting date from calendar or changing time. | |
onClose | function | A function () => {} that is called every time datepicker closes except when it closes due after submit. | |
onSubmit | function | Event handler that is called when user will press the save button | |
overrides | custom | Lets you customize all aspects of the component. | |
peekNextMonth | boolean | false | Defines if dates outside of the range of the current month are displayed. |
placeholder | string | Input's placeholder. | |
showFullDateInSummary | boolean | false | If true, will show the full date with preset in input. |
showTimezoneInSummary | boolean | false | If true shows timezone in input with date |
size | 'xs' | 'sm' | 'md' | Input's size. SPACIOUS | COMFORTABLE -> md, COMPACT -> xxxs, DEFAULT -> md | |
startOpen | boolean | If true, opens the dropdown when the time range picker mounts. | |
timeRangePresets | array | Array of objects, each containing property id, label and getTimeRangeLimits. getTimeRangeLimits function should return array of startDate and endDate. | |
timeSelect | boolean | false | Renders the time picker to select end time |
timezone | string | System Timezone | Currently selected timezone. |
value | array | Currently selected date. Either Array of Date or string from the ids of timeRangePresets | |
variant | 'default' | 'line' | Input's variant - default, line | |
weekStartsOn | number | Decides the start day of week. 0 indicates Sunday. This will depend on locale |
You can check the implementation of the component for more details.
Time Range Picker exports
You can import this module like so:
import {TimeRangePicker} from 'spaceweb/time-range-picker'
It exports the following components or utility functions:
- TimeRangePicker
- convertDateFromSrcTzToTargetTz
- convertDateFromSystemTzToTargetTz
- convertDateFromTargetTzToSystemTz
- formatSummaryValue
- getDefaultTimeRangePresets
- getSystemTzName