dash-core-components 4.0.0 → 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-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 +1 -0
- package/lib/components/Checklist.tsx +1 -1
- package/lib/components/Clipboard.react.js +53 -100
- 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/Store.react.js +16 -13
- package/lib/components/css/datepickers.css +5 -0
- package/lib/components/css/dropdown.css +12 -0
- package/lib/fragments/DatePickerRange.tsx +195 -143
- package/lib/fragments/DatePickerSingle.tsx +126 -111
- 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/Upload.react.js +117 -202
- package/lib/types.ts +5 -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/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 +4 -3
|
@@ -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
|
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
strAsDate,
|
|
21
21
|
} from '../utils/calendar/helpers';
|
|
22
22
|
import {captureCSSForPortal} from '../utils/calendar/cssVariables';
|
|
23
|
+
import ResizeDetector from '../utils/ResizeDetector';
|
|
23
24
|
import '../components/css/datepickers.css';
|
|
24
25
|
|
|
25
26
|
const DatePickerRange = ({
|
|
@@ -104,7 +105,10 @@ const DatePickerRange = ({
|
|
|
104
105
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
105
106
|
const startInputRef = useRef<HTMLInputElement | null>(null);
|
|
106
107
|
const endInputRef = useRef<HTMLInputElement | null>(null);
|
|
108
|
+
const startAutosizeRef = useRef<any>(null);
|
|
109
|
+
const endAutosizeRef = useRef<any>(null);
|
|
107
110
|
const calendarRef = useRef<CalendarHandle>(null);
|
|
111
|
+
const isNewRangeRef = useRef(false);
|
|
108
112
|
const hasPortal = with_portal || with_full_screen_portal;
|
|
109
113
|
|
|
110
114
|
// Capture CSS variables for portal mode
|
|
@@ -128,6 +132,19 @@ const DatePickerRange = ({
|
|
|
128
132
|
setEndInputValue(formatDate(internalEndDate, display_format));
|
|
129
133
|
}, [internalEndDate, display_format]);
|
|
130
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
|
+
|
|
131
148
|
useEffect(() => {
|
|
132
149
|
// Controls when setProps is called. Basically, whenever internal state
|
|
133
150
|
// diverges from props (i.e., user interaction)
|
|
@@ -145,11 +162,17 @@ const DatePickerRange = ({
|
|
|
145
162
|
end_date: dateAsStr(internalEndDate),
|
|
146
163
|
});
|
|
147
164
|
} else if (!internalStartDate && !internalEndDate) {
|
|
148
|
-
// Both dates cleared - send
|
|
165
|
+
// Both dates cleared - send both
|
|
149
166
|
setProps({
|
|
150
167
|
start_date: dateAsStr(internalStartDate),
|
|
151
168
|
end_date: dateAsStr(internalEndDate),
|
|
152
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
|
+
});
|
|
153
176
|
} else if (updatemode === 'singledate' && internalStartDate) {
|
|
154
177
|
// Only start changed - send just that one
|
|
155
178
|
setProps({start_date: dateAsStr(internalStartDate)});
|
|
@@ -295,6 +318,22 @@ const DatePickerRange = ({
|
|
|
295
318
|
setInternalStartDate(start);
|
|
296
319
|
setInternalEndDate(undefined);
|
|
297
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
|
+
|
|
298
337
|
// Normalize dates: ensure start <= end
|
|
299
338
|
if (start && end && start > end) {
|
|
300
339
|
setInternalStartDate(end);
|
|
@@ -309,155 +348,168 @@ const DatePickerRange = ({
|
|
|
309
348
|
}
|
|
310
349
|
}
|
|
311
350
|
},
|
|
312
|
-
[
|
|
351
|
+
[
|
|
352
|
+
internalStartDate,
|
|
353
|
+
internalEndDate,
|
|
354
|
+
stay_open_on_select,
|
|
355
|
+
minimum_nights,
|
|
356
|
+
]
|
|
313
357
|
);
|
|
314
358
|
|
|
315
359
|
return (
|
|
316
|
-
<
|
|
317
|
-
<
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
<
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
e
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}}
|
|
336
|
-
>
|
|
337
|
-
<AutosizeInput
|
|
338
|
-
inputRef={node => {
|
|
339
|
-
startInputRef.current = node;
|
|
340
|
-
}}
|
|
341
|
-
type="text"
|
|
342
|
-
id={start_date_id || accessibleId}
|
|
343
|
-
inputClassName="dash-datepicker-input dash-datepicker-start-date"
|
|
344
|
-
value={startInputValue}
|
|
345
|
-
onChange={e => setStartInputValue(e.target?.value)}
|
|
346
|
-
onKeyDown={handleStartInputKeyDown}
|
|
347
|
-
onFocus={() => {
|
|
348
|
-
if (isCalendarOpen) {
|
|
349
|
-
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);
|
|
350
379
|
}
|
|
351
380
|
}}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
inputClassName="dash-datepicker-input dash-datepicker-end-date"
|
|
365
|
-
value={endInputValue}
|
|
366
|
-
onChange={e => setEndInputValue(e.target?.value)}
|
|
367
|
-
onKeyDown={handleEndInputKeyDown}
|
|
368
|
-
onFocus={() => {
|
|
369
|
-
if (isCalendarOpen) {
|
|
370
|
-
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)
|
|
371
393
|
}
|
|
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
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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>
|
|
441
|
+
|
|
442
|
+
<Popover.Portal
|
|
443
|
+
container={hasPortal ? undefined : containerRef.current}
|
|
444
|
+
>
|
|
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
|
|
421
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
|
+
}
|
|
422
473
|
|
|
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
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
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>
|
|
461
513
|
);
|
|
462
514
|
};
|
|
463
515
|
|