dash-core-components 4.0.0-rc0 → 4.0.0-rc2

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 (67) 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-slider.js +1 -2
  7. package/dash_core_components/async-slider.js.map +1 -1
  8. package/dash_core_components/dash_core_components-shared.js +1 -1
  9. package/dash_core_components/dash_core_components-shared.js.map +1 -1
  10. package/dash_core_components/dash_core_components.js +1 -1
  11. package/dash_core_components/dash_core_components.js.map +1 -1
  12. package/dash_core_components/proptypes.js +118 -1
  13. package/lib/components/Checklist.tsx +67 -0
  14. package/lib/components/Dropdown.tsx +68 -0
  15. package/lib/components/Loading.tsx +185 -0
  16. package/lib/components/RadioItems.tsx +69 -0
  17. package/lib/components/RangeSlider.tsx +12 -1
  18. package/lib/components/Slider.tsx +12 -1
  19. package/lib/components/Tab.react.js.old +79 -0
  20. package/lib/components/Textarea.react.js.old +287 -0
  21. package/lib/components/Textarea.tsx +79 -0
  22. package/lib/components/Tooltip.tsx +66 -0
  23. package/lib/components/css/checklist.css +4 -0
  24. package/lib/components/css/dcc.css +3 -0
  25. package/lib/components/css/dropdown.css +211 -0
  26. package/lib/components/css/input.css +22 -6
  27. package/lib/components/css/optionslist.css +34 -0
  28. package/lib/components/css/radioitems.css +4 -0
  29. package/lib/components/css/sliders.css +19 -7
  30. package/lib/components/css/textarea.css +21 -0
  31. package/lib/components/css/tooltip.css +127 -0
  32. package/lib/fragments/Dropdown.tsx +513 -0
  33. package/lib/fragments/Loading/spinners/CircleSpinner.tsx +185 -0
  34. package/lib/fragments/Loading/spinners/CubeSpinner.tsx +193 -0
  35. package/lib/fragments/Loading/spinners/DebugTitle.tsx +11 -0
  36. package/lib/fragments/Loading/spinners/DefaultSpinner.tsx +110 -0
  37. package/lib/fragments/Loading/spinners/DotSpinner.tsx +96 -0
  38. package/lib/fragments/Loading/spinners/GraphSpinner.tsx +332 -0
  39. package/lib/fragments/Loading/types.ts +13 -0
  40. package/lib/fragments/RangeSlider.tsx +235 -105
  41. package/lib/index.ts +6 -6
  42. package/lib/types.ts +571 -64
  43. package/lib/utils/LazyLoader/dropdown.ts +2 -0
  44. package/lib/utils/_LoadingElement.tsx +8 -18
  45. package/lib/utils/dropdownSearch.ts +92 -0
  46. package/lib/utils/optionRendering.tsx +168 -0
  47. package/lib/utils/optionTypes.ts +27 -0
  48. package/lib/utils/sliderRendering.tsx +23 -4
  49. package/package.json +7 -4
  50. package/lib/components/Checklist.react.js +0 -193
  51. package/lib/components/Dropdown.react.js +0 -182
  52. package/lib/components/Input.react.js.old +0 -507
  53. package/lib/components/Loading.react.js +0 -254
  54. package/lib/components/RadioItems.react.js +0 -192
  55. package/lib/components/Slider.react.js.old +0 -214
  56. package/lib/components/Textarea.react.js +0 -223
  57. package/lib/components/Tooltip.react.js +0 -120
  58. package/lib/components/css/Dropdown.css +0 -8
  59. package/lib/fragments/Dropdown.react.js +0 -158
  60. package/lib/fragments/Loading/spinners/CircleSpinner.js +0 -68
  61. package/lib/fragments/Loading/spinners/CubeSpinner.js +0 -57
  62. package/lib/fragments/Loading/spinners/DebugTitle.js +0 -15
  63. package/lib/fragments/Loading/spinners/DefaultSpinner.js +0 -54
  64. package/lib/fragments/Loading/spinners/DotSpinner.js +0 -50
  65. package/lib/fragments/Loading/spinners/GraphSpinner.js +0 -68
  66. package/lib/fragments/Slider.tsx.old +0 -364
  67. package/lib/utils/LazyLoader/dropdown.js +0 -8
@@ -39,6 +39,7 @@ export default function RangeSlider(props: RangeSliderProps) {
39
39
  allowCross,
40
40
  pushable,
41
41
  count,
42
+ reverse,
42
43
  } = props;
43
44
 
44
45
  // For range slider, we expect an array of values
@@ -49,6 +50,7 @@ export default function RangeSlider(props: RangeSliderProps) {
49
50
  const [showInputs, setShowInputs] = useState<boolean>(value.length === 2);
50
51
 
51
52
  const sliderRef = useRef<HTMLDivElement>(null);
53
+ const inputRef = useRef<HTMLInputElement>(null);
52
54
 
53
55
  // Handle initial mount - equivalent to componentWillMount
54
56
  useEffect(() => {
@@ -166,6 +168,121 @@ export default function RangeSlider(props: RangeSliderProps) {
166
168
  });
167
169
  }, [min, max, processedMarks, step, sliderWidth]);
168
170
 
171
+ // Calculate dynamic input width based on digits needed and container size
172
+ 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
181
+ );
182
+
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)
196
+ );
197
+
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;
211
+
212
+ return `${totalWidth}px`;
213
+ }, [sliderWidth, minMaxValues.min_mark, minMaxValues.max_mark]);
214
+
215
+ const valueIsValid = (val: number): boolean => {
216
+ // Check if value is within min/max bounds
217
+ if (val < minMaxValues.min_mark || val > minMaxValues.max_mark) {
218
+ return false;
219
+ }
220
+
221
+ // If step is defined, check if value aligns with step
222
+ if (stepValue !== undefined) {
223
+ const min = minMaxValues.min_mark;
224
+ const offset = val - min;
225
+ const remainder = Math.abs(offset % stepValue);
226
+ const epsilon = 0.0001; // tolerance for floating point comparison
227
+ if (remainder > epsilon && remainder < stepValue - epsilon) {
228
+ return false;
229
+ }
230
+ }
231
+
232
+ // If step is null and marks exist, value must match a mark
233
+ if (
234
+ step === null &&
235
+ processedMarks &&
236
+ typeof processedMarks === 'object'
237
+ ) {
238
+ const markValues = Object.keys(processedMarks).map(Number);
239
+ const epsilon = 0.0001;
240
+ return markValues.some(mark => Math.abs(val - mark) < epsilon);
241
+ }
242
+
243
+ return true;
244
+ };
245
+
246
+ const constrainToValidValue = (val: number): number => {
247
+ // First constrain to min/max bounds
248
+ let constrained = Math.max(
249
+ minMaxValues.min_mark,
250
+ Math.min(minMaxValues.max_mark, val)
251
+ );
252
+
253
+ // If step is null and marks exist, snap to nearest mark
254
+ if (
255
+ step === null &&
256
+ processedMarks &&
257
+ typeof processedMarks === 'object'
258
+ ) {
259
+ return snapToNearestMark(constrained, processedMarks);
260
+ }
261
+
262
+ // If step is defined, round to nearest step
263
+ if (stepValue !== undefined) {
264
+ const min = minMaxValues.min_mark;
265
+ const steps = Math.round((constrained - min) / stepValue);
266
+ constrained = min + steps * stepValue;
267
+
268
+ // Round to avoid floating point precision issues
269
+ // Determine decimal places from step value
270
+ const stepStr = stepValue.toString();
271
+ const decimalPlaces = stepStr.includes('.')
272
+ ? stepStr.split('.')[1].length
273
+ : 0;
274
+ constrained = Number(constrained.toFixed(decimalPlaces));
275
+
276
+ // Ensure we stay within bounds after rounding
277
+ constrained = Math.max(
278
+ minMaxValues.min_mark,
279
+ Math.min(minMaxValues.max_mark, constrained)
280
+ );
281
+ }
282
+
283
+ return constrained;
284
+ };
285
+
169
286
  const handleValueChange = (newValue: number[]) => {
170
287
  let adjustedValue = newValue;
171
288
 
@@ -193,38 +310,36 @@ export default function RangeSlider(props: RangeSliderProps) {
193
310
  }
194
311
  };
195
312
 
313
+ const classNames = ['dash-slider-container', className].filter(Boolean);
314
+
196
315
  return (
197
316
  <LoadingElement>
198
317
  {loadingProps => (
199
- <div
200
- id={id}
201
- className="dash-slider-container"
202
- {...loadingProps}
203
- >
318
+ <div id={id} className={classNames.join(' ')} {...loadingProps}>
204
319
  {showInputs && value.length === 2 && !vertical && (
205
320
  <input
206
321
  type="number"
207
322
  className="dash-input-container dash-range-slider-input dash-range-slider-min-input"
208
- value={value[0] ?? ''}
323
+ style={{width: inputWidth}}
324
+ value={isNaN(value[0]) ? '' : value[0]}
209
325
  onChange={e => {
210
326
  const inputValue = e.target.value;
211
- // Allow empty string (user is clearing the field)
212
- if (inputValue === '') {
213
- // Don't update props while user is typing, just update local state
214
- setValue([null as any, value[1]]);
215
- } else {
216
- const newMin = parseFloat(inputValue);
217
- if (!isNaN(newMin)) {
218
- const newValue = [newMin, value[1]];
219
- setValue(newValue);
220
- if (updatemode === 'drag') {
221
- setProps({
222
- value: newValue,
223
- drag_value: newValue,
224
- });
225
- } else {
226
- setProps({drag_value: newValue});
227
- }
327
+
328
+ // Parse the input value
329
+ const newMin = parseFloat(inputValue);
330
+ const newValue = [newMin, value[1]];
331
+ setValue(newValue);
332
+ // Only update props if value is valid
333
+ if (valueIsValid(newMin)) {
334
+ if (updatemode === 'drag') {
335
+ setProps({
336
+ value: newValue,
337
+ drag_value: newValue,
338
+ });
339
+ } else {
340
+ setProps({
341
+ drag_value: newValue,
342
+ });
228
343
  }
229
344
  }
230
345
  }}
@@ -234,7 +349,9 @@ export default function RangeSlider(props: RangeSliderProps) {
234
349
 
235
350
  // If empty, default to current value or min_mark
236
351
  if (inputValue === '') {
237
- newMin = value[0] ?? minMaxValues.min_mark;
352
+ newMin = isNaN(value[0])
353
+ ? minMaxValues.min_mark
354
+ : value[0];
238
355
  } else {
239
356
  newMin = parseFloat(inputValue);
240
357
  newMin = isNaN(newMin)
@@ -242,13 +359,15 @@ export default function RangeSlider(props: RangeSliderProps) {
242
359
  : newMin;
243
360
  }
244
361
 
245
- const constrainedMin = Math.max(
246
- minMaxValues.min_mark,
247
- Math.min(
248
- value[1] ?? minMaxValues.max_mark,
249
- newMin
250
- )
362
+ // Constrain to not exceed the max value
363
+ newMin = Math.min(
364
+ value[1] ?? minMaxValues.max_mark,
365
+ newMin
251
366
  );
367
+
368
+ // Snap to valid value (respecting step and marks)
369
+ const constrainedMin =
370
+ constrainToValidValue(newMin);
252
371
  const newValue = [constrainedMin, value[1]];
253
372
  setValue(newValue);
254
373
  if (updatemode === 'mouseup') {
@@ -257,7 +376,86 @@ export default function RangeSlider(props: RangeSliderProps) {
257
376
  }}
258
377
  pattern="^\\d*\\.?\\d*$"
259
378
  min={minMaxValues.min_mark}
260
- max={value[1]}
379
+ max={isNaN(value[1]) ? max : value[1]}
380
+ step={step || undefined}
381
+ disabled={disabled}
382
+ />
383
+ )}
384
+ {showInputs && !vertical && (
385
+ <input
386
+ ref={inputRef}
387
+ type="number"
388
+ className="dash-input-container dash-range-slider-input dash-range-slider-max-input"
389
+ style={{width: inputWidth}}
390
+ value={
391
+ isNaN(value[value.length - 1])
392
+ ? ''
393
+ : value[value.length - 1]
394
+ }
395
+ onChange={e => {
396
+ const inputValue = e.target.value;
397
+
398
+ // Parse the input value
399
+ const newMax = parseFloat(inputValue);
400
+ const newValue = [...value];
401
+ newValue[newValue.length - 1] = newMax;
402
+ setValue(newValue);
403
+ // Only update props if value is valid
404
+ if (valueIsValid(newMax)) {
405
+ if (updatemode === 'drag') {
406
+ setProps({
407
+ value: newValue,
408
+ drag_value: newValue,
409
+ });
410
+ } else {
411
+ setProps({
412
+ drag_value: newValue,
413
+ });
414
+ }
415
+ }
416
+ }}
417
+ onBlur={e => {
418
+ const inputValue = e.target.value;
419
+ let newMax: number;
420
+
421
+ // If empty, default to current value or max_mark
422
+ if (inputValue === '') {
423
+ newMax = isNaN(value[value.length - 1])
424
+ ? minMaxValues.max_mark
425
+ : value[value.length - 1];
426
+ } else {
427
+ newMax = parseFloat(inputValue);
428
+ newMax = isNaN(newMax)
429
+ ? minMaxValues.max_mark
430
+ : newMax;
431
+ }
432
+ // Constrain to not be less than the min value
433
+ newMax = Math.max(
434
+ value[0] ?? minMaxValues.min_mark,
435
+ newMax
436
+ );
437
+
438
+ // Snap to valid value (respecting step and marks)
439
+ const constrainedMax =
440
+ constrainToValidValue(newMax);
441
+ const newValue = [...value];
442
+ newValue[newValue.length - 1] = constrainedMax;
443
+ setValue(newValue);
444
+ if (updatemode === 'mouseup') {
445
+ setProps({value: newValue});
446
+ }
447
+ }}
448
+ pattern="^\\d*\\.?\\d*$"
449
+ min={
450
+ value.length === 1
451
+ ? minMaxValues.min_mark
452
+ : value[0]
453
+ }
454
+ max={
455
+ isNaN(minMaxValues.max_mark)
456
+ ? max
457
+ : minMaxValues.max_mark
458
+ }
261
459
  step={step || undefined}
262
460
  disabled={disabled}
263
461
  />
@@ -270,7 +468,7 @@ export default function RangeSlider(props: RangeSliderProps) {
270
468
  ref={sliderRef}
271
469
  className={`dash-slider-root ${
272
470
  renderedMarks ? 'has-marks' : ''
273
- } ${className || ''}`.trim()}
471
+ }`.trim()}
274
472
  style={{
275
473
  ...(vertical && {
276
474
  height: `${verticalHeight}px`,
@@ -284,6 +482,7 @@ export default function RangeSlider(props: RangeSliderProps) {
284
482
  step={stepValue}
285
483
  disabled={disabled}
286
484
  orientation={vertical ? 'vertical' : 'horizontal'}
485
+ inverted={reverse}
287
486
  data-included={included !== false}
288
487
  minStepsBetweenThumbs={
289
488
  typeof pushable === 'number'
@@ -301,14 +500,16 @@ export default function RangeSlider(props: RangeSliderProps) {
301
500
  renderedMarks,
302
501
  !!vertical,
303
502
  minMaxValues,
304
- !!dots
503
+ !!dots,
504
+ !!reverse
305
505
  )}
306
506
  {dots &&
307
507
  stepValue &&
308
508
  renderSliderDots(
309
509
  stepValue,
310
510
  minMaxValues,
311
- !!vertical
511
+ !!vertical,
512
+ !!reverse
312
513
  )}
313
514
  {/* Render thumbs with tooltips for each value */}
314
515
  {value.map((val, index) => {
@@ -334,77 +535,6 @@ export default function RangeSlider(props: RangeSliderProps) {
334
535
  })}
335
536
  </RadixSlider.Root>
336
537
  </div>
337
- {showInputs && !vertical && (
338
- <input
339
- type="number"
340
- className="dash-input-container dash-range-slider-input"
341
- value={value[value.length - 1] ?? ''}
342
- onChange={e => {
343
- const inputValue = e.target.value;
344
- // Allow empty string (user is clearing the field)
345
- if (inputValue === '') {
346
- // Don't update props while user is typing, just update local state
347
- const newValue = [...value];
348
- newValue[newValue.length - 1] = '' as any;
349
- setValue(newValue);
350
- } else {
351
- const newMax = parseFloat(inputValue);
352
- const constrainedMax = Math.max(
353
- minMaxValues.min_mark,
354
- Math.min(minMaxValues.max_mark, newMax)
355
- );
356
-
357
- if (newMax === constrainedMax) {
358
- const newValue = [...value];
359
- newValue[newValue.length - 1] = newMax;
360
- setProps({
361
- value: newValue,
362
- drag_value: newValue,
363
- });
364
- }
365
- }
366
- }}
367
- onBlur={e => {
368
- const inputValue = e.target.value;
369
- let newMax: number;
370
-
371
- // If empty, default to current value or max_mark
372
- if (inputValue === '') {
373
- newMax =
374
- value[value.length - 1] ??
375
- minMaxValues.max_mark;
376
- } else {
377
- newMax = parseFloat(inputValue);
378
- newMax = isNaN(newMax)
379
- ? minMaxValues.max_mark
380
- : newMax;
381
- }
382
-
383
- const constrainedMax = Math.min(
384
- minMaxValues.max_mark,
385
- Math.max(
386
- value[0] ?? minMaxValues.min_mark,
387
- newMax
388
- )
389
- );
390
- const newValue = [...value];
391
- newValue[newValue.length - 1] = constrainedMax;
392
- setValue(newValue);
393
- if (updatemode === 'mouseup') {
394
- setProps({value: newValue});
395
- }
396
- }}
397
- pattern="^\\d*\\.?\\d*$"
398
- min={
399
- value.length === 1
400
- ? minMaxValues.min_mark
401
- : value[0]
402
- }
403
- max={minMaxValues.max_mark}
404
- step={step || undefined}
405
- disabled={disabled}
406
- />
407
- )}
408
538
  </div>
409
539
  )}
410
540
  </LoadingElement>
package/lib/index.ts CHANGED
@@ -1,28 +1,28 @@
1
1
  /* eslint-disable import/prefer-default-export */
2
- import Checklist from './components/Checklist.react';
2
+ import Checklist from './components/Checklist';
3
3
  import Clipboard from './components/Clipboard.react';
4
4
  import ConfirmDialog from './components/ConfirmDialog.react';
5
5
  import ConfirmDialogProvider from './components/ConfirmDialogProvider.react';
6
6
  import DatePickerRange from './components/DatePickerRange.react';
7
7
  import DatePickerSingle from './components/DatePickerSingle.react';
8
8
  import Download from './components/Download.react';
9
- import Dropdown from './components/Dropdown.react';
9
+ import Dropdown from './components/Dropdown';
10
10
  import Geolocation from './components/Geolocation.react';
11
11
  import Graph from './components/Graph.react';
12
12
  import Input from './components/Input';
13
13
  import Interval from './components/Interval.react';
14
14
  import Link from './components/Link.react';
15
- import Loading from './components/Loading.react';
15
+ import Loading from './components/Loading';
16
16
  import Location from './components/Location.react';
17
17
  import Markdown from './components/Markdown.react';
18
- import RadioItems from './components/RadioItems.react';
18
+ import RadioItems from './components/RadioItems';
19
19
  import RangeSlider from './components/RangeSlider';
20
20
  import Slider from './components/Slider';
21
21
  import Store from './components/Store.react';
22
22
  import Tab from './components/Tab.react';
23
23
  import Tabs from './components/Tabs.react';
24
- import Textarea from './components/Textarea.react';
25
- import Tooltip from './components/Tooltip.react';
24
+ import Textarea from './components/Textarea';
25
+ import Tooltip from './components/Tooltip';
26
26
  import Upload from './components/Upload.react';
27
27
 
28
28
  import './components/css/dcc.css';