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.
Files changed (48) hide show
  1. package/dash_core_components/async-datepicker.js +1 -1
  2. package/dash_core_components/async-datepicker.js.map +1 -1
  3. package/dash_core_components/async-dropdown.js +1 -1
  4. package/dash_core_components/async-dropdown.js.map +1 -1
  5. package/dash_core_components/async-graph.js +1 -1
  6. package/dash_core_components/async-graph.js.map +1 -1
  7. package/dash_core_components/async-highlight.js +1 -1
  8. package/dash_core_components/async-highlight.js.map +1 -1
  9. package/dash_core_components/async-markdown.js +1 -1
  10. package/dash_core_components/async-markdown.js.map +1 -1
  11. package/dash_core_components/async-slider.js +1 -1
  12. package/dash_core_components/async-slider.js.map +1 -1
  13. package/dash_core_components/async-upload.js +1 -2
  14. package/dash_core_components/async-upload.js.map +1 -1
  15. package/dash_core_components/dash_core_components-shared.js +1 -1
  16. package/dash_core_components/dash_core_components-shared.js.map +1 -1
  17. package/dash_core_components/dash_core_components.js +1 -1
  18. package/dash_core_components/dash_core_components.js.map +1 -1
  19. package/dash_core_components/proptypes.js +1 -0
  20. package/lib/components/Checklist.tsx +1 -1
  21. package/lib/components/Clipboard.react.js +53 -100
  22. package/lib/components/ConfirmDialog.react.js +6 -5
  23. package/lib/components/ConfirmDialogProvider.react.js +6 -5
  24. package/lib/components/Download.react.js +3 -1
  25. package/lib/components/Graph.react.js +5 -10
  26. package/lib/components/Interval.react.js +4 -3
  27. package/lib/components/Link.react.js +13 -10
  28. package/lib/components/Location.react.js +11 -7
  29. package/lib/components/Markdown.react.js +1 -8
  30. package/lib/components/RadioItems.tsx +1 -1
  31. package/lib/components/Store.react.js +16 -13
  32. package/lib/components/css/datepickers.css +5 -0
  33. package/lib/components/css/dropdown.css +12 -0
  34. package/lib/fragments/DatePickerRange.tsx +195 -143
  35. package/lib/fragments/DatePickerSingle.tsx +126 -111
  36. package/lib/fragments/Dropdown.tsx +202 -131
  37. package/lib/fragments/Graph.react.js +43 -40
  38. package/lib/fragments/Markdown.react.js +27 -38
  39. package/lib/fragments/Upload.react.js +117 -202
  40. package/lib/types.ts +5 -0
  41. package/lib/utils/LoadingElement.js +3 -2
  42. package/lib/utils/ResizeDetector.js +5 -3
  43. package/lib/utils/calendar/Calendar.tsx +1 -3
  44. package/lib/utils/calendar/helpers.ts +1 -0
  45. package/lib/utils/dropdownSearch.ts +36 -45
  46. package/lib/utils/optionRendering.tsx +284 -43
  47. package/lib/utils/optionTypes.ts +25 -11
  48. 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 undefined for both
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
- [internalStartDate, internalEndDate, stay_open_on_select]
351
+ [
352
+ internalStartDate,
353
+ internalEndDate,
354
+ stay_open_on_select,
355
+ minimum_nights,
356
+ ]
313
357
  );
314
358
 
315
359
  return (
316
- <div className="dash-datepicker" ref={containerRef}>
317
- <Popover.Root
318
- open={!disabled && isCalendarOpen}
319
- onOpenChange={disabled ? undefined : setIsCalendarOpen}
320
- >
321
- <Popover.Trigger asChild disabled={disabled}>
322
- <div
323
- id={accessibleId + '-wrapper'}
324
- className={classNames}
325
- style={style}
326
- aria-labelledby={`${accessibleId} ${accessibleId}-end-date ${start_date_id} ${end_date_id}`}
327
- aria-haspopup="dialog"
328
- aria-expanded={isCalendarOpen}
329
- aria-disabled={disabled}
330
- onClick={e => {
331
- e.preventDefault();
332
- if (!isCalendarOpen && !disabled) {
333
- setIsCalendarOpen(true);
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
- placeholder={start_date_placeholder_text}
353
- disabled={disabled}
354
- dir={direction}
355
- aria-label={start_date_placeholder_text}
356
- />
357
- <ArrowIcon className="dash-datepicker-range-arrow" />
358
- <AutosizeInput
359
- inputRef={node => {
360
- endInputRef.current = node;
361
- }}
362
- type="text"
363
- id={end_date_id || accessibleId + '-end-date'}
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
- placeholder={end_date_placeholder_text}
374
- disabled={disabled}
375
- dir={direction}
376
- aria-label={end_date_placeholder_text}
377
- />
378
- {clearable && !disabled && (
379
- <a
380
- className="dash-datepicker-clear"
381
- onClick={clearSelection}
382
- aria-label="Clear Dates"
383
- >
384
- <Cross1Icon />
385
- </a>
386
- )}
387
- <CaretDownIcon className="dash-datepicker-caret-icon" />
388
- </div>
389
- </Popover.Trigger>
390
-
391
- <Popover.Portal
392
- container={hasPortal ? undefined : containerRef.current}
393
- >
394
- <Popover.Content
395
- className={`dash-datepicker-content${
396
- hasPortal ? ' dash-datepicker-portal' : ''
397
- }${
398
- with_full_screen_portal
399
- ? ' dash-datepicker-fullscreen'
400
- : ''
401
- }`}
402
- style={portalStyle}
403
- align={hasPortal ? 'center' : 'start'}
404
- sideOffset={hasPortal ? 0 : 5}
405
- avoidCollisions={!hasPortal}
406
- onInteractOutside={
407
- with_full_screen_portal
408
- ? e => e.preventDefault()
409
- : undefined
410
- }
411
- onOpenAutoFocus={e => e.preventDefault()}
412
- onCloseAutoFocus={e => {
413
- e.preventDefault();
414
- // Only focus if focus is not already on one of the inputs
415
- const inputs: (Element | null)[] = [
416
- startInputRef.current,
417
- endInputRef.current,
418
- ];
419
- if (inputs.includes(document.activeElement)) {
420
- return;
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
- // Keeps focus on the component when the calendar closes
424
- if (!startInputValue) {
425
- startInputRef.current?.focus();
426
- } else {
427
- endInputRef.current?.focus();
428
- }
429
- }}
430
- >
431
- {with_full_screen_portal && (
432
- <button
433
- className="dash-datepicker-close-button"
434
- onClick={() => setIsCalendarOpen(false)}
435
- aria-label="Close calendar"
436
- >
437
- <Cross1Icon />
438
- </button>
439
- )}
440
- <Calendar
441
- ref={calendarRef}
442
- initialVisibleDate={initialCalendarDate}
443
- selectionStart={internalStartDate}
444
- selectionEnd={internalEndDate}
445
- minDateAllowed={minDate}
446
- maxDateAllowed={maxDate}
447
- disabledDates={disabledDates}
448
- firstDayOfWeek={first_day_of_week}
449
- showOutsideDays={show_outside_days}
450
- monthFormat={month_format}
451
- numberOfMonthsShown={number_of_months_shown}
452
- calendarOrientation={calendar_orientation}
453
- daySize={day_size}
454
- direction={direction}
455
- onSelectionChange={handleSelectionChange}
456
- />
457
- </Popover.Content>
458
- </Popover.Portal>
459
- </Popover.Root>
460
- </div>
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