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
@@ -14,6 +14,7 @@ import {
14
14
  strAsDate,
15
15
  } from '../utils/calendar/helpers';
16
16
  import {captureCSSForPortal} from '../utils/calendar/cssVariables';
17
+ import ResizeDetector from '../utils/ResizeDetector';
17
18
  import '../components/css/datepickers.css';
18
19
 
19
20
  const DatePickerSingle = ({
@@ -63,6 +64,7 @@ const DatePickerSingle = ({
63
64
 
64
65
  const containerRef = useRef<HTMLDivElement>(null);
65
66
  const inputRef = useRef<HTMLInputElement | null>(null);
67
+ const autosizeRef = useRef<any>(null);
66
68
  const calendarRef = useRef<CalendarHandle>(null);
67
69
  const hasPortal = with_portal || with_full_screen_portal;
68
70
 
@@ -87,6 +89,14 @@ const DatePickerSingle = ({
87
89
  }
88
90
  }, [internalDate]);
89
91
 
92
+ const handleResize = useCallback(() => {
93
+ autosizeRef.current?.updateInputWidth?.();
94
+ }, []);
95
+
96
+ useEffect(() => {
97
+ autosizeRef.current?.updateInputWidth?.();
98
+ }, [inputValue]);
99
+
90
100
  const parseUserInput = useCallback(
91
101
  (focusCalendar = false) => {
92
102
  if (inputValue === '') {
@@ -157,123 +167,128 @@ const DatePickerSingle = ({
157
167
  }
158
168
 
159
169
  return (
160
- <div className="dash-datepicker" ref={containerRef}>
161
- <Popover.Root
162
- open={!disabled && isCalendarOpen}
163
- onOpenChange={disabled ? undefined : setIsCalendarOpen}
164
- >
165
- <Popover.Trigger asChild disabled={disabled}>
166
- <div
167
- id={accessibleId + '-wrapper'}
168
- className={classNames}
169
- style={style}
170
- aria-labelledby={`${accessibleId}`}
171
- aria-haspopup="dialog"
172
- aria-expanded={isCalendarOpen}
173
- aria-disabled={disabled}
174
- onClick={e => {
175
- e.preventDefault();
176
- if (!isCalendarOpen && !disabled) {
177
- setIsCalendarOpen(true);
178
- }
179
- }}
180
- >
181
- <AutosizeInput
182
- inputRef={node => {
183
- 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
+ }
184
190
  }}
185
- type="text"
186
- id={accessibleId}
187
- inputClassName="dash-datepicker-input dash-datepicker-end-date"
188
- value={inputValue}
189
- onChange={e => setInputValue(e.target?.value)}
190
- onKeyDown={handleInputKeyDown}
191
- placeholder={placeholder}
192
- disabled={disabled}
193
- dir={direction}
194
- aria-label={placeholder}
195
- />
196
- {clearable && !disabled && !!date && (
197
- <a
198
- className="dash-datepicker-clear"
199
- onClick={clearSelection}
200
- aria-label="Clear date"
201
- >
202
- <Cross1Icon />
203
- </a>
204
- )}
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
+ )}
205
217
 
206
- <CaretDownIcon className="dash-datepicker-caret-icon" />
207
- </div>
208
- </Popover.Trigger>
218
+ <CaretDownIcon className="dash-datepicker-caret-icon" />
219
+ </div>
220
+ </Popover.Trigger>
209
221
 
210
- <Popover.Portal
211
- container={hasPortal ? undefined : containerRef.current}
212
- >
213
- <Popover.Content
214
- className={`dash-datepicker-content${
215
- hasPortal ? ' dash-datepicker-portal' : ''
216
- }${
217
- with_full_screen_portal
218
- ? ' dash-datepicker-fullscreen'
219
- : ''
220
- }`}
221
- style={portalStyle}
222
- align={hasPortal ? 'center' : 'start'}
223
- sideOffset={hasPortal ? 0 : 5}
224
- avoidCollisions={!hasPortal}
225
- onInteractOutside={
226
- with_full_screen_portal
227
- ? e => e.preventDefault()
228
- : undefined
229
- }
230
- onOpenAutoFocus={e => e.preventDefault()}
231
- onCloseAutoFocus={e => {
232
- e.preventDefault();
233
- // Only focus if focus is not already on the input
234
- if (document.activeElement !== inputRef.current) {
235
- inputRef.current?.focus();
236
- }
237
- }}
222
+ <Popover.Portal
223
+ container={hasPortal ? undefined : containerRef.current}
238
224
  >
239
- {with_full_screen_portal && (
240
- <button
241
- className="dash-datepicker-close-button"
242
- onClick={() => setIsCalendarOpen(false)}
243
- aria-label="Close calendar"
244
- >
245
- <Cross1Icon />
246
- </button>
247
- )}
248
- <Calendar
249
- ref={calendarRef}
250
- initialVisibleDate={initialMonth}
251
- selectionStart={internalDate}
252
- selectionEnd={internalDate}
253
- minDateAllowed={minDate}
254
- maxDateAllowed={maxDate}
255
- disabledDates={disabledDates}
256
- firstDayOfWeek={first_day_of_week}
257
- showOutsideDays={show_outside_days}
258
- monthFormat={month_format}
259
- numberOfMonthsShown={number_of_months_shown}
260
- calendarOrientation={calendar_orientation}
261
- daySize={day_size}
262
- direction={direction}
263
- onSelectionChange={(_, selection) => {
264
- if (!selection) {
265
- return;
266
- }
267
- setInternalDate(selection);
268
- if (!stay_open_on_select) {
269
- 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();
270
250
  }
271
251
  }}
272
- />
273
- </Popover.Content>
274
- </Popover.Portal>
275
- </Popover.Root>
276
- </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>
277
292
  );
278
293
  };
279
294