Skip to content

Commit bf30769

Browse files
committed
Implement DatePickerRange
1 parent ef1063c commit bf30769

19 files changed

+1208
-292
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React, {lazy, Suspense} from 'react';
2+
import datePickerRange from '../utils/LazyLoader/datePickerRange';
3+
import transformDate from '../utils/DatePickerPersistence';
4+
import {DatePickerRangeProps, PersistedProps, PersistenceTypes} from '../types';
5+
6+
const RealDatePickerRange = lazy(datePickerRange);
7+
8+
/**
9+
* DatePickerRange is a tailor made component designed for selecting
10+
* timespan across multiple days off of a calendar.
11+
*
12+
* The DatePicker integrates well with the Python datetime module with the
13+
* startDate and endDate being returned in a string format suitable for
14+
* creating datetime objects.
15+
*
16+
*/
17+
export default function DatePickerRange({
18+
calendar_orientation = 'horizontal',
19+
is_RTL = false,
20+
// eslint-disable-next-line no-magic-numbers
21+
day_size = 34,
22+
with_portal = false,
23+
with_full_screen_portal = false,
24+
first_day_of_week = 0,
25+
number_of_months_shown = 2,
26+
stay_open_on_select = false,
27+
reopen_calendar_on_clear = false,
28+
clearable = false,
29+
disabled = false,
30+
updatemode = 'singledate',
31+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
32+
persisted_props = [PersistedProps.start_date, PersistedProps.end_date],
33+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
34+
persistence_type = PersistenceTypes.local,
35+
disabled_days = [],
36+
...props
37+
}: DatePickerRangeProps) {
38+
return (
39+
<Suspense fallback={null}>
40+
<RealDatePickerRange
41+
calendar_orientation={calendar_orientation}
42+
is_RTL={is_RTL}
43+
day_size={day_size}
44+
with_portal={with_portal}
45+
with_full_screen_portal={with_full_screen_portal}
46+
first_day_of_week={first_day_of_week}
47+
number_of_months_shown={number_of_months_shown}
48+
stay_open_on_select={stay_open_on_select}
49+
reopen_calendar_on_clear={reopen_calendar_on_clear}
50+
clearable={clearable}
51+
disabled={disabled}
52+
disabled_days={disabled_days}
53+
updatemode={updatemode}
54+
{...props}
55+
/>
56+
</Suspense>
57+
);
58+
}
59+
60+
DatePickerRange.dashPersistence = {
61+
persisted_props: [PersistedProps.start_date, PersistedProps.end_date],
62+
persistence_type: PersistenceTypes.local,
63+
};
64+
65+
DatePickerRange.persistenceTransforms = {
66+
end_date: transformDate,
67+
start_date: transformDate,
68+
};

components/dash-core-components/src/components/css/datepickers.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
grid-template-columns: auto 1fr auto auto;
3333
}
3434

35+
.dash-datepicker-input-wrapper:has(:nth-child(5)) {
36+
grid-template-columns: auto auto auto 1fr auto;
37+
}
38+
39+
.dash-datepicker-input-wrapper:has(:nth-child(6)) {
40+
grid-template-columns: auto auto auto 1fr auto auto;
41+
}
42+
3543
.dash-datepicker-input-wrapper,
3644
.dash-datepicker-content {
3745
border-radius: var(--Dash-Spacing);
@@ -42,7 +50,7 @@
4250

4351
.dash-datepicker-input {
4452
height: 34px;
45-
width: 100%;
53+
width: fit-content;
4654
border: none;
4755
outline: none;
4856
border-radius: 4px;

0 commit comments

Comments
 (0)