dash-core-components 4.0.0-rc6 → 4.1.0
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-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 -2
- 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 +3 -0
- package/lib/components/Checklist.tsx +1 -1
- package/lib/components/Clipboard.react.js +67 -105
- package/lib/components/ConfirmDialog.react.js +6 -5
- package/lib/components/ConfirmDialogProvider.react.js +6 -5
- package/lib/components/Download.react.js +3 -1
- package/lib/components/Graph.react.js +5 -10
- package/lib/components/Interval.react.js +4 -3
- package/lib/components/Link.react.js +13 -10
- package/lib/components/Location.react.js +11 -7
- package/lib/components/Markdown.react.js +1 -8
- package/lib/components/RadioItems.tsx +1 -1
- package/lib/components/RangeSlider.tsx +2 -0
- package/lib/components/Slider.tsx +2 -0
- package/lib/components/Store.react.js +16 -13
- package/lib/components/css/calendar.css +20 -3
- package/lib/components/css/datepickers.css +9 -2
- package/lib/components/css/dropdown.css +12 -0
- package/lib/components/css/optionslist.css +0 -1
- package/lib/fragments/DatePickerRange.tsx +201 -140
- package/lib/fragments/DatePickerSingle.tsx +132 -108
- package/lib/fragments/Dropdown.tsx +202 -131
- package/lib/fragments/Graph.react.js +43 -40
- package/lib/fragments/Markdown.react.js +27 -38
- package/lib/fragments/RangeSlider.tsx +2 -0
- package/lib/fragments/Upload.react.js +117 -202
- package/lib/types.ts +17 -0
- package/lib/utils/LoadingElement.js +3 -2
- package/lib/utils/ResizeDetector.js +5 -3
- package/lib/utils/calendar/Calendar.tsx +1 -3
- package/lib/utils/calendar/cssVariables.ts +41 -0
- package/lib/utils/calendar/helpers.ts +1 -0
- package/lib/utils/dropdownSearch.ts +36 -45
- package/lib/utils/optionRendering.tsx +284 -43
- package/lib/utils/optionTypes.ts +25 -11
- package/package.json +9 -8
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
CaretDownIcon,
|
|
7
7
|
Cross1Icon,
|
|
8
8
|
} from '@radix-ui/react-icons';
|
|
9
|
-
import {addDays, subDays} from 'date-fns';
|
|
9
|
+
import {addDays, subDays, differenceInCalendarDays} from 'date-fns';
|
|
10
10
|
import AutosizeInput from 'react-input-autosize';
|
|
11
11
|
import uuid from 'uniqid';
|
|
12
12
|
|
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
isSameDay,
|
|
20
20
|
strAsDate,
|
|
21
21
|
} from '../utils/calendar/helpers';
|
|
22
|
+
import {captureCSSForPortal} from '../utils/calendar/cssVariables';
|
|
23
|
+
import ResizeDetector from '../utils/ResizeDetector';
|
|
22
24
|
import '../components/css/datepickers.css';
|
|
23
25
|
|
|
24
26
|
const DatePickerRange = ({
|
|
@@ -103,9 +105,17 @@ const DatePickerRange = ({
|
|
|
103
105
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
104
106
|
const startInputRef = useRef<HTMLInputElement | null>(null);
|
|
105
107
|
const endInputRef = useRef<HTMLInputElement | null>(null);
|
|
108
|
+
const startAutosizeRef = useRef<any>(null);
|
|
109
|
+
const endAutosizeRef = useRef<any>(null);
|
|
106
110
|
const calendarRef = useRef<CalendarHandle>(null);
|
|
111
|
+
const isNewRangeRef = useRef(false);
|
|
107
112
|
const hasPortal = with_portal || with_full_screen_portal;
|
|
108
113
|
|
|
114
|
+
// Capture CSS variables for portal mode
|
|
115
|
+
const portalStyle = useMemo(() => {
|
|
116
|
+
return hasPortal ? captureCSSForPortal(containerRef) : undefined;
|
|
117
|
+
}, [hasPortal, isCalendarOpen]);
|
|
118
|
+
|
|
109
119
|
useEffect(() => {
|
|
110
120
|
setInternalStartDate(strAsDate(start_date));
|
|
111
121
|
}, [start_date]);
|
|
@@ -122,6 +132,19 @@ const DatePickerRange = ({
|
|
|
122
132
|
setEndInputValue(formatDate(internalEndDate, display_format));
|
|
123
133
|
}, [internalEndDate, display_format]);
|
|
124
134
|
|
|
135
|
+
const handleResize = useCallback(() => {
|
|
136
|
+
startAutosizeRef.current?.updateInputWidth?.();
|
|
137
|
+
endAutosizeRef.current?.updateInputWidth?.();
|
|
138
|
+
}, []);
|
|
139
|
+
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
startAutosizeRef.current?.updateInputWidth?.();
|
|
142
|
+
}, [startInputValue]);
|
|
143
|
+
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
endAutosizeRef.current?.updateInputWidth?.();
|
|
146
|
+
}, [endInputValue]);
|
|
147
|
+
|
|
125
148
|
useEffect(() => {
|
|
126
149
|
// Controls when setProps is called. Basically, whenever internal state
|
|
127
150
|
// diverges from props (i.e., user interaction)
|
|
@@ -139,11 +162,17 @@ const DatePickerRange = ({
|
|
|
139
162
|
end_date: dateAsStr(internalEndDate),
|
|
140
163
|
});
|
|
141
164
|
} else if (!internalStartDate && !internalEndDate) {
|
|
142
|
-
// Both dates cleared - send
|
|
165
|
+
// Both dates cleared - send both
|
|
143
166
|
setProps({
|
|
144
167
|
start_date: dateAsStr(internalStartDate),
|
|
145
168
|
end_date: dateAsStr(internalEndDate),
|
|
146
169
|
});
|
|
170
|
+
} else if (endChanged && !internalEndDate) {
|
|
171
|
+
// End date was cleared (user started a new range).
|
|
172
|
+
setProps({
|
|
173
|
+
start_date: dateAsStr(internalStartDate) ?? null,
|
|
174
|
+
end_date: null,
|
|
175
|
+
});
|
|
147
176
|
} else if (updatemode === 'singledate' && internalStartDate) {
|
|
148
177
|
// Only start changed - send just that one
|
|
149
178
|
setProps({start_date: dateAsStr(internalStartDate)});
|
|
@@ -289,6 +318,22 @@ const DatePickerRange = ({
|
|
|
289
318
|
setInternalStartDate(start);
|
|
290
319
|
setInternalEndDate(undefined);
|
|
291
320
|
} else {
|
|
321
|
+
// Skip the mouseUp from the same click that started this range
|
|
322
|
+
if (isNewRangeRef.current && isSameDay(start, end)) {
|
|
323
|
+
isNewRangeRef.current = false;
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
isNewRangeRef.current = !!(start && !end);
|
|
327
|
+
|
|
328
|
+
if (start && end && minimum_nights) {
|
|
329
|
+
const numNights = Math.abs(
|
|
330
|
+
differenceInCalendarDays(end, start)
|
|
331
|
+
);
|
|
332
|
+
if (numNights < minimum_nights) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
292
337
|
// Normalize dates: ensure start <= end
|
|
293
338
|
if (start && end && start > end) {
|
|
294
339
|
setInternalStartDate(end);
|
|
@@ -303,152 +348,168 @@ const DatePickerRange = ({
|
|
|
303
348
|
}
|
|
304
349
|
}
|
|
305
350
|
},
|
|
306
|
-
[
|
|
351
|
+
[
|
|
352
|
+
internalStartDate,
|
|
353
|
+
internalEndDate,
|
|
354
|
+
stay_open_on_select,
|
|
355
|
+
minimum_nights,
|
|
356
|
+
]
|
|
307
357
|
);
|
|
308
358
|
|
|
309
359
|
return (
|
|
310
|
-
<
|
|
311
|
-
<
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
<
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
e
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}}
|
|
330
|
-
>
|
|
331
|
-
<AutosizeInput
|
|
332
|
-
inputRef={node => {
|
|
333
|
-
startInputRef.current = node;
|
|
334
|
-
}}
|
|
335
|
-
type="text"
|
|
336
|
-
id={start_date_id || accessibleId}
|
|
337
|
-
inputClassName="dash-datepicker-input dash-datepicker-start-date"
|
|
338
|
-
value={startInputValue}
|
|
339
|
-
onChange={e => setStartInputValue(e.target?.value)}
|
|
340
|
-
onKeyDown={handleStartInputKeyDown}
|
|
341
|
-
onFocus={() => {
|
|
342
|
-
if (isCalendarOpen) {
|
|
343
|
-
sendStartInputAsDate();
|
|
360
|
+
<ResizeDetector onResize={handleResize} targets={[containerRef]}>
|
|
361
|
+
<div className="dash-datepicker" ref={containerRef}>
|
|
362
|
+
<Popover.Root
|
|
363
|
+
open={!disabled && isCalendarOpen}
|
|
364
|
+
onOpenChange={disabled ? undefined : setIsCalendarOpen}
|
|
365
|
+
>
|
|
366
|
+
<Popover.Trigger asChild disabled={disabled}>
|
|
367
|
+
<div
|
|
368
|
+
id={accessibleId + '-wrapper'}
|
|
369
|
+
className={classNames}
|
|
370
|
+
style={style}
|
|
371
|
+
aria-labelledby={`${accessibleId} ${accessibleId}-end-date ${start_date_id} ${end_date_id}`}
|
|
372
|
+
aria-haspopup="dialog"
|
|
373
|
+
aria-expanded={isCalendarOpen}
|
|
374
|
+
aria-disabled={disabled}
|
|
375
|
+
onClick={e => {
|
|
376
|
+
e.preventDefault();
|
|
377
|
+
if (!isCalendarOpen && !disabled) {
|
|
378
|
+
setIsCalendarOpen(true);
|
|
344
379
|
}
|
|
345
380
|
}}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
inputClassName="dash-datepicker-input dash-datepicker-end-date"
|
|
359
|
-
value={endInputValue}
|
|
360
|
-
onChange={e => setEndInputValue(e.target?.value)}
|
|
361
|
-
onKeyDown={handleEndInputKeyDown}
|
|
362
|
-
onFocus={() => {
|
|
363
|
-
if (isCalendarOpen) {
|
|
364
|
-
sendEndInputAsDate();
|
|
381
|
+
>
|
|
382
|
+
<AutosizeInput
|
|
383
|
+
ref={startAutosizeRef}
|
|
384
|
+
inputRef={node => {
|
|
385
|
+
startInputRef.current = node;
|
|
386
|
+
}}
|
|
387
|
+
type="text"
|
|
388
|
+
id={start_date_id || accessibleId}
|
|
389
|
+
inputClassName="dash-datepicker-input dash-datepicker-start-date"
|
|
390
|
+
value={startInputValue}
|
|
391
|
+
onChange={e =>
|
|
392
|
+
setStartInputValue(e.target?.value)
|
|
365
393
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
394
|
+
onKeyDown={handleStartInputKeyDown}
|
|
395
|
+
onFocus={() => {
|
|
396
|
+
if (isCalendarOpen) {
|
|
397
|
+
sendStartInputAsDate();
|
|
398
|
+
}
|
|
399
|
+
}}
|
|
400
|
+
placeholder={start_date_placeholder_text}
|
|
401
|
+
disabled={disabled}
|
|
402
|
+
dir={direction}
|
|
403
|
+
aria-label={start_date_placeholder_text}
|
|
404
|
+
/>
|
|
405
|
+
<ArrowIcon className="dash-datepicker-range-arrow" />
|
|
406
|
+
<AutosizeInput
|
|
407
|
+
ref={endAutosizeRef}
|
|
408
|
+
inputRef={node => {
|
|
409
|
+
endInputRef.current = node;
|
|
410
|
+
}}
|
|
411
|
+
type="text"
|
|
412
|
+
id={end_date_id || accessibleId + '-end-date'}
|
|
413
|
+
inputClassName="dash-datepicker-input dash-datepicker-end-date"
|
|
414
|
+
value={endInputValue}
|
|
415
|
+
onChange={e =>
|
|
416
|
+
setEndInputValue(e.target?.value)
|
|
417
|
+
}
|
|
418
|
+
onKeyDown={handleEndInputKeyDown}
|
|
419
|
+
onFocus={() => {
|
|
420
|
+
if (isCalendarOpen) {
|
|
421
|
+
sendEndInputAsDate();
|
|
422
|
+
}
|
|
423
|
+
}}
|
|
424
|
+
placeholder={end_date_placeholder_text}
|
|
425
|
+
disabled={disabled}
|
|
426
|
+
dir={direction}
|
|
427
|
+
aria-label={end_date_placeholder_text}
|
|
428
|
+
/>
|
|
429
|
+
{clearable && !disabled && (
|
|
430
|
+
<a
|
|
431
|
+
className="dash-datepicker-clear"
|
|
432
|
+
onClick={clearSelection}
|
|
433
|
+
aria-label="Clear Dates"
|
|
434
|
+
>
|
|
435
|
+
<Cross1Icon />
|
|
436
|
+
</a>
|
|
437
|
+
)}
|
|
438
|
+
<CaretDownIcon className="dash-datepicker-caret-icon" />
|
|
439
|
+
</div>
|
|
440
|
+
</Popover.Trigger>
|
|
413
441
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
startInputRef.current?.focus();
|
|
417
|
-
} else {
|
|
418
|
-
endInputRef.current?.focus();
|
|
419
|
-
}
|
|
420
|
-
}}
|
|
442
|
+
<Popover.Portal
|
|
443
|
+
container={hasPortal ? undefined : containerRef.current}
|
|
421
444
|
>
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
445
|
+
<Popover.Content
|
|
446
|
+
className={`dash-datepicker-content${
|
|
447
|
+
hasPortal ? ' dash-datepicker-portal' : ''
|
|
448
|
+
}${
|
|
449
|
+
with_full_screen_portal
|
|
450
|
+
? ' dash-datepicker-fullscreen'
|
|
451
|
+
: ''
|
|
452
|
+
}`}
|
|
453
|
+
style={portalStyle}
|
|
454
|
+
align={hasPortal ? 'center' : 'start'}
|
|
455
|
+
sideOffset={hasPortal ? 0 : 5}
|
|
456
|
+
avoidCollisions={!hasPortal}
|
|
457
|
+
onInteractOutside={
|
|
458
|
+
with_full_screen_portal
|
|
459
|
+
? e => e.preventDefault()
|
|
460
|
+
: undefined
|
|
461
|
+
}
|
|
462
|
+
onOpenAutoFocus={e => e.preventDefault()}
|
|
463
|
+
onCloseAutoFocus={e => {
|
|
464
|
+
e.preventDefault();
|
|
465
|
+
// Only focus if focus is not already on one of the inputs
|
|
466
|
+
const inputs: (Element | null)[] = [
|
|
467
|
+
startInputRef.current,
|
|
468
|
+
endInputRef.current,
|
|
469
|
+
];
|
|
470
|
+
if (inputs.includes(document.activeElement)) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Keeps focus on the component when the calendar closes
|
|
475
|
+
if (!startInputValue) {
|
|
476
|
+
startInputRef.current?.focus();
|
|
477
|
+
} else {
|
|
478
|
+
endInputRef.current?.focus();
|
|
479
|
+
}
|
|
480
|
+
}}
|
|
481
|
+
>
|
|
482
|
+
{with_full_screen_portal && (
|
|
483
|
+
<button
|
|
484
|
+
className="dash-datepicker-close-button"
|
|
485
|
+
onClick={() => setIsCalendarOpen(false)}
|
|
486
|
+
aria-label="Close calendar"
|
|
487
|
+
>
|
|
488
|
+
<Cross1Icon />
|
|
489
|
+
</button>
|
|
490
|
+
)}
|
|
491
|
+
<Calendar
|
|
492
|
+
ref={calendarRef}
|
|
493
|
+
initialVisibleDate={initialCalendarDate}
|
|
494
|
+
selectionStart={internalStartDate}
|
|
495
|
+
selectionEnd={internalEndDate}
|
|
496
|
+
minDateAllowed={minDate}
|
|
497
|
+
maxDateAllowed={maxDate}
|
|
498
|
+
disabledDates={disabledDates}
|
|
499
|
+
firstDayOfWeek={first_day_of_week}
|
|
500
|
+
showOutsideDays={show_outside_days}
|
|
501
|
+
monthFormat={month_format}
|
|
502
|
+
numberOfMonthsShown={number_of_months_shown}
|
|
503
|
+
calendarOrientation={calendar_orientation}
|
|
504
|
+
daySize={day_size}
|
|
505
|
+
direction={direction}
|
|
506
|
+
onSelectionChange={handleSelectionChange}
|
|
507
|
+
/>
|
|
508
|
+
</Popover.Content>
|
|
509
|
+
</Popover.Portal>
|
|
510
|
+
</Popover.Root>
|
|
511
|
+
</div>
|
|
512
|
+
</ResizeDetector>
|
|
452
513
|
);
|
|
453
514
|
};
|
|
454
515
|
|