dash-core-components 3.2.0 → 4.0.0-rc0

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 (50) 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-highlight.js +1 -1
  6. package/dash_core_components/async-highlight.js.map +1 -1
  7. package/dash_core_components/async-markdown.js +1 -1
  8. package/dash_core_components/async-markdown.js.map +1 -1
  9. package/dash_core_components/async-slider.js +1 -1
  10. package/dash_core_components/async-slider.js.map +1 -1
  11. package/dash_core_components/dash_core_components-shared.js +1 -1
  12. package/dash_core_components/dash_core_components-shared.js.map +1 -1
  13. package/dash_core_components/dash_core_components.js +1 -1
  14. package/dash_core_components/dash_core_components.js.map +1 -1
  15. package/dash_core_components/plotly.min.js +8 -0
  16. package/dash_core_components/proptypes.js +81 -0
  17. package/lib/components/Dropdown.react.js.old +228 -0
  18. package/lib/components/Input.react.js.old +507 -0
  19. package/lib/components/Input.tsx +543 -0
  20. package/lib/components/RangeSlider.tsx +39 -0
  21. package/lib/components/Slider.react.js.old +214 -0
  22. package/lib/components/Slider.tsx +81 -0
  23. package/lib/components/css/dcc.css +13 -0
  24. package/lib/components/css/input.css +116 -2
  25. package/lib/components/css/react-select@1.0.0-rc.3.min.css +1 -1
  26. package/lib/components/css/sliders.css +198 -4
  27. package/lib/fragments/RangeSlider.tsx +412 -0
  28. package/lib/fragments/Slider.tsx.old +364 -0
  29. package/lib/index.ts +58 -0
  30. package/lib/types.ts +331 -0
  31. package/lib/utils/LazyLoader/rangeSlider.ts +2 -0
  32. package/lib/utils/LazyLoader/slider.ts +2 -0
  33. package/lib/utils/_LoadingElement.tsx +36 -0
  34. package/lib/utils/computeSliderMarkers.ts +302 -0
  35. package/lib/utils/formatSliderTooltip.ts +20 -0
  36. package/lib/utils/sliderRendering.tsx +144 -0
  37. package/lib/utils/sliderSnapToMark.ts +17 -0
  38. package/lib/utils/sliderTooltip.tsx +65 -0
  39. package/package.json +22 -4
  40. package/lib/components/Input.react.js +0 -403
  41. package/lib/components/RangeSlider.react.js +0 -194
  42. package/lib/components/Slider.react.js +0 -179
  43. package/lib/fragments/RangeSlider.react.js +0 -143
  44. package/lib/fragments/Slider.react.js +0 -159
  45. package/lib/index.js +0 -183
  46. package/lib/utils/LazyLoader/rangeSlider.js +0 -8
  47. package/lib/utils/LazyLoader/slider.js +0 -8
  48. package/lib/utils/computeSliderMarkers.js +0 -153
  49. package/lib/utils/computeSliderStyle.js +0 -26
  50. package/lib/utils/formatSliderTooltip.js +0 -19
@@ -0,0 +1,364 @@
1
+ import React, {useEffect, useState, useMemo, useRef} from 'react';
2
+ import * as RadixSlider from '@radix-ui/react-slider';
3
+ import * as Tooltip from '@radix-ui/react-tooltip';
4
+ import {isNil} from 'ramda';
5
+
6
+ import {
7
+ sanitizeMarks,
8
+ calcStep,
9
+ setUndefined,
10
+ } from '../utils/computeSliderMarkers';
11
+ import {
12
+ formatSliderTooltip,
13
+ transformSliderTooltip,
14
+ } from '../utils/formatSliderTooltip';
15
+ import {snapToNearestMark} from '../utils/sliderSnapToMark';
16
+ import {renderSliderMarks, renderSliderDots} from '../utils/sliderRendering';
17
+ import LoadingElement from '../utils/_LoadingElement';
18
+ import {SliderProps} from '../types';
19
+
20
+ const MAX_MARKS = 500;
21
+
22
+ /**
23
+ * A slider component with a single handle.
24
+ */
25
+ export default function Slider(props: SliderProps) {
26
+ const {
27
+ className,
28
+ id,
29
+ setProps,
30
+ tooltip,
31
+ updatemode,
32
+ min,
33
+ max,
34
+ marks,
35
+ step,
36
+ vertical,
37
+ verticalHeight,
38
+ value: propValue,
39
+ disabled,
40
+ dots,
41
+ included,
42
+ } = props;
43
+
44
+ // Radix UI expects arrays, so we normalize the value
45
+ const [value, setValue] = useState<number | null>(propValue || null);
46
+
47
+ // Track slider dimension (width for horizontal, height for vertical) for dynamic mark density
48
+ const [sliderWidth, setSliderWidth] = useState<number | null>(null);
49
+ const [showInput, setShowInput] = useState<boolean>(true);
50
+ const sliderRef = useRef<HTMLDivElement>(null);
51
+
52
+ // Convert single value to array format for Radix UI
53
+ const radixValue = useMemo(() => {
54
+ return value !== null ? [value] : [NaN];
55
+ }, [value]);
56
+
57
+ useEffect(() => {
58
+ if (propValue !== null && propValue !== undefined) {
59
+ setProps({drag_value: propValue});
60
+ setValue(propValue);
61
+ }
62
+ }, []);
63
+
64
+ // Dynamic dimension detection using ResizeObserver (width for horizontal, height for vertical)
65
+ useEffect(() => {
66
+ if (!sliderRef.current) {
67
+ return;
68
+ }
69
+
70
+ if (step === null) {
71
+ // If the user has explicitly disabled stepping (step=None), then
72
+ // the slider values are constrained to the given marks and user
73
+ // cannot enter arbitrary values via the input element
74
+ setShowInput(false);
75
+ return;
76
+ }
77
+
78
+ const measureWidth = () => {
79
+ if (sliderRef.current) {
80
+ const rect = sliderRef.current.getBoundingClientRect();
81
+ // Use height for vertical sliders, width for horizontal sliders
82
+ const dimension = vertical ? rect.height : rect.width;
83
+ if (dimension > 0) {
84
+ setSliderWidth(dimension);
85
+
86
+ const HIDE_AT_WIDTH = 200;
87
+ const SHOW_AT_WIDTH = 300;
88
+ if (showInput && dimension < HIDE_AT_WIDTH) {
89
+ setShowInput(false);
90
+ } else if (!showInput && dimension >= SHOW_AT_WIDTH) {
91
+ setShowInput(true);
92
+ }
93
+ }
94
+ }
95
+ };
96
+
97
+ // Initial measurement
98
+ measureWidth();
99
+
100
+ // Set up ResizeObserver for dynamic resizing
101
+ const resizeObserver = new ResizeObserver(() => {
102
+ measureWidth();
103
+ });
104
+
105
+ resizeObserver.observe(sliderRef.current);
106
+
107
+ // Cleanup function when component unmounts
108
+ // eslint-disable-next-line consistent-return
109
+ return () => {
110
+ resizeObserver.disconnect();
111
+ };
112
+ }, [showInput, vertical, step]);
113
+
114
+ useEffect(() => {
115
+ if (propValue !== value) {
116
+ setProps({drag_value: propValue || undefined});
117
+ setValue(propValue || null);
118
+ }
119
+ }, [propValue]);
120
+
121
+ // Check if marks exceed 500 limit for performance
122
+ let processedMarks = marks;
123
+ if (marks && typeof marks === 'object' && marks !== null) {
124
+ const marksCount = Object.keys(marks).length;
125
+ if (marksCount > MAX_MARKS) {
126
+ /* eslint-disable no-console */
127
+ console.error(
128
+ `dcc.Slider: Too many marks (${marksCount}) provided. ` +
129
+ `For performance reasons, marks are limited to 500. ` +
130
+ `Using auto-generated marks instead.`
131
+ );
132
+ processedMarks = undefined;
133
+ }
134
+ }
135
+
136
+ // Tooltip configuration for Radix UI
137
+ const tooltipContent = useMemo(() => {
138
+ if (!tooltip || value === null) {
139
+ return null;
140
+ }
141
+
142
+ let displayValue: number | string = value;
143
+ if (tooltip.transform) {
144
+ displayValue = transformSliderTooltip(tooltip.transform, value);
145
+ }
146
+
147
+ const content = formatSliderTooltip(
148
+ tooltip.template || '{value}',
149
+ displayValue
150
+ );
151
+
152
+ return (
153
+ <div id={`${id}-tooltip-content`} style={tooltip.style}>
154
+ {content}
155
+ </div>
156
+ );
157
+ }, [tooltip, value]);
158
+
159
+ const minMaxValues = useMemo(() => {
160
+ return setUndefined(min, max, value, processedMarks);
161
+ }, [min, max, value, processedMarks]);
162
+
163
+ const stepValue: number | undefined = useMemo(() => {
164
+ return step === null && isNil(processedMarks)
165
+ ? undefined
166
+ : calcStep(min, max, step);
167
+ }, [step, processedMarks, min, max]);
168
+
169
+ // Generate marks for rendering (if needed)
170
+ const renderedMarks = useMemo(() => {
171
+ if (processedMarks === null) {
172
+ return null;
173
+ }
174
+ return sanitizeMarks({
175
+ min,
176
+ max,
177
+ marks: processedMarks,
178
+ step,
179
+ sliderWidth,
180
+ });
181
+ }, [min, max, processedMarks, step, sliderWidth]);
182
+
183
+ return (
184
+ <LoadingElement>
185
+ {loadingProps => (
186
+ <div
187
+ id={id}
188
+ className="dash-slider-container"
189
+ {...loadingProps}
190
+ >
191
+ <div className="dash-slider-wrapper">
192
+ <Tooltip.Provider>
193
+ <RadixSlider.Root
194
+ ref={sliderRef}
195
+ className={`dash-slider-root ${
196
+ renderedMarks ? 'has-marks' : ''
197
+ } ${className || ''}`.trim()}
198
+ style={{
199
+ position: 'relative',
200
+ ...(vertical && {
201
+ height: `${verticalHeight}px`,
202
+ }),
203
+ }}
204
+ value={radixValue}
205
+ onValueChange={(newValue: number[]) => {
206
+ let singleValue = newValue[0];
207
+
208
+ // Snap to nearest mark if step is null and marks exist
209
+ if (
210
+ step === null &&
211
+ processedMarks &&
212
+ typeof processedMarks === 'object'
213
+ ) {
214
+ singleValue = snapToNearestMark(
215
+ singleValue,
216
+ processedMarks
217
+ );
218
+ }
219
+
220
+ setValue(singleValue);
221
+ if (updatemode === 'drag') {
222
+ setProps({
223
+ value: singleValue,
224
+ drag_value: singleValue,
225
+ });
226
+ } else {
227
+ setProps({drag_value: singleValue});
228
+ }
229
+ }}
230
+ onValueCommit={() => {
231
+ if (updatemode === 'mouseup') {
232
+ setProps({value});
233
+ }
234
+ }}
235
+ min={minMaxValues.min_mark}
236
+ max={minMaxValues.max_mark}
237
+ step={stepValue}
238
+ disabled={disabled}
239
+ orientation={
240
+ vertical ? 'vertical' : 'horizontal'
241
+ }
242
+ data-included={included !== false}
243
+ >
244
+ <RadixSlider.Track className="dash-slider-track">
245
+ {included !== false && (
246
+ <RadixSlider.Range className="dash-slider-range" />
247
+ )}
248
+ </RadixSlider.Track>
249
+
250
+ {renderedMarks &&
251
+ renderSliderMarks(
252
+ renderedMarks,
253
+ !!vertical,
254
+ minMaxValues,
255
+ !!dots
256
+ )}
257
+
258
+ {dots &&
259
+ stepValue &&
260
+ renderSliderDots(
261
+ stepValue,
262
+ minMaxValues,
263
+ !!vertical
264
+ )}
265
+
266
+ {/* Thumb with tooltip */}
267
+ {tooltip ? (
268
+ <Tooltip.Root
269
+ open={
270
+ tooltip.always_visible || undefined
271
+ }
272
+ >
273
+ <Tooltip.Trigger asChild>
274
+ <RadixSlider.Thumb className="dash-slider-thumb" />
275
+ </Tooltip.Trigger>
276
+ <Tooltip.Portal>
277
+ <Tooltip.Content
278
+ className="dash-slider-tooltip"
279
+ side={
280
+ vertical ? 'right' : 'top'
281
+ }
282
+ sideOffset={5}
283
+ >
284
+ {tooltipContent}
285
+ <Tooltip.Arrow />
286
+ </Tooltip.Content>
287
+ </Tooltip.Portal>
288
+ </Tooltip.Root>
289
+ ) : (
290
+ <RadixSlider.Thumb className="dash-slider-thumb" />
291
+ )}
292
+ </RadixSlider.Root>
293
+ </Tooltip.Provider>
294
+ </div>
295
+ {showInput && !vertical && (
296
+ <input
297
+ type="number"
298
+ className="dash-input-container dash-slider-input"
299
+ value={value ?? ''}
300
+ onChange={e => {
301
+ const inputValue = e.target.value;
302
+ // Allow empty string (user is clearing the field)
303
+ if (inputValue === '') {
304
+ setValue(null);
305
+ } else {
306
+ const numericValue = parseFloat(inputValue);
307
+ const constrainedValue = Math.max(
308
+ minMaxValues.min_mark,
309
+ Math.min(
310
+ minMaxValues.max_mark,
311
+ numericValue
312
+ )
313
+ );
314
+
315
+ if (numericValue === constrainedValue) {
316
+ setProps({
317
+ value: numericValue,
318
+ drag_value: numericValue,
319
+ });
320
+ }
321
+ }
322
+ }}
323
+ onBlur={e => {
324
+ const inputValue = e.target.value;
325
+ // If empty, use the current slider value or default to min
326
+ if (inputValue === '') {
327
+ const defaultValue =
328
+ value ?? minMaxValues.min_mark;
329
+ setProps({
330
+ value: defaultValue,
331
+ drag_value: defaultValue,
332
+ });
333
+ return;
334
+ }
335
+
336
+ // Otherwise, constrain value to the given min and max
337
+ let numericValue = parseFloat(inputValue);
338
+ numericValue = isNaN(numericValue)
339
+ ? minMaxValues.min_mark
340
+ : numericValue;
341
+ const constrainedValue = Math.max(
342
+ minMaxValues.min_mark,
343
+ Math.min(
344
+ minMaxValues.max_mark,
345
+ numericValue
346
+ )
347
+ );
348
+ setProps({
349
+ value: constrainedValue,
350
+ drag_value: constrainedValue,
351
+ });
352
+ }}
353
+ pattern="^\\d*\\.?\\d*$"
354
+ min={minMaxValues.min_mark}
355
+ max={minMaxValues.max_mark}
356
+ step={step || undefined}
357
+ disabled={disabled}
358
+ />
359
+ )}
360
+ </div>
361
+ )}
362
+ </LoadingElement>
363
+ );
364
+ }
package/lib/index.ts ADDED
@@ -0,0 +1,58 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ import Checklist from './components/Checklist.react';
3
+ import Clipboard from './components/Clipboard.react';
4
+ import ConfirmDialog from './components/ConfirmDialog.react';
5
+ import ConfirmDialogProvider from './components/ConfirmDialogProvider.react';
6
+ import DatePickerRange from './components/DatePickerRange.react';
7
+ import DatePickerSingle from './components/DatePickerSingle.react';
8
+ import Download from './components/Download.react';
9
+ import Dropdown from './components/Dropdown.react';
10
+ import Geolocation from './components/Geolocation.react';
11
+ import Graph from './components/Graph.react';
12
+ import Input from './components/Input';
13
+ import Interval from './components/Interval.react';
14
+ import Link from './components/Link.react';
15
+ import Loading from './components/Loading.react';
16
+ import Location from './components/Location.react';
17
+ import Markdown from './components/Markdown.react';
18
+ import RadioItems from './components/RadioItems.react';
19
+ import RangeSlider from './components/RangeSlider';
20
+ import Slider from './components/Slider';
21
+ import Store from './components/Store.react';
22
+ import Tab from './components/Tab.react';
23
+ import Tabs from './components/Tabs.react';
24
+ import Textarea from './components/Textarea.react';
25
+ import Tooltip from './components/Tooltip.react';
26
+ import Upload from './components/Upload.react';
27
+
28
+ 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
+
32
+ export {
33
+ Checklist,
34
+ Clipboard,
35
+ ConfirmDialog,
36
+ ConfirmDialogProvider,
37
+ DatePickerRange,
38
+ DatePickerSingle,
39
+ Download,
40
+ Dropdown,
41
+ Geolocation,
42
+ Graph,
43
+ Interval,
44
+ Input,
45
+ Link,
46
+ Loading,
47
+ Location,
48
+ Markdown,
49
+ RadioItems,
50
+ RangeSlider,
51
+ Slider,
52
+ Store,
53
+ Tab,
54
+ Tabs,
55
+ Textarea,
56
+ Tooltip,
57
+ Upload,
58
+ };