dash-core-components 4.0.0-rc2 → 4.0.0-rc3
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 -2
- package/dash_core_components/async-dropdown.js.map +1 -1
- package/dash_core_components/async-graph.js +1 -1
- package/dash_core_components/async-graph.js.map +1 -1
- package/dash_core_components/async-highlight.js +1 -1
- package/dash_core_components/async-highlight.js.map +1 -1
- package/dash_core_components/async-markdown.js +1 -1
- package/dash_core_components/async-markdown.js.map +1 -1
- package/dash_core_components/async-mathjax.js +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 +1 -1
- package/dash_core_components/async-upload.js.map +1 -1
- package/dash_core_components/dash_core_components-shared.js +1 -1
- package/dash_core_components/dash_core_components-shared.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/dash_core_components/proptypes.js +116 -12
- package/lib/components/Clipboard.react.js +1 -1
- package/lib/components/DatePickerRange.tsx +70 -0
- package/lib/components/DatePickerSingle.tsx +72 -0
- package/lib/components/Input.tsx +1 -1
- package/lib/components/Tab.tsx +19 -0
- package/lib/components/Tabs.tsx +311 -0
- package/lib/components/css/calendar.css +66 -0
- package/lib/components/css/datepickers.css +233 -0
- package/lib/components/css/dcc.css +1 -0
- package/lib/components/css/dropdown.css +6 -3
- package/lib/components/css/input.css +8 -2
- package/lib/components/css/sliders.css +22 -0
- package/lib/components/css/tabs.css +113 -0
- package/lib/fragments/DatePickerRange.tsx +444 -0
- package/lib/fragments/DatePickerSingle.tsx +249 -0
- package/lib/fragments/Dropdown.tsx +8 -4
- package/lib/fragments/Graph.react.js +18 -45
- package/lib/fragments/RangeSlider.tsx +2 -0
- package/lib/index.ts +4 -6
- package/lib/types.ts +353 -27
- package/lib/utils/DatePickerPersistence.ts +14 -0
- package/lib/utils/LazyLoader/datePickerRange.ts +4 -0
- package/lib/utils/LazyLoader/datePickerSingle.ts +4 -0
- package/lib/utils/calendar/Calendar.tsx +382 -0
- package/lib/utils/calendar/CalendarDay.tsx +75 -0
- package/lib/utils/calendar/CalendarDayPadding.tsx +15 -0
- package/lib/utils/calendar/CalendarMonth.tsx +247 -0
- package/lib/utils/calendar/CalendarMonthHeader.tsx +23 -0
- package/lib/utils/calendar/createMonthGrid.ts +28 -0
- package/lib/utils/calendar/helpers.ts +272 -0
- package/lib/utils/computeSliderMarkers.ts +71 -116
- package/lib/utils/optionRendering.tsx +22 -15
- package/lib/utils/sliderRendering.tsx +40 -2
- package/package.json +16 -13
- package/lib/components/DatePickerRange.react.js +0 -244
- package/lib/components/DatePickerSingle.react.js +0 -209
- package/lib/components/Dropdown.react.js.old +0 -228
- package/lib/components/Tab.react.js +0 -80
- package/lib/components/Tab.react.js.old +0 -79
- package/lib/components/Tabs.react.js +0 -295
- package/lib/components/Textarea.react.js.old +0 -287
- package/lib/fragments/DatePickerRange.react.js +0 -188
- package/lib/fragments/DatePickerSingle.react.js +0 -132
- package/lib/utils/DatePickerPersistence.js +0 -18
- package/lib/utils/LazyLoader/datePickerRange.js +0 -8
- package/lib/utils/LazyLoader/datePickerSingle.js +0 -8
- package/lib/utils/convertToMoment.js +0 -30
- package/lib/utils/optionTypes.js +0 -39
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useImperativeHandle,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
forwardRef,
|
|
9
|
+
} from 'react';
|
|
10
|
+
import {addMonths, subMonths} from 'date-fns';
|
|
11
|
+
import {
|
|
12
|
+
ArrowUpIcon,
|
|
13
|
+
ArrowDownIcon,
|
|
14
|
+
ArrowLeftIcon,
|
|
15
|
+
ArrowRightIcon,
|
|
16
|
+
} from '@radix-ui/react-icons';
|
|
17
|
+
import Input, {HTMLInputTypes} from '../../components/Input';
|
|
18
|
+
import Dropdown from '../../components/Dropdown';
|
|
19
|
+
import {DayOfWeek, CalendarDirection} from '../../types';
|
|
20
|
+
import {CalendarMonth} from './CalendarMonth';
|
|
21
|
+
import {
|
|
22
|
+
getMonthOptions,
|
|
23
|
+
formatYear,
|
|
24
|
+
parseYear,
|
|
25
|
+
isDateInRange,
|
|
26
|
+
isSameDay,
|
|
27
|
+
} from './helpers';
|
|
28
|
+
|
|
29
|
+
export type CalendarHandle = {
|
|
30
|
+
focusDate: (date?: Date) => void;
|
|
31
|
+
setVisibleDate: (date: Date) => void;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type CalendarProps = {
|
|
35
|
+
onSelectionChange: (selectionStart: Date, selectionEnd?: Date) => void;
|
|
36
|
+
selectionStart?: Date;
|
|
37
|
+
selectionEnd?: Date;
|
|
38
|
+
highlightStart?: Date;
|
|
39
|
+
highlightEnd?: Date;
|
|
40
|
+
initialVisibleDate?: Date;
|
|
41
|
+
minDateAllowed?: Date;
|
|
42
|
+
maxDateAllowed?: Date;
|
|
43
|
+
disabledDates?: Date[];
|
|
44
|
+
firstDayOfWeek?: DayOfWeek;
|
|
45
|
+
showOutsideDays?: boolean;
|
|
46
|
+
monthFormat?: string;
|
|
47
|
+
calendarOrientation?: 'vertical' | 'horizontal';
|
|
48
|
+
numberOfMonthsShown?: number;
|
|
49
|
+
daySize?: number;
|
|
50
|
+
direction?: CalendarDirection;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type CalendarPropsWithRef = CalendarProps & {
|
|
54
|
+
forwardedRef?: React.Ref<CalendarHandle>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const CalendarComponent = ({
|
|
58
|
+
initialVisibleDate = new Date(),
|
|
59
|
+
onSelectionChange,
|
|
60
|
+
selectionStart,
|
|
61
|
+
selectionEnd,
|
|
62
|
+
highlightStart,
|
|
63
|
+
highlightEnd,
|
|
64
|
+
minDateAllowed,
|
|
65
|
+
maxDateAllowed,
|
|
66
|
+
disabledDates,
|
|
67
|
+
firstDayOfWeek,
|
|
68
|
+
showOutsideDays,
|
|
69
|
+
monthFormat,
|
|
70
|
+
calendarOrientation,
|
|
71
|
+
numberOfMonthsShown = 1,
|
|
72
|
+
daySize,
|
|
73
|
+
direction = CalendarDirection.LeftToRight,
|
|
74
|
+
forwardedRef,
|
|
75
|
+
}: CalendarPropsWithRef) => {
|
|
76
|
+
const [activeYear, setActiveYear] = useState(() =>
|
|
77
|
+
initialVisibleDate.getFullYear()
|
|
78
|
+
);
|
|
79
|
+
const [activeMonth, setActiveMonth] = useState(() =>
|
|
80
|
+
initialVisibleDate.getMonth()
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const [focusedDate, setFocusedDate] = useState<Date>();
|
|
84
|
+
const [highlightedDates, setHighlightedDates] = useState<[Date, Date]>();
|
|
85
|
+
const calendarContainerRef = useRef(document.createElement('div'));
|
|
86
|
+
const scrollAccumulatorRef = useRef(0);
|
|
87
|
+
const prevFocusedDateRef = useRef(focusedDate);
|
|
88
|
+
|
|
89
|
+
const displayYear = useMemo(() => {
|
|
90
|
+
const formatted = formatYear(activeYear, monthFormat);
|
|
91
|
+
return parseInt(formatted, 10);
|
|
92
|
+
}, [activeYear, monthFormat]);
|
|
93
|
+
|
|
94
|
+
useImperativeHandle(forwardedRef, () => ({
|
|
95
|
+
focusDate: (date = new Date(activeYear, activeMonth, 1)) => {
|
|
96
|
+
setFocusedDate(date);
|
|
97
|
+
},
|
|
98
|
+
setVisibleDate: (date: Date) => {
|
|
99
|
+
setActiveMonth(date.getMonth());
|
|
100
|
+
setActiveYear(date.getFullYear());
|
|
101
|
+
},
|
|
102
|
+
}));
|
|
103
|
+
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
// Syncs activeMonth/activeYear to focusedDate when focusedDate changes
|
|
106
|
+
if (!focusedDate) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (focusedDate.getTime() === prevFocusedDateRef.current?.getTime()) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
prevFocusedDateRef.current = focusedDate;
|
|
113
|
+
|
|
114
|
+
const halfRange = Math.floor((numberOfMonthsShown - 1) / 2);
|
|
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)) {
|
|
125
|
+
setActiveMonth(focusedDate.getMonth());
|
|
126
|
+
setActiveYear(focusedDate.getFullYear());
|
|
127
|
+
}
|
|
128
|
+
}, [focusedDate, activeMonth, activeYear, numberOfMonthsShown]);
|
|
129
|
+
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (highlightStart && highlightEnd) {
|
|
132
|
+
setHighlightedDates([highlightStart, highlightEnd]);
|
|
133
|
+
} else if (highlightStart) {
|
|
134
|
+
setHighlightedDates([highlightStart, highlightStart]);
|
|
135
|
+
} else {
|
|
136
|
+
setHighlightedDates(undefined);
|
|
137
|
+
}
|
|
138
|
+
}, [highlightStart, highlightEnd]);
|
|
139
|
+
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (selectionStart && selectionEnd) {
|
|
142
|
+
setHighlightedDates([selectionStart, selectionEnd]);
|
|
143
|
+
}
|
|
144
|
+
}, [selectionStart, selectionEnd]);
|
|
145
|
+
|
|
146
|
+
const selectedDates = useMemo((): Date[] => {
|
|
147
|
+
return [selectionStart, selectionEnd].filter(
|
|
148
|
+
(d): d is Date => d !== undefined
|
|
149
|
+
);
|
|
150
|
+
}, [selectionStart, selectionEnd]);
|
|
151
|
+
|
|
152
|
+
const handleSelectionStart = useCallback(
|
|
153
|
+
(date: Date) => {
|
|
154
|
+
if (!selectionStart || selectionEnd) {
|
|
155
|
+
// No selection yet, or previous selection is complete → start new selection
|
|
156
|
+
setHighlightedDates(undefined);
|
|
157
|
+
onSelectionChange(date, undefined);
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
[selectionStart, selectionEnd, onSelectionChange]
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
const handleSelectionEnd = useCallback(
|
|
164
|
+
(date: Date) => {
|
|
165
|
+
// Complete the selection with an end date
|
|
166
|
+
if (selectionStart && !selectionEnd) {
|
|
167
|
+
// Incomplete selection exists (range picker mid-selection)
|
|
168
|
+
if (!isSameDay(selectionStart, date)) {
|
|
169
|
+
onSelectionChange(selectionStart, date);
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
// Complete selection exists or a single date was chosen
|
|
173
|
+
onSelectionChange(date, date);
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
[selectionStart, selectionEnd, onSelectionChange]
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
const handleDaysHighlighted = useCallback(
|
|
180
|
+
(date: Date) => {
|
|
181
|
+
if (selectionStart && selectionEnd) {
|
|
182
|
+
setHighlightedDates([selectionStart, selectionEnd]);
|
|
183
|
+
} else if (selectionStart && !selectionEnd) {
|
|
184
|
+
setHighlightedDates([selectionStart, date]);
|
|
185
|
+
} else {
|
|
186
|
+
setHighlightedDates([date, date]);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
[selectionStart, selectionEnd]
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
const handleDayFocused = useCallback(
|
|
193
|
+
(date: Date) => {
|
|
194
|
+
setFocusedDate(date);
|
|
195
|
+
// When navigating with keyboard during range selection,
|
|
196
|
+
// highlight the range from start to focused date
|
|
197
|
+
if (selectionStart && !selectionEnd) {
|
|
198
|
+
setHighlightedDates([selectionStart, date]);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
[selectionStart, selectionEnd]
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
const monthOptions = useMemo(
|
|
205
|
+
() =>
|
|
206
|
+
getMonthOptions(
|
|
207
|
+
activeYear,
|
|
208
|
+
monthFormat,
|
|
209
|
+
minDateAllowed,
|
|
210
|
+
maxDateAllowed
|
|
211
|
+
),
|
|
212
|
+
[activeYear, monthFormat, minDateAllowed, maxDateAllowed]
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
const changeMonthBy = useCallback(
|
|
216
|
+
(months: number) => {
|
|
217
|
+
const currentDate = new Date(activeYear, activeMonth, 1);
|
|
218
|
+
|
|
219
|
+
// In RTL mode, directions are reversed
|
|
220
|
+
const actualMonths =
|
|
221
|
+
direction === CalendarDirection.RightToLeft ? -months : months;
|
|
222
|
+
|
|
223
|
+
const newMonthStart = addMonths(currentDate, actualMonths);
|
|
224
|
+
|
|
225
|
+
if (isDateInRange(newMonthStart, minDateAllowed, maxDateAllowed)) {
|
|
226
|
+
setActiveYear(newMonthStart.getFullYear());
|
|
227
|
+
setActiveMonth(newMonthStart.getMonth());
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
[activeYear, activeMonth, minDateAllowed, maxDateAllowed, direction]
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
const handleWheel = useCallback(
|
|
234
|
+
(e: WheelEvent) => {
|
|
235
|
+
e.preventDefault();
|
|
236
|
+
|
|
237
|
+
// Accumulate scroll delta until threshold is reached, then change the active month
|
|
238
|
+
// This respects OS scroll speed settings and works well with trackpads
|
|
239
|
+
const threshold = 100; // Adjust this to control sensitivity
|
|
240
|
+
|
|
241
|
+
scrollAccumulatorRef.current += e.deltaY;
|
|
242
|
+
|
|
243
|
+
if (Math.abs(scrollAccumulatorRef.current) >= threshold) {
|
|
244
|
+
const offset = scrollAccumulatorRef.current > 0 ? 1 : -1;
|
|
245
|
+
changeMonthBy(offset);
|
|
246
|
+
scrollAccumulatorRef.current = 0; // Reset accumulator after month change
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
[changeMonthBy]
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
useEffect(() => {
|
|
253
|
+
// Add listener with passive: false to allow preventDefault
|
|
254
|
+
calendarContainerRef.current.addEventListener('wheel', handleWheel, {
|
|
255
|
+
passive: false,
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
return () => {
|
|
259
|
+
calendarContainerRef.current?.removeEventListener(
|
|
260
|
+
'wheel',
|
|
261
|
+
handleWheel
|
|
262
|
+
);
|
|
263
|
+
};
|
|
264
|
+
}, [handleWheel]);
|
|
265
|
+
|
|
266
|
+
const canChangeMonthBy = useCallback(
|
|
267
|
+
(months: number) => {
|
|
268
|
+
const currentDate = new Date(activeYear, activeMonth, 1);
|
|
269
|
+
const targetMonth = addMonths(currentDate, months);
|
|
270
|
+
|
|
271
|
+
return isDateInRange(targetMonth, minDateAllowed, maxDateAllowed);
|
|
272
|
+
},
|
|
273
|
+
[activeYear, activeMonth, minDateAllowed, maxDateAllowed]
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
const isVertical = calendarOrientation === 'vertical';
|
|
277
|
+
const PreviousMonthIcon = isVertical ? ArrowUpIcon : ArrowLeftIcon;
|
|
278
|
+
const NextMonthIcon = isVertical ? ArrowDownIcon : ArrowRightIcon;
|
|
279
|
+
|
|
280
|
+
return (
|
|
281
|
+
<div
|
|
282
|
+
className="dash-datepicker-calendar-wrapper"
|
|
283
|
+
style={{'--day-size': `${daySize}px`} as React.CSSProperties}
|
|
284
|
+
>
|
|
285
|
+
<div className="dash-datepicker-controls">
|
|
286
|
+
<button
|
|
287
|
+
type="button"
|
|
288
|
+
className="dash-datepicker-month-nav"
|
|
289
|
+
onClick={() => changeMonthBy(-1)}
|
|
290
|
+
disabled={!canChangeMonthBy(-1)}
|
|
291
|
+
aria-label="Previous month"
|
|
292
|
+
>
|
|
293
|
+
<PreviousMonthIcon />
|
|
294
|
+
</button>
|
|
295
|
+
<Dropdown
|
|
296
|
+
options={monthOptions}
|
|
297
|
+
value={activeMonth}
|
|
298
|
+
clearable={false}
|
|
299
|
+
maxHeight={250}
|
|
300
|
+
searchable={false}
|
|
301
|
+
setProps={({value}) => {
|
|
302
|
+
if (Number.isInteger(value)) {
|
|
303
|
+
setActiveMonth(value as number);
|
|
304
|
+
}
|
|
305
|
+
}}
|
|
306
|
+
/>
|
|
307
|
+
<Input
|
|
308
|
+
type={HTMLInputTypes.number}
|
|
309
|
+
debounce={0.5}
|
|
310
|
+
value={displayYear}
|
|
311
|
+
min={minDateAllowed?.getFullYear()}
|
|
312
|
+
max={maxDateAllowed?.getFullYear()}
|
|
313
|
+
setProps={({value}) => {
|
|
314
|
+
const parsed = parseYear(String(value));
|
|
315
|
+
if (parsed !== undefined) {
|
|
316
|
+
setActiveYear(parsed);
|
|
317
|
+
}
|
|
318
|
+
}}
|
|
319
|
+
/>
|
|
320
|
+
<button
|
|
321
|
+
type="button"
|
|
322
|
+
className="dash-datepicker-month-nav"
|
|
323
|
+
onClick={() => changeMonthBy(1)}
|
|
324
|
+
disabled={!canChangeMonthBy(1)}
|
|
325
|
+
aria-label="Next month"
|
|
326
|
+
>
|
|
327
|
+
<NextMonthIcon />
|
|
328
|
+
</button>
|
|
329
|
+
</div>
|
|
330
|
+
<div
|
|
331
|
+
className="dash-datepicker-calendar-container"
|
|
332
|
+
ref={calendarContainerRef}
|
|
333
|
+
dir={direction}
|
|
334
|
+
style={{
|
|
335
|
+
flexDirection:
|
|
336
|
+
calendarOrientation === 'vertical' ? 'column' : 'row',
|
|
337
|
+
}}
|
|
338
|
+
>
|
|
339
|
+
{Array.from({length: numberOfMonthsShown}, (_, i) => {
|
|
340
|
+
// Center the view: start from (numberOfMonthsShown - 1) / 2 months before activeMonth
|
|
341
|
+
const offset =
|
|
342
|
+
i - Math.floor((numberOfMonthsShown - 1) / 2);
|
|
343
|
+
const monthDate = addMonths(
|
|
344
|
+
new Date(activeYear, activeMonth, 1),
|
|
345
|
+
offset
|
|
346
|
+
);
|
|
347
|
+
return (
|
|
348
|
+
<CalendarMonth
|
|
349
|
+
key={i}
|
|
350
|
+
year={monthDate.getFullYear()}
|
|
351
|
+
month={monthDate.getMonth()}
|
|
352
|
+
minDateAllowed={minDateAllowed}
|
|
353
|
+
maxDateAllowed={maxDateAllowed}
|
|
354
|
+
disabledDates={disabledDates}
|
|
355
|
+
dateFocused={focusedDate}
|
|
356
|
+
onDayFocused={handleDayFocused}
|
|
357
|
+
selectedDates={selectedDates}
|
|
358
|
+
onSelectionStart={handleSelectionStart}
|
|
359
|
+
onSelectionEnd={handleSelectionEnd}
|
|
360
|
+
highlightedDatesRange={highlightedDates}
|
|
361
|
+
onDaysHighlighted={handleDaysHighlighted}
|
|
362
|
+
firstDayOfWeek={firstDayOfWeek}
|
|
363
|
+
showOutsideDays={showOutsideDays}
|
|
364
|
+
daySize={daySize}
|
|
365
|
+
monthFormat={monthFormat}
|
|
366
|
+
showMonthHeader={numberOfMonthsShown > 1}
|
|
367
|
+
direction={direction}
|
|
368
|
+
/>
|
|
369
|
+
);
|
|
370
|
+
})}
|
|
371
|
+
</div>
|
|
372
|
+
</div>
|
|
373
|
+
);
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
const Calendar = forwardRef<CalendarHandle, CalendarProps>((props, ref) => {
|
|
377
|
+
return <CalendarComponent {...props} forwardedRef={ref} />;
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
Calendar.displayName = 'Calendar';
|
|
381
|
+
|
|
382
|
+
export default Calendar;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
DetailedHTMLProps,
|
|
3
|
+
TdHTMLAttributes,
|
|
4
|
+
useEffect,
|
|
5
|
+
useRef,
|
|
6
|
+
} from 'react';
|
|
7
|
+
|
|
8
|
+
type CalendarDayProps = DetailedHTMLProps<
|
|
9
|
+
TdHTMLAttributes<HTMLTableCellElement>,
|
|
10
|
+
HTMLTableCellElement
|
|
11
|
+
> & {
|
|
12
|
+
date: Date;
|
|
13
|
+
isOutside: boolean;
|
|
14
|
+
showOutsideDays: boolean;
|
|
15
|
+
isSelected?: boolean;
|
|
16
|
+
isHighlighted?: boolean;
|
|
17
|
+
isFocused?: boolean;
|
|
18
|
+
isDisabled?: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const CalendarDay = ({
|
|
22
|
+
date,
|
|
23
|
+
isOutside,
|
|
24
|
+
showOutsideDays,
|
|
25
|
+
isSelected = false,
|
|
26
|
+
isHighlighted = false,
|
|
27
|
+
isFocused = false,
|
|
28
|
+
isDisabled = false,
|
|
29
|
+
className,
|
|
30
|
+
...passThruProps
|
|
31
|
+
}: CalendarDayProps): JSX.Element => {
|
|
32
|
+
// Compute label: show day number unless it's an outside day and we're not showing outside days
|
|
33
|
+
const label = !showOutsideDays && isOutside ? '' : String(date.getDate());
|
|
34
|
+
|
|
35
|
+
let extraClasses = '';
|
|
36
|
+
|
|
37
|
+
if (isOutside) {
|
|
38
|
+
extraClasses += ' dash-datepicker-calendar-date-outside';
|
|
39
|
+
} else {
|
|
40
|
+
extraClasses += ' dash-datepicker-calendar-date-inside';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (isSelected) {
|
|
44
|
+
extraClasses += ' dash-datepicker-calendar-date-selected';
|
|
45
|
+
}
|
|
46
|
+
if (isHighlighted) {
|
|
47
|
+
extraClasses += ' dash-datepicker-calendar-date-highlighted';
|
|
48
|
+
}
|
|
49
|
+
if (isDisabled) {
|
|
50
|
+
extraClasses += ' dash-datepicker-calendar-date-disabled';
|
|
51
|
+
}
|
|
52
|
+
className = (className ?? '') + extraClasses;
|
|
53
|
+
|
|
54
|
+
const ref = useRef(document.createElement('td'));
|
|
55
|
+
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (isFocused) {
|
|
58
|
+
ref.current.focus();
|
|
59
|
+
}
|
|
60
|
+
}, [isFocused]);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<td
|
|
64
|
+
className={className}
|
|
65
|
+
{...passThruProps}
|
|
66
|
+
ref={ref}
|
|
67
|
+
aria-disabled={isDisabled}
|
|
68
|
+
tabIndex={isOutside || isDisabled ? undefined : 0}
|
|
69
|
+
>
|
|
70
|
+
<span>{label}</span>
|
|
71
|
+
</td>
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export default CalendarDay;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Renders an "empty" cell in a calendar month, representing days that fall
|
|
5
|
+
* outside the month
|
|
6
|
+
*/
|
|
7
|
+
const CalendarDayPadding = (): JSX.Element => {
|
|
8
|
+
return (
|
|
9
|
+
<td className="dash-datepicker-calendar-padding">
|
|
10
|
+
<span></span>
|
|
11
|
+
</td>
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default CalendarDayPadding;
|