dash-core-components 4.0.0-rc4 → 4.0.0-rc6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dash_core_components/async-datepicker.js +1 -1
- package/dash_core_components/async-datepicker.js.map +1 -1
- package/dash_core_components/async-dropdown.js +1 -1
- package/dash_core_components/async-dropdown.js.map +1 -1
- package/dash_core_components/async-slider.js +1 -1
- package/dash_core_components/async-slider.js.map +1 -1
- package/dash_core_components/async-upload.js +2 -1
- package/dash_core_components/async-upload.js.map +1 -1
- package/dash_core_components/dash_core_components.js +1 -1
- package/dash_core_components/dash_core_components.js.map +1 -1
- package/lib/components/Input.tsx +13 -3
- package/lib/components/Tabs.tsx +1 -1
- package/lib/components/Tooltip.tsx +1 -0
- package/lib/components/Upload.react.js +13 -1
- package/lib/components/css/button.css +5 -10
- package/lib/components/css/calendar.css +25 -7
- package/lib/components/css/datepickers.css +98 -39
- package/lib/components/css/dcc.css +2 -2
- package/lib/components/css/dropdown.css +25 -11
- package/lib/components/css/input.css +8 -2
- package/lib/components/css/optionslist.css +2 -1
- package/lib/components/css/sliders.css +15 -6
- package/lib/components/css/textarea.css +10 -0
- package/lib/components/css/tooltip.css +1 -1
- package/lib/fragments/DatePickerRange.tsx +57 -50
- package/lib/fragments/DatePickerSingle.tsx +33 -10
- package/lib/fragments/Dropdown.tsx +19 -5
- package/lib/fragments/RangeSlider.tsx +1 -2
- package/lib/fragments/Upload.react.js +243 -1
- package/lib/utils/calendar/Calendar.tsx +62 -32
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ import React, {
|
|
|
7
7
|
useState,
|
|
8
8
|
forwardRef,
|
|
9
9
|
} from 'react';
|
|
10
|
-
import {addMonths, subMonths} from 'date-fns';
|
|
10
|
+
import {addMonths, subMonths, endOfMonth} from 'date-fns';
|
|
11
11
|
import {
|
|
12
12
|
ArrowUpIcon,
|
|
13
13
|
ArrowDownIcon,
|
|
@@ -80,6 +80,12 @@ const CalendarComponent = ({
|
|
|
80
80
|
initialVisibleDate.getMonth()
|
|
81
81
|
);
|
|
82
82
|
|
|
83
|
+
const [firstCalendarMonth, setFirstCalendarMonth] = useState(() => {
|
|
84
|
+
// Start by displaying calendar months centered around the initial date
|
|
85
|
+
const halfRange = Math.floor((numberOfMonthsShown - 1) / 2);
|
|
86
|
+
return subMonths(initialVisibleDate, halfRange);
|
|
87
|
+
});
|
|
88
|
+
|
|
83
89
|
const [focusedDate, setFocusedDate] = useState<Date>();
|
|
84
90
|
const [highlightedDates, setHighlightedDates] = useState<[Date, Date]>();
|
|
85
91
|
const calendarContainerRef = useRef(document.createElement('div'));
|
|
@@ -101,6 +107,33 @@ const CalendarComponent = ({
|
|
|
101
107
|
},
|
|
102
108
|
}));
|
|
103
109
|
|
|
110
|
+
const isMonthVisible = useCallback(
|
|
111
|
+
(date: Date) => {
|
|
112
|
+
const visibleStart = firstCalendarMonth;
|
|
113
|
+
const visibleEnd = endOfMonth(
|
|
114
|
+
addMonths(visibleStart, numberOfMonthsShown - 1)
|
|
115
|
+
);
|
|
116
|
+
return isDateInRange(date, visibleStart, visibleEnd);
|
|
117
|
+
},
|
|
118
|
+
[firstCalendarMonth, numberOfMonthsShown]
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// Updates the calendar whenever the active month & year change
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
const activeDate = new Date(activeYear, activeMonth, 1);
|
|
124
|
+
|
|
125
|
+
// Don't change calendar if the active month is already visible
|
|
126
|
+
if (isMonthVisible(activeDate)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
setFirstCalendarMonth(
|
|
131
|
+
activeDate < firstCalendarMonth
|
|
132
|
+
? activeDate // Moved backward: show activeDate as first month
|
|
133
|
+
: subMonths(activeDate, numberOfMonthsShown - 1) // Moved forward: show activeDate as last month
|
|
134
|
+
);
|
|
135
|
+
}, [activeMonth, activeYear, isMonthVisible]);
|
|
136
|
+
|
|
104
137
|
useEffect(() => {
|
|
105
138
|
// Syncs activeMonth/activeYear to focusedDate when focusedDate changes
|
|
106
139
|
if (!focusedDate) {
|
|
@@ -111,21 +144,11 @@ const CalendarComponent = ({
|
|
|
111
144
|
}
|
|
112
145
|
prevFocusedDateRef.current = focusedDate;
|
|
113
146
|
|
|
114
|
-
|
|
115
|
-
const activeMonthStart = new Date(activeYear, activeMonth, 1);
|
|
116
|
-
const visibleStart = subMonths(activeMonthStart, halfRange);
|
|
117
|
-
const visibleEnd = addMonths(activeMonthStart, halfRange);
|
|
118
|
-
|
|
119
|
-
const focusedMonthStart = new Date(
|
|
120
|
-
focusedDate.getFullYear(),
|
|
121
|
-
focusedDate.getMonth(),
|
|
122
|
-
1
|
|
123
|
-
);
|
|
124
|
-
if (!isDateInRange(focusedMonthStart, visibleStart, visibleEnd)) {
|
|
147
|
+
if (!isMonthVisible(focusedDate)) {
|
|
125
148
|
setActiveMonth(focusedDate.getMonth());
|
|
126
149
|
setActiveYear(focusedDate.getFullYear());
|
|
127
150
|
}
|
|
128
|
-
}, [focusedDate,
|
|
151
|
+
}, [focusedDate, isMonthVisible]);
|
|
129
152
|
|
|
130
153
|
useEffect(() => {
|
|
131
154
|
if (highlightStart && highlightEnd) {
|
|
@@ -225,6 +248,7 @@ const CalendarComponent = ({
|
|
|
225
248
|
if (isDateInRange(newMonthStart, minDateAllowed, maxDateAllowed)) {
|
|
226
249
|
setActiveYear(newMonthStart.getFullYear());
|
|
227
250
|
setActiveMonth(newMonthStart.getMonth());
|
|
251
|
+
setFirstCalendarMonth(newMonthStart);
|
|
228
252
|
}
|
|
229
253
|
},
|
|
230
254
|
[activeYear, activeMonth, minDateAllowed, maxDateAllowed, direction]
|
|
@@ -292,18 +316,30 @@ const CalendarComponent = ({
|
|
|
292
316
|
>
|
|
293
317
|
<PreviousMonthIcon />
|
|
294
318
|
</button>
|
|
295
|
-
<
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
306
|
-
|
|
319
|
+
<div style={{display: 'grid'}}>
|
|
320
|
+
{/* Render all the month names invisibly so that the longest month name is what determines the width of the month picker, regardless of which language is used */}
|
|
321
|
+
{monthOptions.map((opt, i) => (
|
|
322
|
+
<div
|
|
323
|
+
key={i}
|
|
324
|
+
className="dash-datepicker-month-sizer"
|
|
325
|
+
aria-hidden="true"
|
|
326
|
+
>
|
|
327
|
+
{opt.label}
|
|
328
|
+
</div>
|
|
329
|
+
))}
|
|
330
|
+
<Dropdown
|
|
331
|
+
options={monthOptions}
|
|
332
|
+
value={activeMonth}
|
|
333
|
+
clearable={false}
|
|
334
|
+
maxHeight={250}
|
|
335
|
+
searchable={false}
|
|
336
|
+
setProps={({value}) => {
|
|
337
|
+
if (Number.isInteger(value)) {
|
|
338
|
+
setActiveMonth(value as number);
|
|
339
|
+
}
|
|
340
|
+
}}
|
|
341
|
+
/>
|
|
342
|
+
</div>
|
|
307
343
|
<Input
|
|
308
344
|
type={HTMLInputTypes.number}
|
|
309
345
|
debounce={0.5}
|
|
@@ -337,13 +373,7 @@ const CalendarComponent = ({
|
|
|
337
373
|
}}
|
|
338
374
|
>
|
|
339
375
|
{Array.from({length: numberOfMonthsShown}, (_, i) => {
|
|
340
|
-
|
|
341
|
-
const offset =
|
|
342
|
-
i - Math.floor((numberOfMonthsShown - 1) / 2);
|
|
343
|
-
const monthDate = addMonths(
|
|
344
|
-
new Date(activeYear, activeMonth, 1),
|
|
345
|
-
offset
|
|
346
|
-
);
|
|
376
|
+
const monthDate = addMonths(firstCalendarMonth, i);
|
|
347
377
|
return (
|
|
348
378
|
<CalendarMonth
|
|
349
379
|
key={i}
|