dash-core-components 4.0.0-rc0 → 4.0.0-rc1
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.
- package/dash_core_components/async-datepicker.js +1 -1
- package/dash_core_components/async-datepicker.js.map +1 -1
- package/dash_core_components/async-dropdown.js +1 -1
- package/dash_core_components/async-dropdown.js.map +1 -1
- package/dash_core_components/async-graph.js +1 -1
- package/dash_core_components/async-slider.js +1 -2
- package/dash_core_components/async-slider.js.map +1 -1
- package/dash_core_components/dash_core_components-shared.js +1 -1
- package/dash_core_components/dash_core_components-shared.js.map +1 -1
- package/dash_core_components/dash_core_components.js +1 -1
- package/dash_core_components/dash_core_components.js.map +1 -1
- package/dash_core_components/proptypes.js +18 -0
- package/lib/components/Dropdown.tsx +52 -0
- package/lib/components/RangeSlider.tsx +8 -1
- package/lib/components/Textarea.react.js.old +287 -0
- package/lib/components/css/dcc.css +1 -0
- package/lib/components/css/dropdown.css +230 -0
- package/lib/components/css/sliders.css +8 -0
- package/lib/fragments/Dropdown.tsx +577 -0
- package/lib/fragments/RangeSlider.tsx +71 -71
- package/lib/index.ts +1 -1
- package/lib/types.ts +168 -0
- package/lib/utils/LazyLoader/dropdown.ts +2 -0
- package/lib/utils/_LoadingElement.tsx +8 -18
- package/lib/utils/dropdownSearch.ts +92 -0
- package/lib/utils/optionTypes.ts +27 -0
- package/package.json +7 -3
- package/lib/components/Dropdown.react.js +0 -182
- package/lib/fragments/Dropdown.react.js +0 -158
- package/lib/fragments/Slider.tsx.old +0 -364
- package/lib/utils/LazyLoader/dropdown.js +0 -8
|
@@ -1,364 +0,0 @@
|
|
|
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
|
-
}
|