dash-core-components 4.0.0-rc2 → 4.0.0-rc4

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 (71) 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 -2
  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 -1
  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 +153 -14
  21. package/lib/components/Button.tsx +48 -0
  22. package/lib/components/Clipboard.react.js +1 -1
  23. package/lib/components/DatePickerRange.tsx +70 -0
  24. package/lib/components/DatePickerSingle.tsx +72 -0
  25. package/lib/components/Input.tsx +12 -233
  26. package/lib/components/RadioItems.tsx +3 -1
  27. package/lib/components/Tab.tsx +19 -0
  28. package/lib/components/Tabs.tsx +311 -0
  29. package/lib/components/css/button.css +55 -0
  30. package/lib/components/css/calendar.css +66 -0
  31. package/lib/components/css/datepickers.css +239 -0
  32. package/lib/components/css/dcc.css +1 -0
  33. package/lib/components/css/dropdown.css +19 -6
  34. package/lib/components/css/input.css +9 -3
  35. package/lib/components/css/sliders.css +41 -1
  36. package/lib/components/css/tabs.css +113 -0
  37. package/lib/fragments/DatePickerRange.tsx +448 -0
  38. package/lib/fragments/DatePickerSingle.tsx +248 -0
  39. package/lib/fragments/Dropdown.tsx +44 -19
  40. package/lib/fragments/Graph.react.js +18 -45
  41. package/lib/fragments/RangeSlider.tsx +24 -66
  42. package/lib/index.ts +6 -6
  43. package/lib/types.ts +660 -28
  44. package/lib/utils/DatePickerPersistence.ts +14 -0
  45. package/lib/utils/LazyLoader/datePickerRange.ts +4 -0
  46. package/lib/utils/LazyLoader/datePickerSingle.ts +4 -0
  47. package/lib/utils/calendar/Calendar.tsx +382 -0
  48. package/lib/utils/calendar/CalendarDay.tsx +75 -0
  49. package/lib/utils/calendar/CalendarDayPadding.tsx +15 -0
  50. package/lib/utils/calendar/CalendarMonth.tsx +247 -0
  51. package/lib/utils/calendar/CalendarMonthHeader.tsx +23 -0
  52. package/lib/utils/calendar/createMonthGrid.ts +28 -0
  53. package/lib/utils/calendar/helpers.ts +272 -0
  54. package/lib/utils/computeSliderMarkers.ts +71 -116
  55. package/lib/utils/optionRendering.tsx +22 -15
  56. package/lib/utils/sliderRendering.tsx +40 -2
  57. package/package.json +16 -13
  58. package/lib/components/DatePickerRange.react.js +0 -244
  59. package/lib/components/DatePickerSingle.react.js +0 -209
  60. package/lib/components/Dropdown.react.js.old +0 -228
  61. package/lib/components/Tab.react.js +0 -80
  62. package/lib/components/Tab.react.js.old +0 -79
  63. package/lib/components/Tabs.react.js +0 -295
  64. package/lib/components/Textarea.react.js.old +0 -287
  65. package/lib/fragments/DatePickerRange.react.js +0 -188
  66. package/lib/fragments/DatePickerSingle.react.js +0 -132
  67. package/lib/utils/DatePickerPersistence.js +0 -18
  68. package/lib/utils/LazyLoader/datePickerRange.js +0 -8
  69. package/lib/utils/LazyLoader/datePickerSingle.js +0 -8
  70. package/lib/utils/convertToMoment.js +0 -30
  71. package/lib/utils/optionTypes.js +0 -39
@@ -47,6 +47,7 @@ const Dropdown = (props: DropdownProps) => {
47
47
  const dropdownContentRef = useRef<HTMLDivElement>(
48
48
  document.createElement('div')
49
49
  );
50
+ const searchInputRef = useRef<HTMLInputElement>(null);
50
51
 
51
52
  const ctx = window.dash_component_api.useDashContext();
52
53
  const loading = ctx.useLoading();
@@ -156,10 +157,12 @@ const Dropdown = (props: DropdownProps) => {
156
157
  option => option.value === val
157
158
  );
158
159
  return (
159
- <React.Fragment key={`${option?.value}-${i}`}>
160
+ <span
161
+ key={`${option?.value}-${i}`}
162
+ className="dash-dropdown-value-item"
163
+ >
160
164
  {option && <OptionLabel {...option} index={i} />}
161
- {i === sanitizedValues.length - 1 ? '' : ', '}
162
- </React.Fragment>
165
+ </span>
163
166
  );
164
167
  });
165
168
  return labels;
@@ -232,25 +235,36 @@ const Dropdown = (props: DropdownProps) => {
232
235
  }
233
236
  }, [filteredOptions, isOpen]);
234
237
 
235
- // Focus (and scroll) the first selected item when dropdown opens
238
+ // Focus first selected item or search input when dropdown opens
236
239
  useEffect(() => {
237
- if (!isOpen || multi || search_value) {
240
+ if (!isOpen || search_value) {
238
241
  return;
239
242
  }
240
243
 
241
244
  // waiting for the DOM to be ready after the dropdown renders
242
245
  requestAnimationFrame(() => {
243
- const selectedValue = sanitizedValues[0];
244
-
245
- const selectedElement = dropdownContentRef.current.querySelector(
246
- `.dash-options-list-option-checkbox[value="${selectedValue}"]`
247
- );
246
+ // Try to focus the first selected item (for single-select)
247
+ if (!multi) {
248
+ const selectedValue = sanitizedValues[0];
249
+ if (selectedValue) {
250
+ const selectedElement =
251
+ dropdownContentRef.current.querySelector(
252
+ `.dash-options-list-option-checkbox[value="${selectedValue}"]`
253
+ );
254
+
255
+ if (selectedElement instanceof HTMLElement) {
256
+ selectedElement.focus();
257
+ return;
258
+ }
259
+ }
260
+ }
248
261
 
249
- if (selectedElement instanceof HTMLElement) {
250
- selectedElement?.focus();
262
+ // Fallback: focus search input if available and no selected item was focused
263
+ if (searchable && searchInputRef.current) {
264
+ searchInputRef.current.focus();
251
265
  }
252
266
  });
253
- }, [isOpen, multi, displayOptions, sanitizedValues]);
267
+ }, [isOpen, multi, displayOptions]);
254
268
 
255
269
  // Handle keyboard navigation in popover
256
270
  const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
@@ -275,7 +289,7 @@ const Dropdown = (props: DropdownProps) => {
275
289
  }
276
290
 
277
291
  const focusableElements = e.currentTarget.querySelectorAll(
278
- 'input[type="search"], input[type="checkbox"]:not([disabled])'
292
+ 'input[type="search"], input:not([disabled])'
279
293
  ) as NodeListOf<HTMLElement>;
280
294
 
281
295
  // Don't interfere with the event if there aren't any options that the user can interact with
@@ -333,7 +347,7 @@ const Dropdown = (props: DropdownProps) => {
333
347
  } else {
334
348
  focusableElements[nextIndex].scrollIntoView({
335
349
  behavior: 'auto',
336
- block: 'center',
350
+ block: 'nearest',
337
351
  });
338
352
  }
339
353
  }
@@ -352,8 +366,9 @@ const Dropdown = (props: DropdownProps) => {
352
366
  );
353
367
 
354
368
  const accessibleId = id ?? uuid();
369
+ const positioningContainerRef = useRef<HTMLDivElement>(null);
355
370
 
356
- return (
371
+ const popover = (
357
372
  <Popover.Root open={isOpen} onOpenChange={handleOpenChange}>
358
373
  <Popover.Trigger asChild>
359
374
  <button
@@ -363,6 +378,7 @@ const Dropdown = (props: DropdownProps) => {
363
378
  type="button"
364
379
  onKeyDown={e => {
365
380
  if (e.key === 'ArrowDown') {
381
+ e.preventDefault();
366
382
  setIsOpen(true);
367
383
  }
368
384
  }}
@@ -424,7 +440,7 @@ const Dropdown = (props: DropdownProps) => {
424
440
  // container is required otherwise popover will be rendered
425
441
  // at document root, which may be outside of the Dash app (i.e.
426
442
  // an embedded app)
427
- container={dropdownContainerRef.current?.parentElement}
443
+ container={positioningContainerRef.current}
428
444
  >
429
445
  <Popover.Content
430
446
  ref={dropdownContentRef}
@@ -434,7 +450,9 @@ const Dropdown = (props: DropdownProps) => {
434
450
  onOpenAutoFocus={e => e.preventDefault()}
435
451
  onKeyDown={handleKeyDown}
436
452
  style={{
437
- maxHeight: maxHeight ? `${maxHeight}px` : 'auto',
453
+ maxHeight: maxHeight
454
+ ? `min(${maxHeight}px, calc(100vh - 100px))`
455
+ : 'calc(100vh - 100px)',
438
456
  }}
439
457
  >
440
458
  {searchable && (
@@ -447,7 +465,7 @@ const Dropdown = (props: DropdownProps) => {
447
465
  value={search_value || ''}
448
466
  autoComplete="off"
449
467
  onChange={e => onInputChange(e.target.value)}
450
- autoFocus
468
+ ref={searchInputRef}
451
469
  />
452
470
  {search_value && (
453
471
  <button
@@ -487,6 +505,7 @@ const Dropdown = (props: DropdownProps) => {
487
505
  options={displayOptions}
488
506
  selected={sanitizedValues}
489
507
  onSelectionChange={updateSelection}
508
+ inputType={multi ? 'checkbox' : 'radio'}
490
509
  className="dash-dropdown-options"
491
510
  optionClassName="dash-dropdown-option"
492
511
  optionStyle={{
@@ -508,6 +527,12 @@ const Dropdown = (props: DropdownProps) => {
508
527
  </Popover.Portal>
509
528
  </Popover.Root>
510
529
  );
530
+
531
+ return (
532
+ <div ref={positioningContainerRef} className="dash-dropdown-wrapper">
533
+ {popover}
534
+ </div>
535
+ );
511
536
  };
512
537
 
513
538
  export default Dropdown;
@@ -335,6 +335,8 @@ class PlotlyGraph extends _react.Component {
335
335
  return;
336
336
  }
337
337
  gd.classList.add('dash-graph--pending');
338
+
339
+ // Calling resize enables layout.autosize in plotly.js
338
340
  Plotly.Plots.resize(gd).catch(() => {}).finally(() => gd.classList.remove('dash-graph--pending'));
339
341
  }
340
342
  bindEvents() {
@@ -405,26 +407,6 @@ class PlotlyGraph extends _react.Component {
405
407
  }
406
408
  });
407
409
  }
408
- getStyle() {
409
- var responsive = this.props.responsive;
410
- var style = this.props.style;
411
-
412
- // When there is no forced responsive style, return the original style property
413
- if (!responsive) {
414
- return style;
415
- }
416
-
417
- // Otherwise, if the height is not set, we make the graph size equal to the parent one
418
- if (!style) {
419
- style = {};
420
- }
421
- if (!style.height) {
422
- return Object.assign({
423
- height: '100%'
424
- }, style);
425
- }
426
- return style;
427
- }
428
410
  componentDidMount() {
429
411
  var p = this.plot(this.props);
430
412
  this._queue = this.amendTraces(p, {}, this.props);
@@ -465,34 +447,25 @@ class PlotlyGraph extends _react.Component {
465
447
  var _this$props2 = this.props,
466
448
  className = _this$props2.className,
467
449
  id = _this$props2.id,
468
- loading_state = _this$props2.loading_state;
469
- var style = this.getStyle();
470
- if (window.dash_component_api) {
471
- return /*#__PURE__*/_react.default.createElement(_LoadingElement.default, {
472
- id: id,
473
- key: id,
474
- className: className,
475
- style: style,
476
- ref: this.parentElement
477
- }, /*#__PURE__*/_react.default.createElement(_ResizeDetector.default, {
478
- onResize: this.graphResize,
479
- targets: [this.parentElement, this.gd]
480
- }), /*#__PURE__*/_react.default.createElement("div", {
481
- ref: this.gd,
482
- style: {
483
- height: '100%',
484
- width: '100%'
485
- }
486
- }));
450
+ loading_state = _this$props2.loading_state,
451
+ _this$props2$style = _this$props2.style,
452
+ style = _this$props2$style === void 0 ? {} : _this$props2$style;
453
+ if (this.isResponsive(this.props)) {
454
+ style.height || (style.height = '100%');
487
455
  }
488
- return /*#__PURE__*/_react.default.createElement("div", {
489
- id: id,
456
+ var Container = _LoadingElement.default;
457
+ var containerProps = {
458
+ className,
459
+ id,
490
460
  key: id,
491
- className: className,
492
- style: style,
493
461
  ref: this.parentElement,
494
- "data-dash-is-loading": loading_state && loading_state.is_loading || undefined
495
- }, /*#__PURE__*/_react.default.createElement(_ResizeDetector.default, {
462
+ style
463
+ };
464
+ if (!window.dash_component_api) {
465
+ Container = 'div';
466
+ containerProps['data-dash-is-loading'] = (loading_state === null || loading_state === void 0 ? void 0 : loading_state.is_loading) || undefined;
467
+ }
468
+ return /*#__PURE__*/_react.default.createElement(Container, containerProps, /*#__PURE__*/_react.default.createElement(_ResizeDetector.default, {
496
469
  onResize: this.graphResize,
497
470
  targets: [this.parentElement, this.gd]
498
471
  }), /*#__PURE__*/_react.default.createElement("div", {
@@ -45,9 +45,8 @@ export default function RangeSlider(props: RangeSliderProps) {
45
45
  // For range slider, we expect an array of values
46
46
  const [value, setValue] = useState<number[]>(propValue || []);
47
47
 
48
- // Track slider dimension (width for horizontal, height for vertical) for conditional input rendering
48
+ // Track slider dimension (width for horizontal, height for vertical) for marks rendering
49
49
  const [sliderWidth, setSliderWidth] = useState<number | null>(null);
50
- const [showInputs, setShowInputs] = useState<boolean>(value.length === 2);
51
50
 
52
51
  const sliderRef = useRef<HTMLDivElement>(null);
53
52
  const inputRef = useRef<HTMLInputElement>(null);
@@ -64,25 +63,12 @@ export default function RangeSlider(props: RangeSliderProps) {
64
63
  }
65
64
  }, []);
66
65
 
67
- // Dynamic dimension detection using ResizeObserver (width for horizontal, height for vertical)
66
+ // Dynamic dimension detection using ResizeObserver for marks rendering
68
67
  useEffect(() => {
69
68
  if (!sliderRef.current) {
70
69
  return;
71
70
  }
72
71
 
73
- if (step === null) {
74
- // If the user has explicitly disabled stepping (step=None), then
75
- // the slider values are constrained to the given marks and user
76
- // cannot enter arbitrary values via the input element
77
- setShowInputs(false);
78
- return;
79
- }
80
-
81
- if (!value || value.length > 2) {
82
- setShowInputs(false);
83
- return;
84
- }
85
-
86
72
  const measureWidth = () => {
87
73
  if (sliderRef.current) {
88
74
  const rect = sliderRef.current.getBoundingClientRect();
@@ -90,16 +76,6 @@ export default function RangeSlider(props: RangeSliderProps) {
90
76
  const dimension = vertical ? rect.height : rect.width;
91
77
  if (dimension > 0) {
92
78
  setSliderWidth(dimension);
93
-
94
- // eslint-disable-next-line no-magic-numbers
95
- const HIDE_AT_WIDTH = value.length === 1 ? 200 : 250;
96
- // eslint-disable-next-line no-magic-numbers
97
- const SHOW_AT_WIDTH = value.length === 1 ? 300 : 450;
98
- if (showInputs && dimension < HIDE_AT_WIDTH) {
99
- setShowInputs(false);
100
- } else if (!showInputs && dimension >= SHOW_AT_WIDTH) {
101
- setShowInputs(true);
102
- }
103
79
  }
104
80
  }
105
81
  };
@@ -119,7 +95,7 @@ export default function RangeSlider(props: RangeSliderProps) {
119
95
  return () => {
120
96
  resizeObserver.disconnect();
121
97
  };
122
- }, [showInputs, vertical, step, value]);
98
+ }, [vertical]);
123
99
 
124
100
  // Handle prop value changes - equivalent to componentWillReceiveProps
125
101
  useEffect(() => {
@@ -168,49 +144,23 @@ export default function RangeSlider(props: RangeSliderProps) {
168
144
  });
169
145
  }, [min, max, processedMarks, step, sliderWidth]);
170
146
 
171
- // Calculate dynamic input width based on digits needed and container size
147
+ // Calculate dynamic input width based on min/max values
172
148
  const inputWidth = useMemo(() => {
173
- if (!sliderWidth) {
174
- return '64px'; // fallback to current width
175
- }
176
-
177
- // Count digits needed for min and max values
178
- const maxDigits = Math.max(
179
- String(Math.floor(Math.abs(minMaxValues.max_mark))).length,
180
- String(Math.floor(Math.abs(minMaxValues.min_mark))).length
149
+ const maxIntegerChars = Math.max(
150
+ String(Math.floor(minMaxValues.max_mark)).length,
151
+ String(Math.floor(minMaxValues.min_mark)).length
181
152
  );
182
153
 
183
- // Add 1 for minus sign if min is negative
184
- const totalChars = maxDigits + (minMaxValues.min_mark < 0 ? 1 : 0);
185
-
186
- // Calculate width as percentage of container (5% min, 15% max)
187
- /* eslint-disable no-magic-numbers */
188
- const minWidth = sliderWidth * 0.05;
189
- const maxWidth = sliderWidth * 0.15;
190
- const charBasedWidth = totalChars * 12; // approx 12px per character
191
- /* eslint-enable no-magic-numbers */
192
-
193
- const calculatedWidth = Math.max(
194
- minWidth,
195
- Math.min(maxWidth, charBasedWidth)
154
+ const maxDecimalChars = Math.min(
155
+ (String(stepValue).split('.')[1]?.length ?? -1) + 1,
156
+ 3
196
157
  );
197
158
 
198
- // Add padding if box-sizing is border-box
199
- let inputPadding = 0;
200
- if (inputRef.current) {
201
- const computedStyle = window.getComputedStyle(inputRef.current);
202
- if (computedStyle.boxSizing === 'border-box') {
203
- const paddingLeft = parseFloat(computedStyle.paddingLeft) || 0;
204
- const paddingRight =
205
- parseFloat(computedStyle.paddingRight) || 0;
206
- inputPadding = paddingLeft + paddingRight;
207
- }
208
- }
209
-
210
- const totalWidth = calculatedWidth + inputPadding;
159
+ const totalChars = maxIntegerChars + maxDecimalChars;
160
+ const charWidth = 12;
211
161
 
212
- return `${totalWidth}px`;
213
- }, [sliderWidth, minMaxValues.min_mark, minMaxValues.max_mark]);
162
+ return `${totalChars * charWidth}px`;
163
+ }, [minMaxValues.min_mark, minMaxValues.max_mark, stepValue]);
214
164
 
215
165
  const valueIsValid = (val: number): boolean => {
216
166
  // Check if value is within min/max bounds
@@ -312,11 +262,17 @@ export default function RangeSlider(props: RangeSliderProps) {
312
262
 
313
263
  const classNames = ['dash-slider-container', className].filter(Boolean);
314
264
 
265
+ // Determine if inputs should be rendered at all (CSS will handle responsive visibility)
266
+ const shouldShowInputs =
267
+ step !== null && // Not disabled by step=None
268
+ value.length <= 2 && // Only for single or range sliders
269
+ !vertical; // Only for horizontal sliders
270
+
315
271
  return (
316
272
  <LoadingElement>
317
273
  {loadingProps => (
318
274
  <div id={id} className={classNames.join(' ')} {...loadingProps}>
319
- {showInputs && value.length === 2 && !vertical && (
275
+ {shouldShowInputs && value.length === 2 && (
320
276
  <input
321
277
  type="number"
322
278
  className="dash-input-container dash-range-slider-input dash-range-slider-min-input"
@@ -381,7 +337,7 @@ export default function RangeSlider(props: RangeSliderProps) {
381
337
  disabled={disabled}
382
338
  />
383
339
  )}
384
- {showInputs && !vertical && (
340
+ {shouldShowInputs && (
385
341
  <input
386
342
  ref={inputRef}
387
343
  type="number"
@@ -500,6 +456,7 @@ export default function RangeSlider(props: RangeSliderProps) {
500
456
  renderedMarks,
501
457
  !!vertical,
502
458
  minMaxValues,
459
+ value,
503
460
  !!dots,
504
461
  !!reverse
505
462
  )}
@@ -508,6 +465,7 @@ export default function RangeSlider(props: RangeSliderProps) {
508
465
  renderSliderDots(
509
466
  stepValue,
510
467
  minMaxValues,
468
+ value,
511
469
  !!vertical,
512
470
  !!reverse
513
471
  )}
package/lib/index.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  /* eslint-disable import/prefer-default-export */
2
+ import Button from './components/Button';
2
3
  import Checklist from './components/Checklist';
3
4
  import Clipboard from './components/Clipboard.react';
4
5
  import ConfirmDialog from './components/ConfirmDialog.react';
5
6
  import ConfirmDialogProvider from './components/ConfirmDialogProvider.react';
6
- import DatePickerRange from './components/DatePickerRange.react';
7
- import DatePickerSingle from './components/DatePickerSingle.react';
7
+ import DatePickerRange from './components/DatePickerRange';
8
+ import DatePickerSingle from './components/DatePickerSingle';
8
9
  import Download from './components/Download.react';
9
10
  import Dropdown from './components/Dropdown';
10
11
  import Geolocation from './components/Geolocation.react';
@@ -19,17 +20,16 @@ import RadioItems from './components/RadioItems';
19
20
  import RangeSlider from './components/RangeSlider';
20
21
  import Slider from './components/Slider';
21
22
  import Store from './components/Store.react';
22
- import Tab from './components/Tab.react';
23
- import Tabs from './components/Tabs.react';
23
+ import Tab from './components/Tab';
24
+ import Tabs from './components/Tabs';
24
25
  import Textarea from './components/Textarea';
25
26
  import Tooltip from './components/Tooltip';
26
27
  import Upload from './components/Upload.react';
27
28
 
28
29
  import './components/css/dcc.css';
29
- import 'react-dates/lib/css/_datepicker.css';
30
- import './components/css/react-dates@20.1.0-fix.css';
31
30
 
32
31
  export {
32
+ Button,
33
33
  Checklist,
34
34
  Clipboard,
35
35
  ConfirmDialog,