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.
Files changed (55) 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-mathjax.js +1 -1
  12. package/dash_core_components/async-slider.js +1 -1
  13. package/dash_core_components/async-slider.js.map +1 -1
  14. package/dash_core_components/async-upload.js +1 -2
  15. package/dash_core_components/async-upload.js.map +1 -1
  16. package/dash_core_components/dash_core_components-shared.js +1 -1
  17. package/dash_core_components/dash_core_components-shared.js.map +1 -1
  18. package/dash_core_components/dash_core_components.js +1 -1
  19. package/dash_core_components/dash_core_components.js.map +1 -1
  20. package/dash_core_components/proptypes.js +3 -0
  21. package/lib/components/Checklist.tsx +1 -1
  22. package/lib/components/Clipboard.react.js +67 -105
  23. package/lib/components/ConfirmDialog.react.js +6 -5
  24. package/lib/components/ConfirmDialogProvider.react.js +6 -5
  25. package/lib/components/Download.react.js +3 -1
  26. package/lib/components/Graph.react.js +5 -10
  27. package/lib/components/Interval.react.js +4 -3
  28. package/lib/components/Link.react.js +13 -10
  29. package/lib/components/Location.react.js +11 -7
  30. package/lib/components/Markdown.react.js +1 -8
  31. package/lib/components/RadioItems.tsx +1 -1
  32. package/lib/components/RangeSlider.tsx +2 -0
  33. package/lib/components/Slider.tsx +2 -0
  34. package/lib/components/Store.react.js +16 -13
  35. package/lib/components/css/calendar.css +20 -3
  36. package/lib/components/css/datepickers.css +9 -2
  37. package/lib/components/css/dropdown.css +12 -0
  38. package/lib/components/css/optionslist.css +0 -1
  39. package/lib/fragments/DatePickerRange.tsx +201 -140
  40. package/lib/fragments/DatePickerSingle.tsx +132 -108
  41. package/lib/fragments/Dropdown.tsx +202 -131
  42. package/lib/fragments/Graph.react.js +43 -40
  43. package/lib/fragments/Markdown.react.js +27 -38
  44. package/lib/fragments/RangeSlider.tsx +2 -0
  45. package/lib/fragments/Upload.react.js +117 -202
  46. package/lib/types.ts +17 -0
  47. package/lib/utils/LoadingElement.js +3 -2
  48. package/lib/utils/ResizeDetector.js +5 -3
  49. package/lib/utils/calendar/Calendar.tsx +1 -3
  50. package/lib/utils/calendar/cssVariables.ts +41 -0
  51. package/lib/utils/calendar/helpers.ts +1 -0
  52. package/lib/utils/dropdownSearch.ts +36 -45
  53. package/lib/utils/optionRendering.tsx +284 -43
  54. package/lib/utils/optionTypes.ts +25 -11
  55. package/package.json +9 -8
@@ -13,6 +13,8 @@ import {
13
13
  isSameDay,
14
14
  strAsDate,
15
15
  } from '../utils/calendar/helpers';
16
+ import {captureCSSForPortal} from '../utils/calendar/cssVariables';
17
+ import ResizeDetector from '../utils/ResizeDetector';
16
18
  import '../components/css/datepickers.css';
17
19
 
18
20
  const DatePickerSingle = ({
@@ -62,9 +64,15 @@ const DatePickerSingle = ({
62
64
 
63
65
  const containerRef = useRef<HTMLDivElement>(null);
64
66
  const inputRef = useRef<HTMLInputElement | null>(null);
67
+ const autosizeRef = useRef<any>(null);
65
68
  const calendarRef = useRef<CalendarHandle>(null);
66
69
  const hasPortal = with_portal || with_full_screen_portal;
67
70
 
71
+ // Capture CSS variables for portal mode
72
+ const portalStyle = useMemo(() => {
73
+ return hasPortal ? captureCSSForPortal(containerRef) : undefined;
74
+ }, [hasPortal, isCalendarOpen]);
75
+
68
76
  useEffect(() => {
69
77
  setInternalDate(strAsDate(date));
70
78
  }, [date]);
@@ -81,6 +89,14 @@ const DatePickerSingle = ({
81
89
  }
82
90
  }, [internalDate]);
83
91
 
92
+ const handleResize = useCallback(() => {
93
+ autosizeRef.current?.updateInputWidth?.();
94
+ }, []);
95
+
96
+ useEffect(() => {
97
+ autosizeRef.current?.updateInputWidth?.();
98
+ }, [inputValue]);
99
+
84
100
  const parseUserInput = useCallback(
85
101
  (focusCalendar = false) => {
86
102
  if (inputValue === '') {
@@ -151,120 +167,128 @@ const DatePickerSingle = ({
151
167
  }
152
168
 
153
169
  return (
154
- <div className="dash-datepicker" ref={containerRef}>
155
- <Popover.Root
156
- open={!disabled && isCalendarOpen}
157
- onOpenChange={disabled ? undefined : setIsCalendarOpen}
158
- >
159
- <Popover.Trigger asChild disabled={disabled}>
160
- <div
161
- id={accessibleId + '-wrapper'}
162
- className={classNames}
163
- style={style}
164
- aria-labelledby={`${accessibleId}`}
165
- aria-haspopup="dialog"
166
- aria-expanded={isCalendarOpen}
167
- aria-disabled={disabled}
168
- onClick={e => {
169
- e.preventDefault();
170
- if (!isCalendarOpen && !disabled) {
171
- setIsCalendarOpen(true);
172
- }
173
- }}
174
- >
175
- <AutosizeInput
176
- inputRef={node => {
177
- inputRef.current = node;
170
+ <ResizeDetector onResize={handleResize} targets={[containerRef]}>
171
+ <div className="dash-datepicker" ref={containerRef}>
172
+ <Popover.Root
173
+ open={!disabled && isCalendarOpen}
174
+ onOpenChange={disabled ? undefined : setIsCalendarOpen}
175
+ >
176
+ <Popover.Trigger asChild disabled={disabled}>
177
+ <div
178
+ id={accessibleId + '-wrapper'}
179
+ className={classNames}
180
+ style={style}
181
+ aria-labelledby={`${accessibleId}`}
182
+ aria-haspopup="dialog"
183
+ aria-expanded={isCalendarOpen}
184
+ aria-disabled={disabled}
185
+ onClick={e => {
186
+ e.preventDefault();
187
+ if (!isCalendarOpen && !disabled) {
188
+ setIsCalendarOpen(true);
189
+ }
178
190
  }}
179
- type="text"
180
- id={accessibleId}
181
- inputClassName="dash-datepicker-input dash-datepicker-end-date"
182
- value={inputValue}
183
- onChange={e => setInputValue(e.target?.value)}
184
- onKeyDown={handleInputKeyDown}
185
- placeholder={placeholder}
186
- disabled={disabled}
187
- dir={direction}
188
- aria-label={placeholder}
189
- />
190
- {clearable && !disabled && !!date && (
191
- <a
192
- className="dash-datepicker-clear"
193
- onClick={clearSelection}
194
- aria-label="Clear date"
195
- >
196
- <Cross1Icon />
197
- </a>
198
- )}
191
+ >
192
+ <AutosizeInput
193
+ ref={autosizeRef}
194
+ inputRef={node => {
195
+ inputRef.current = node;
196
+ }}
197
+ type="text"
198
+ id={accessibleId}
199
+ inputClassName="dash-datepicker-input dash-datepicker-end-date"
200
+ value={inputValue}
201
+ onChange={e => setInputValue(e.target?.value)}
202
+ onKeyDown={handleInputKeyDown}
203
+ placeholder={placeholder}
204
+ disabled={disabled}
205
+ dir={direction}
206
+ aria-label={placeholder}
207
+ />
208
+ {clearable && !disabled && !!date && (
209
+ <a
210
+ className="dash-datepicker-clear"
211
+ onClick={clearSelection}
212
+ aria-label="Clear date"
213
+ >
214
+ <Cross1Icon />
215
+ </a>
216
+ )}
199
217
 
200
- <CaretDownIcon className="dash-datepicker-caret-icon" />
201
- </div>
202
- </Popover.Trigger>
218
+ <CaretDownIcon className="dash-datepicker-caret-icon" />
219
+ </div>
220
+ </Popover.Trigger>
203
221
 
204
- <Popover.Portal container={containerRef.current}>
205
- <Popover.Content
206
- className={`dash-datepicker-content${
207
- hasPortal ? ' dash-datepicker-portal' : ''
208
- }${
209
- with_full_screen_portal
210
- ? ' dash-datepicker-fullscreen'
211
- : ''
212
- }`}
213
- align={hasPortal ? 'center' : 'start'}
214
- sideOffset={hasPortal ? 0 : 5}
215
- avoidCollisions={!hasPortal}
216
- onInteractOutside={
217
- with_full_screen_portal
218
- ? e => e.preventDefault()
219
- : undefined
220
- }
221
- onOpenAutoFocus={e => e.preventDefault()}
222
- onCloseAutoFocus={e => {
223
- e.preventDefault();
224
- // Only focus if focus is not already on the input
225
- if (document.activeElement !== inputRef.current) {
226
- inputRef.current?.focus();
227
- }
228
- }}
222
+ <Popover.Portal
223
+ container={hasPortal ? undefined : containerRef.current}
229
224
  >
230
- {with_full_screen_portal && (
231
- <button
232
- className="dash-datepicker-close-button"
233
- onClick={() => setIsCalendarOpen(false)}
234
- aria-label="Close calendar"
235
- >
236
- <Cross1Icon />
237
- </button>
238
- )}
239
- <Calendar
240
- ref={calendarRef}
241
- initialVisibleDate={initialMonth}
242
- selectionStart={internalDate}
243
- selectionEnd={internalDate}
244
- minDateAllowed={minDate}
245
- maxDateAllowed={maxDate}
246
- disabledDates={disabledDates}
247
- firstDayOfWeek={first_day_of_week}
248
- showOutsideDays={show_outside_days}
249
- monthFormat={month_format}
250
- numberOfMonthsShown={number_of_months_shown}
251
- calendarOrientation={calendar_orientation}
252
- daySize={day_size}
253
- direction={direction}
254
- onSelectionChange={(_, selection) => {
255
- if (!selection) {
256
- return;
257
- }
258
- setInternalDate(selection);
259
- if (!stay_open_on_select) {
260
- setIsCalendarOpen(false);
225
+ <Popover.Content
226
+ className={`dash-datepicker-content${
227
+ hasPortal ? ' dash-datepicker-portal' : ''
228
+ }${
229
+ with_full_screen_portal
230
+ ? ' dash-datepicker-fullscreen'
231
+ : ''
232
+ }`}
233
+ style={portalStyle}
234
+ align={hasPortal ? 'center' : 'start'}
235
+ sideOffset={hasPortal ? 0 : 5}
236
+ avoidCollisions={!hasPortal}
237
+ onInteractOutside={
238
+ with_full_screen_portal
239
+ ? e => e.preventDefault()
240
+ : undefined
241
+ }
242
+ onOpenAutoFocus={e => e.preventDefault()}
243
+ onCloseAutoFocus={e => {
244
+ e.preventDefault();
245
+ // Only focus if focus is not already on the input
246
+ if (
247
+ document.activeElement !== inputRef.current
248
+ ) {
249
+ inputRef.current?.focus();
261
250
  }
262
251
  }}
263
- />
264
- </Popover.Content>
265
- </Popover.Portal>
266
- </Popover.Root>
267
- </div>
252
+ >
253
+ {with_full_screen_portal && (
254
+ <button
255
+ className="dash-datepicker-close-button"
256
+ onClick={() => setIsCalendarOpen(false)}
257
+ aria-label="Close calendar"
258
+ >
259
+ <Cross1Icon />
260
+ </button>
261
+ )}
262
+ <Calendar
263
+ ref={calendarRef}
264
+ initialVisibleDate={initialMonth}
265
+ selectionStart={internalDate}
266
+ selectionEnd={internalDate}
267
+ minDateAllowed={minDate}
268
+ maxDateAllowed={maxDate}
269
+ disabledDates={disabledDates}
270
+ firstDayOfWeek={first_day_of_week}
271
+ showOutsideDays={show_outside_days}
272
+ monthFormat={month_format}
273
+ numberOfMonthsShown={number_of_months_shown}
274
+ calendarOrientation={calendar_orientation}
275
+ daySize={day_size}
276
+ direction={direction}
277
+ onSelectionChange={(_, selection) => {
278
+ if (!selection) {
279
+ return;
280
+ }
281
+ setInternalDate(selection);
282
+ if (!stay_open_on_select) {
283
+ setIsCalendarOpen(false);
284
+ }
285
+ }}
286
+ />
287
+ </Popover.Content>
288
+ </Popover.Portal>
289
+ </Popover.Root>
290
+ </div>
291
+ </ResizeDetector>
268
292
  );
269
293
  };
270
294