dash-core-components 4.0.0-rc1 → 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 (55) hide show
  1. package/dash_core_components/async-dropdown.js +1 -1
  2. package/dash_core_components/async-dropdown.js.map +1 -1
  3. package/dash_core_components/async-slider.js +1 -1
  4. package/dash_core_components/async-slider.js.map +1 -1
  5. package/dash_core_components/dash_core_components.js +1 -1
  6. package/dash_core_components/dash_core_components.js.map +1 -1
  7. package/dash_core_components/proptypes.js +102 -3
  8. package/lib/components/Checklist.tsx +67 -0
  9. package/lib/components/Dropdown.tsx +19 -3
  10. package/lib/components/Loading.tsx +185 -0
  11. package/lib/components/RadioItems.tsx +69 -0
  12. package/lib/components/RangeSlider.tsx +5 -1
  13. package/lib/components/Slider.tsx +12 -1
  14. package/lib/components/Tab.react.js.old +79 -0
  15. package/lib/components/Textarea.tsx +79 -0
  16. package/lib/components/Tooltip.tsx +66 -0
  17. package/lib/components/css/checklist.css +4 -0
  18. package/lib/components/css/dcc.css +2 -0
  19. package/lib/components/css/dropdown.css +30 -49
  20. package/lib/components/css/input.css +22 -6
  21. package/lib/components/css/optionslist.css +34 -0
  22. package/lib/components/css/radioitems.css +4 -0
  23. package/lib/components/css/sliders.css +11 -7
  24. package/lib/components/css/textarea.css +21 -0
  25. package/lib/components/css/tooltip.css +127 -0
  26. package/lib/fragments/Dropdown.tsx +205 -269
  27. package/lib/fragments/Loading/spinners/CircleSpinner.tsx +185 -0
  28. package/lib/fragments/Loading/spinners/CubeSpinner.tsx +193 -0
  29. package/lib/fragments/Loading/spinners/DebugTitle.tsx +11 -0
  30. package/lib/fragments/Loading/spinners/DefaultSpinner.tsx +110 -0
  31. package/lib/fragments/Loading/spinners/DotSpinner.tsx +96 -0
  32. package/lib/fragments/Loading/spinners/GraphSpinner.tsx +332 -0
  33. package/lib/fragments/Loading/types.ts +13 -0
  34. package/lib/fragments/RangeSlider.tsx +193 -63
  35. package/lib/index.ts +5 -5
  36. package/lib/types.ts +455 -116
  37. package/lib/utils/dropdownSearch.ts +4 -4
  38. package/lib/utils/optionRendering.tsx +168 -0
  39. package/lib/utils/optionTypes.ts +5 -5
  40. package/lib/utils/sliderRendering.tsx +23 -4
  41. package/package.json +1 -2
  42. package/lib/components/Checklist.react.js +0 -193
  43. package/lib/components/Input.react.js.old +0 -507
  44. package/lib/components/Loading.react.js +0 -254
  45. package/lib/components/RadioItems.react.js +0 -192
  46. package/lib/components/Slider.react.js.old +0 -214
  47. package/lib/components/Textarea.react.js +0 -223
  48. package/lib/components/Tooltip.react.js +0 -120
  49. package/lib/components/css/Dropdown.css +0 -8
  50. package/lib/fragments/Loading/spinners/CircleSpinner.js +0 -68
  51. package/lib/fragments/Loading/spinners/CubeSpinner.js +0 -57
  52. package/lib/fragments/Loading/spinners/DebugTitle.js +0 -15
  53. package/lib/fragments/Loading/spinners/DefaultSpinner.js +0 -54
  54. package/lib/fragments/Loading/spinners/DotSpinner.js +0 -50
  55. package/lib/fragments/Loading/spinners/GraphSpinner.js +0 -68
@@ -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,38 +376,41 @@ 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]}
261
380
  step={step || undefined}
262
381
  disabled={disabled}
263
382
  />
264
383
  )}
265
384
  {showInputs && !vertical && (
266
385
  <input
386
+ ref={inputRef}
267
387
  type="number"
268
- className="dash-input-container dash-range-slider-input dash-range-slider-max-input"
269
- value={value[value.length - 1] ?? ''}
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
+ }
270
395
  onChange={e => {
271
396
  const inputValue = e.target.value;
272
- // Allow empty string (user is clearing the field)
273
- if (inputValue === '') {
274
- // Don't update props while user is typing, just update local state
275
- const newValue = [...value];
276
- newValue[newValue.length - 1] = '' as any;
277
- setValue(newValue);
278
- } else {
279
- const newMax = parseFloat(inputValue);
280
- const constrainedMax = Math.max(
281
- minMaxValues.min_mark,
282
- Math.min(minMaxValues.max_mark, newMax)
283
- );
284
-
285
- if (newMax === constrainedMax) {
286
- const newValue = [...value];
287
- newValue[newValue.length - 1] = newMax;
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') {
288
406
  setProps({
289
407
  value: newValue,
290
408
  drag_value: newValue,
291
409
  });
410
+ } else {
411
+ setProps({
412
+ drag_value: newValue,
413
+ });
292
414
  }
293
415
  }
294
416
  }}
@@ -298,23 +420,24 @@ export default function RangeSlider(props: RangeSliderProps) {
298
420
 
299
421
  // If empty, default to current value or max_mark
300
422
  if (inputValue === '') {
301
- newMax =
302
- value[value.length - 1] ??
303
- minMaxValues.max_mark;
423
+ newMax = isNaN(value[value.length - 1])
424
+ ? minMaxValues.max_mark
425
+ : value[value.length - 1];
304
426
  } else {
305
427
  newMax = parseFloat(inputValue);
306
428
  newMax = isNaN(newMax)
307
429
  ? minMaxValues.max_mark
308
430
  : newMax;
309
431
  }
310
-
311
- const constrainedMax = Math.min(
312
- minMaxValues.max_mark,
313
- Math.max(
314
- value[0] ?? minMaxValues.min_mark,
315
- newMax
316
- )
432
+ // Constrain to not be less than the min value
433
+ newMax = Math.max(
434
+ value[0] ?? minMaxValues.min_mark,
435
+ newMax
317
436
  );
437
+
438
+ // Snap to valid value (respecting step and marks)
439
+ const constrainedMax =
440
+ constrainToValidValue(newMax);
318
441
  const newValue = [...value];
319
442
  newValue[newValue.length - 1] = constrainedMax;
320
443
  setValue(newValue);
@@ -328,7 +451,11 @@ export default function RangeSlider(props: RangeSliderProps) {
328
451
  ? minMaxValues.min_mark
329
452
  : value[0]
330
453
  }
331
- max={minMaxValues.max_mark}
454
+ max={
455
+ isNaN(minMaxValues.max_mark)
456
+ ? max
457
+ : minMaxValues.max_mark
458
+ }
332
459
  step={step || undefined}
333
460
  disabled={disabled}
334
461
  />
@@ -341,7 +468,7 @@ export default function RangeSlider(props: RangeSliderProps) {
341
468
  ref={sliderRef}
342
469
  className={`dash-slider-root ${
343
470
  renderedMarks ? 'has-marks' : ''
344
- } ${className || ''}`.trim()}
471
+ }`.trim()}
345
472
  style={{
346
473
  ...(vertical && {
347
474
  height: `${verticalHeight}px`,
@@ -355,6 +482,7 @@ export default function RangeSlider(props: RangeSliderProps) {
355
482
  step={stepValue}
356
483
  disabled={disabled}
357
484
  orientation={vertical ? 'vertical' : 'horizontal'}
485
+ inverted={reverse}
358
486
  data-included={included !== false}
359
487
  minStepsBetweenThumbs={
360
488
  typeof pushable === 'number'
@@ -372,14 +500,16 @@ export default function RangeSlider(props: RangeSliderProps) {
372
500
  renderedMarks,
373
501
  !!vertical,
374
502
  minMaxValues,
375
- !!dots
503
+ !!dots,
504
+ !!reverse
376
505
  )}
377
506
  {dots &&
378
507
  stepValue &&
379
508
  renderSliderDots(
380
509
  stepValue,
381
510
  minMaxValues,
382
- !!vertical
511
+ !!vertical,
512
+ !!reverse
383
513
  )}
384
514
  {/* Render thumbs with tooltips for each value */}
385
515
  {value.map((val, index) => {
package/lib/index.ts CHANGED
@@ -1,5 +1,5 @@
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';
@@ -12,17 +12,17 @@ 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';