@radix-ui/react-slider 0.1.5-rc.4 → 0.1.5-rc.40
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +604 -1
- package/dist/index.js.map +1 -1
- package/dist/index.module.js +585 -1
- package/dist/index.module.js.map +1 -1
- package/package.json +12 -11
package/dist/index.module.js
CHANGED
|
@@ -1,2 +1,586 @@
|
|
|
1
|
-
import
|
|
1
|
+
import $g1Vy2$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import {forwardRef as $g1Vy2$forwardRef, useState as $g1Vy2$useState, useRef as $g1Vy2$useRef, createElement as $g1Vy2$createElement, useMemo as $g1Vy2$useMemo, useEffect as $g1Vy2$useEffect} from "react";
|
|
3
|
+
import {clamp as $g1Vy2$clamp} from "@radix-ui/number";
|
|
4
|
+
import {composeEventHandlers as $g1Vy2$composeEventHandlers} from "@radix-ui/primitive";
|
|
5
|
+
import {useComposedRefs as $g1Vy2$useComposedRefs} from "@radix-ui/react-compose-refs";
|
|
6
|
+
import {createContextScope as $g1Vy2$createContextScope} from "@radix-ui/react-context";
|
|
7
|
+
import {useControllableState as $g1Vy2$useControllableState} from "@radix-ui/react-use-controllable-state";
|
|
8
|
+
import {useDirection as $g1Vy2$useDirection} from "@radix-ui/react-direction";
|
|
9
|
+
import {usePrevious as $g1Vy2$usePrevious} from "@radix-ui/react-use-previous";
|
|
10
|
+
import {useSize as $g1Vy2$useSize} from "@radix-ui/react-use-size";
|
|
11
|
+
import {Primitive as $g1Vy2$Primitive} from "@radix-ui/react-primitive";
|
|
12
|
+
import {createCollection as $g1Vy2$createCollection} from "@radix-ui/react-collection";
|
|
13
|
+
|
|
14
|
+
function $parcel$export(e, n, v, s) {
|
|
15
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
16
|
+
}
|
|
17
|
+
var $faa2e61a3361514f$exports = {};
|
|
18
|
+
|
|
19
|
+
$parcel$export($faa2e61a3361514f$exports, "createSliderScope", () => $faa2e61a3361514f$export$ef72632d7b901f97);
|
|
20
|
+
$parcel$export($faa2e61a3361514f$exports, "Slider", () => $faa2e61a3361514f$export$472062a354075cee);
|
|
21
|
+
$parcel$export($faa2e61a3361514f$exports, "SliderTrack", () => $faa2e61a3361514f$export$105594979f116971);
|
|
22
|
+
$parcel$export($faa2e61a3361514f$exports, "SliderRange", () => $faa2e61a3361514f$export$a5cf38a7a000fe77);
|
|
23
|
+
$parcel$export($faa2e61a3361514f$exports, "SliderThumb", () => $faa2e61a3361514f$export$2c1b491743890dec);
|
|
24
|
+
$parcel$export($faa2e61a3361514f$exports, "Root", () => $faa2e61a3361514f$export$be92b6f5f03c0fe9);
|
|
25
|
+
$parcel$export($faa2e61a3361514f$exports, "Track", () => $faa2e61a3361514f$export$13921ac0cc260818);
|
|
26
|
+
$parcel$export($faa2e61a3361514f$exports, "Range", () => $faa2e61a3361514f$export$9a58ef0d7ad3278c);
|
|
27
|
+
$parcel$export($faa2e61a3361514f$exports, "Thumb", () => $faa2e61a3361514f$export$6521433ed15a34db);
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const $faa2e61a3361514f$var$PAGE_KEYS = [
|
|
41
|
+
'PageUp',
|
|
42
|
+
'PageDown'
|
|
43
|
+
];
|
|
44
|
+
const $faa2e61a3361514f$var$ARROW_KEYS = [
|
|
45
|
+
'ArrowUp',
|
|
46
|
+
'ArrowDown',
|
|
47
|
+
'ArrowLeft',
|
|
48
|
+
'ArrowRight'
|
|
49
|
+
];
|
|
50
|
+
const $faa2e61a3361514f$var$BACK_KEYS = {
|
|
51
|
+
ltr: [
|
|
52
|
+
'ArrowDown',
|
|
53
|
+
'Home',
|
|
54
|
+
'ArrowLeft',
|
|
55
|
+
'PageDown'
|
|
56
|
+
],
|
|
57
|
+
rtl: [
|
|
58
|
+
'ArrowDown',
|
|
59
|
+
'Home',
|
|
60
|
+
'ArrowRight',
|
|
61
|
+
'PageDown'
|
|
62
|
+
]
|
|
63
|
+
};
|
|
64
|
+
/* -------------------------------------------------------------------------------------------------
|
|
65
|
+
* Slider
|
|
66
|
+
* -----------------------------------------------------------------------------------------------*/ const $faa2e61a3361514f$var$SLIDER_NAME = 'Slider';
|
|
67
|
+
const [$faa2e61a3361514f$var$Collection, $faa2e61a3361514f$var$useCollection, $faa2e61a3361514f$var$createCollectionScope] = $g1Vy2$createCollection($faa2e61a3361514f$var$SLIDER_NAME);
|
|
68
|
+
const [$faa2e61a3361514f$var$createSliderContext, $faa2e61a3361514f$export$ef72632d7b901f97] = $g1Vy2$createContextScope($faa2e61a3361514f$var$SLIDER_NAME, [
|
|
69
|
+
$faa2e61a3361514f$var$createCollectionScope
|
|
70
|
+
]);
|
|
71
|
+
const [$faa2e61a3361514f$var$SliderProvider, $faa2e61a3361514f$var$useSliderContext] = $faa2e61a3361514f$var$createSliderContext($faa2e61a3361514f$var$SLIDER_NAME);
|
|
72
|
+
const $faa2e61a3361514f$export$472062a354075cee = /*#__PURE__*/ $g1Vy2$forwardRef((props, forwardedRef)=>{
|
|
73
|
+
const { name: name , min: min = 0 , max: max = 100 , step: step = 1 , orientation: orientation = 'horizontal' , disabled: disabled = false , minStepsBetweenThumbs: minStepsBetweenThumbs = 0 , defaultValue: defaultValue = [
|
|
74
|
+
min
|
|
75
|
+
] , value: value1 , onValueChange: onValueChange = ()=>{} , ...sliderProps } = props;
|
|
76
|
+
const [slider, setSlider] = $g1Vy2$useState(null);
|
|
77
|
+
const composedRefs = $g1Vy2$useComposedRefs(forwardedRef, (node)=>setSlider(node)
|
|
78
|
+
);
|
|
79
|
+
const thumbRefs = $g1Vy2$useRef(new Set());
|
|
80
|
+
const valueIndexToChangeRef = $g1Vy2$useRef(0);
|
|
81
|
+
const isHorizontal = orientation === 'horizontal'; // We set this to true by default so that events bubble to forms without JS (SSR)
|
|
82
|
+
const isFormControl = slider ? Boolean(slider.closest('form')) : true;
|
|
83
|
+
const SliderOrientation = isHorizontal ? $faa2e61a3361514f$var$SliderHorizontal : $faa2e61a3361514f$var$SliderVertical;
|
|
84
|
+
const [values = [], setValues] = $g1Vy2$useControllableState({
|
|
85
|
+
prop: value1,
|
|
86
|
+
defaultProp: defaultValue,
|
|
87
|
+
onChange: (value)=>{
|
|
88
|
+
var _thumbs$valueIndexToC;
|
|
89
|
+
const thumbs = [
|
|
90
|
+
...thumbRefs.current
|
|
91
|
+
];
|
|
92
|
+
(_thumbs$valueIndexToC = thumbs[valueIndexToChangeRef.current]) === null || _thumbs$valueIndexToC === void 0 || _thumbs$valueIndexToC.focus();
|
|
93
|
+
onValueChange(value);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
function handleSlideStart(value) {
|
|
97
|
+
const closestIndex = $faa2e61a3361514f$var$getClosestValueIndex(values, value);
|
|
98
|
+
updateValues(value, closestIndex);
|
|
99
|
+
}
|
|
100
|
+
function handleSlideMove(value) {
|
|
101
|
+
updateValues(value, valueIndexToChangeRef.current);
|
|
102
|
+
}
|
|
103
|
+
function updateValues(value, atIndex) {
|
|
104
|
+
const decimalCount = $faa2e61a3361514f$var$getDecimalCount(step);
|
|
105
|
+
const snapToStep = $faa2e61a3361514f$var$roundValue(Math.round((value - min) / step) * step + min, decimalCount);
|
|
106
|
+
const nextValue = $g1Vy2$clamp(snapToStep, [
|
|
107
|
+
min,
|
|
108
|
+
max
|
|
109
|
+
]);
|
|
110
|
+
setValues((prevValues = [])=>{
|
|
111
|
+
const nextValues = $faa2e61a3361514f$var$getNextSortedValues(prevValues, nextValue, atIndex);
|
|
112
|
+
if ($faa2e61a3361514f$var$hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {
|
|
113
|
+
valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
|
|
114
|
+
return String(nextValues) === String(prevValues) ? prevValues : nextValues;
|
|
115
|
+
} else return prevValues;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return /*#__PURE__*/ $g1Vy2$createElement($faa2e61a3361514f$var$SliderProvider, {
|
|
119
|
+
scope: props.__scopeSlider,
|
|
120
|
+
disabled: disabled,
|
|
121
|
+
min: min,
|
|
122
|
+
max: max,
|
|
123
|
+
valueIndexToChangeRef: valueIndexToChangeRef,
|
|
124
|
+
thumbs: thumbRefs.current,
|
|
125
|
+
values: values,
|
|
126
|
+
orientation: orientation
|
|
127
|
+
}, /*#__PURE__*/ $g1Vy2$createElement($faa2e61a3361514f$var$Collection.Provider, {
|
|
128
|
+
scope: props.__scopeSlider
|
|
129
|
+
}, /*#__PURE__*/ $g1Vy2$createElement($faa2e61a3361514f$var$Collection.Slot, {
|
|
130
|
+
scope: props.__scopeSlider
|
|
131
|
+
}, /*#__PURE__*/ $g1Vy2$createElement(SliderOrientation, $g1Vy2$babelruntimehelpersesmextends({
|
|
132
|
+
"aria-disabled": disabled,
|
|
133
|
+
"data-disabled": disabled ? '' : undefined
|
|
134
|
+
}, sliderProps, {
|
|
135
|
+
ref: composedRefs,
|
|
136
|
+
min: min,
|
|
137
|
+
max: max,
|
|
138
|
+
onSlideStart: disabled ? undefined : handleSlideStart,
|
|
139
|
+
onSlideMove: disabled ? undefined : handleSlideMove,
|
|
140
|
+
onHomeKeyDown: ()=>!disabled && updateValues(min, 0)
|
|
141
|
+
,
|
|
142
|
+
onEndKeyDown: ()=>!disabled && updateValues(max, values.length - 1)
|
|
143
|
+
,
|
|
144
|
+
onStepKeyDown: ({ event: event , direction: stepDirection })=>{
|
|
145
|
+
if (!disabled) {
|
|
146
|
+
const isPageKey = $faa2e61a3361514f$var$PAGE_KEYS.includes(event.key);
|
|
147
|
+
const isSkipKey = isPageKey || event.shiftKey && $faa2e61a3361514f$var$ARROW_KEYS.includes(event.key);
|
|
148
|
+
const multiplier = isSkipKey ? 10 : 1;
|
|
149
|
+
const atIndex = valueIndexToChangeRef.current;
|
|
150
|
+
const value = values[atIndex];
|
|
151
|
+
const stepInDirection = step * multiplier * stepDirection;
|
|
152
|
+
updateValues(value + stepInDirection, atIndex);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
})))), isFormControl && values.map((value, index)=>/*#__PURE__*/ $g1Vy2$createElement($faa2e61a3361514f$var$BubbleInput, {
|
|
156
|
+
key: index,
|
|
157
|
+
name: name ? name + (values.length > 1 ? '[]' : '') : undefined,
|
|
158
|
+
value: value
|
|
159
|
+
})
|
|
160
|
+
));
|
|
161
|
+
});
|
|
162
|
+
/*#__PURE__*/ Object.assign($faa2e61a3361514f$export$472062a354075cee, {
|
|
163
|
+
displayName: $faa2e61a3361514f$var$SLIDER_NAME
|
|
164
|
+
});
|
|
165
|
+
/* -------------------------------------------------------------------------------------------------
|
|
166
|
+
* SliderHorizontal
|
|
167
|
+
* -----------------------------------------------------------------------------------------------*/ const [$faa2e61a3361514f$var$SliderOrientationProvider, $faa2e61a3361514f$var$useSliderOrientationContext] = $faa2e61a3361514f$var$createSliderContext($faa2e61a3361514f$var$SLIDER_NAME, {
|
|
168
|
+
startEdge: 'left',
|
|
169
|
+
endEdge: 'right',
|
|
170
|
+
size: 'width',
|
|
171
|
+
direction: 1
|
|
172
|
+
});
|
|
173
|
+
const $faa2e61a3361514f$var$SliderHorizontal = /*#__PURE__*/ $g1Vy2$forwardRef((props, forwardedRef)=>{
|
|
174
|
+
const { min: min , max: max , dir: dir , onSlideStart: onSlideStart , onSlideMove: onSlideMove , onStepKeyDown: onStepKeyDown , ...sliderProps } = props;
|
|
175
|
+
const [slider, setSlider] = $g1Vy2$useState(null);
|
|
176
|
+
const composedRefs = $g1Vy2$useComposedRefs(forwardedRef, (node)=>setSlider(node)
|
|
177
|
+
);
|
|
178
|
+
const rectRef = $g1Vy2$useRef();
|
|
179
|
+
const direction = $g1Vy2$useDirection(dir);
|
|
180
|
+
const isDirectionLTR = direction === 'ltr';
|
|
181
|
+
function getValueFromPointer(pointerPosition) {
|
|
182
|
+
const rect = rectRef.current || slider.getBoundingClientRect();
|
|
183
|
+
const input = [
|
|
184
|
+
0,
|
|
185
|
+
rect.width
|
|
186
|
+
];
|
|
187
|
+
const output = isDirectionLTR ? [
|
|
188
|
+
min,
|
|
189
|
+
max
|
|
190
|
+
] : [
|
|
191
|
+
max,
|
|
192
|
+
min
|
|
193
|
+
];
|
|
194
|
+
const value = $faa2e61a3361514f$var$linearScale(input, output);
|
|
195
|
+
rectRef.current = rect;
|
|
196
|
+
return value(pointerPosition - rect.left);
|
|
197
|
+
}
|
|
198
|
+
return /*#__PURE__*/ $g1Vy2$createElement($faa2e61a3361514f$var$SliderOrientationProvider, {
|
|
199
|
+
scope: props.__scopeSlider,
|
|
200
|
+
startEdge: isDirectionLTR ? 'left' : 'right',
|
|
201
|
+
endEdge: isDirectionLTR ? 'right' : 'left',
|
|
202
|
+
direction: isDirectionLTR ? 1 : -1,
|
|
203
|
+
size: "width"
|
|
204
|
+
}, /*#__PURE__*/ $g1Vy2$createElement($faa2e61a3361514f$var$SliderImpl, $g1Vy2$babelruntimehelpersesmextends({
|
|
205
|
+
dir: direction,
|
|
206
|
+
"data-orientation": "horizontal"
|
|
207
|
+
}, sliderProps, {
|
|
208
|
+
ref: composedRefs,
|
|
209
|
+
style: {
|
|
210
|
+
...sliderProps.style,
|
|
211
|
+
['--radix-slider-thumb-transform']: 'translateX(-50%)'
|
|
212
|
+
},
|
|
213
|
+
onSlideStart: (event)=>{
|
|
214
|
+
const value = getValueFromPointer(event.clientX);
|
|
215
|
+
onSlideStart === null || onSlideStart === void 0 || onSlideStart(value);
|
|
216
|
+
},
|
|
217
|
+
onSlideMove: (event)=>{
|
|
218
|
+
const value = getValueFromPointer(event.clientX);
|
|
219
|
+
onSlideMove === null || onSlideMove === void 0 || onSlideMove(value);
|
|
220
|
+
},
|
|
221
|
+
onSlideEnd: ()=>rectRef.current = undefined
|
|
222
|
+
,
|
|
223
|
+
onStepKeyDown: (event)=>{
|
|
224
|
+
const isBackKey = $faa2e61a3361514f$var$BACK_KEYS[direction].includes(event.key);
|
|
225
|
+
onStepKeyDown === null || onStepKeyDown === void 0 || onStepKeyDown({
|
|
226
|
+
event: event,
|
|
227
|
+
direction: isBackKey ? -1 : 1
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
})));
|
|
231
|
+
});
|
|
232
|
+
/* -------------------------------------------------------------------------------------------------
|
|
233
|
+
* SliderVertical
|
|
234
|
+
* -----------------------------------------------------------------------------------------------*/ const $faa2e61a3361514f$var$SliderVertical = /*#__PURE__*/ $g1Vy2$forwardRef((props, forwardedRef)=>{
|
|
235
|
+
const { min: min , max: max , onSlideStart: onSlideStart , onSlideMove: onSlideMove , onStepKeyDown: onStepKeyDown , ...sliderProps } = props;
|
|
236
|
+
const sliderRef = $g1Vy2$useRef(null);
|
|
237
|
+
const ref = $g1Vy2$useComposedRefs(forwardedRef, sliderRef);
|
|
238
|
+
const rectRef = $g1Vy2$useRef();
|
|
239
|
+
function getValueFromPointer(pointerPosition) {
|
|
240
|
+
const rect = rectRef.current || sliderRef.current.getBoundingClientRect();
|
|
241
|
+
const input = [
|
|
242
|
+
0,
|
|
243
|
+
rect.height
|
|
244
|
+
];
|
|
245
|
+
const output = [
|
|
246
|
+
max,
|
|
247
|
+
min
|
|
248
|
+
];
|
|
249
|
+
const value = $faa2e61a3361514f$var$linearScale(input, output);
|
|
250
|
+
rectRef.current = rect;
|
|
251
|
+
return value(pointerPosition - rect.top);
|
|
252
|
+
}
|
|
253
|
+
return /*#__PURE__*/ $g1Vy2$createElement($faa2e61a3361514f$var$SliderOrientationProvider, {
|
|
254
|
+
scope: props.__scopeSlider,
|
|
255
|
+
startEdge: "bottom",
|
|
256
|
+
endEdge: "top",
|
|
257
|
+
size: "height",
|
|
258
|
+
direction: 1
|
|
259
|
+
}, /*#__PURE__*/ $g1Vy2$createElement($faa2e61a3361514f$var$SliderImpl, $g1Vy2$babelruntimehelpersesmextends({
|
|
260
|
+
"data-orientation": "vertical"
|
|
261
|
+
}, sliderProps, {
|
|
262
|
+
ref: ref,
|
|
263
|
+
style: {
|
|
264
|
+
...sliderProps.style,
|
|
265
|
+
['--radix-slider-thumb-transform']: 'translateY(50%)'
|
|
266
|
+
},
|
|
267
|
+
onSlideStart: (event)=>{
|
|
268
|
+
const value = getValueFromPointer(event.clientY);
|
|
269
|
+
onSlideStart === null || onSlideStart === void 0 || onSlideStart(value);
|
|
270
|
+
},
|
|
271
|
+
onSlideMove: (event)=>{
|
|
272
|
+
const value = getValueFromPointer(event.clientY);
|
|
273
|
+
onSlideMove === null || onSlideMove === void 0 || onSlideMove(value);
|
|
274
|
+
},
|
|
275
|
+
onSlideEnd: ()=>rectRef.current = undefined
|
|
276
|
+
,
|
|
277
|
+
onStepKeyDown: (event)=>{
|
|
278
|
+
const isBackKey = $faa2e61a3361514f$var$BACK_KEYS.ltr.includes(event.key);
|
|
279
|
+
onStepKeyDown === null || onStepKeyDown === void 0 || onStepKeyDown({
|
|
280
|
+
event: event,
|
|
281
|
+
direction: isBackKey ? -1 : 1
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
})));
|
|
285
|
+
});
|
|
286
|
+
/* -------------------------------------------------------------------------------------------------
|
|
287
|
+
* SliderImpl
|
|
288
|
+
* -----------------------------------------------------------------------------------------------*/ const $faa2e61a3361514f$var$SliderImpl = /*#__PURE__*/ $g1Vy2$forwardRef((props, forwardedRef)=>{
|
|
289
|
+
const { __scopeSlider: __scopeSlider , onSlideStart: onSlideStart , onSlideMove: onSlideMove , onSlideEnd: onSlideEnd , onHomeKeyDown: onHomeKeyDown , onEndKeyDown: onEndKeyDown , onStepKeyDown: onStepKeyDown , ...sliderProps } = props;
|
|
290
|
+
const context = $faa2e61a3361514f$var$useSliderContext($faa2e61a3361514f$var$SLIDER_NAME, __scopeSlider);
|
|
291
|
+
return /*#__PURE__*/ $g1Vy2$createElement($g1Vy2$Primitive.span, $g1Vy2$babelruntimehelpersesmextends({}, sliderProps, {
|
|
292
|
+
ref: forwardedRef,
|
|
293
|
+
onKeyDown: $g1Vy2$composeEventHandlers(props.onKeyDown, (event)=>{
|
|
294
|
+
if (event.key === 'Home') {
|
|
295
|
+
onHomeKeyDown(event); // Prevent scrolling to page start
|
|
296
|
+
event.preventDefault();
|
|
297
|
+
} else if (event.key === 'End') {
|
|
298
|
+
onEndKeyDown(event); // Prevent scrolling to page end
|
|
299
|
+
event.preventDefault();
|
|
300
|
+
} else if ($faa2e61a3361514f$var$PAGE_KEYS.concat($faa2e61a3361514f$var$ARROW_KEYS).includes(event.key)) {
|
|
301
|
+
onStepKeyDown(event); // Prevent scrolling for directional key presses
|
|
302
|
+
event.preventDefault();
|
|
303
|
+
}
|
|
304
|
+
}),
|
|
305
|
+
onPointerDown: $g1Vy2$composeEventHandlers(props.onPointerDown, (event)=>{
|
|
306
|
+
const target = event.target;
|
|
307
|
+
target.setPointerCapture(event.pointerId); // Prevent browser focus behaviour because we focus a thumb manually when values change.
|
|
308
|
+
event.preventDefault(); // Touch devices have a delay before focusing so won't focus if touch immediately moves
|
|
309
|
+
// away from target (sliding). We want thumb to focus regardless.
|
|
310
|
+
if (context.thumbs.has(target)) target.focus();
|
|
311
|
+
else onSlideStart(event);
|
|
312
|
+
}),
|
|
313
|
+
onPointerMove: $g1Vy2$composeEventHandlers(props.onPointerMove, (event)=>{
|
|
314
|
+
const target = event.target;
|
|
315
|
+
if (target.hasPointerCapture(event.pointerId)) onSlideMove(event);
|
|
316
|
+
}),
|
|
317
|
+
onPointerUp: $g1Vy2$composeEventHandlers(props.onPointerUp, (event)=>{
|
|
318
|
+
const target = event.target;
|
|
319
|
+
if (target.hasPointerCapture(event.pointerId)) {
|
|
320
|
+
target.releasePointerCapture(event.pointerId);
|
|
321
|
+
onSlideEnd(event);
|
|
322
|
+
}
|
|
323
|
+
})
|
|
324
|
+
}));
|
|
325
|
+
});
|
|
326
|
+
/* -------------------------------------------------------------------------------------------------
|
|
327
|
+
* SliderTrack
|
|
328
|
+
* -----------------------------------------------------------------------------------------------*/ const $faa2e61a3361514f$var$TRACK_NAME = 'SliderTrack';
|
|
329
|
+
const $faa2e61a3361514f$export$105594979f116971 = /*#__PURE__*/ $g1Vy2$forwardRef((props, forwardedRef)=>{
|
|
330
|
+
const { __scopeSlider: __scopeSlider , ...trackProps } = props;
|
|
331
|
+
const context = $faa2e61a3361514f$var$useSliderContext($faa2e61a3361514f$var$TRACK_NAME, __scopeSlider);
|
|
332
|
+
return /*#__PURE__*/ $g1Vy2$createElement($g1Vy2$Primitive.span, $g1Vy2$babelruntimehelpersesmextends({
|
|
333
|
+
"data-disabled": context.disabled ? '' : undefined,
|
|
334
|
+
"data-orientation": context.orientation
|
|
335
|
+
}, trackProps, {
|
|
336
|
+
ref: forwardedRef
|
|
337
|
+
}));
|
|
338
|
+
});
|
|
339
|
+
/*#__PURE__*/ Object.assign($faa2e61a3361514f$export$105594979f116971, {
|
|
340
|
+
displayName: $faa2e61a3361514f$var$TRACK_NAME
|
|
341
|
+
});
|
|
342
|
+
/* -------------------------------------------------------------------------------------------------
|
|
343
|
+
* SliderRange
|
|
344
|
+
* -----------------------------------------------------------------------------------------------*/ const $faa2e61a3361514f$var$RANGE_NAME = 'SliderRange';
|
|
345
|
+
const $faa2e61a3361514f$export$a5cf38a7a000fe77 = /*#__PURE__*/ $g1Vy2$forwardRef((props, forwardedRef)=>{
|
|
346
|
+
const { __scopeSlider: __scopeSlider , ...rangeProps } = props;
|
|
347
|
+
const context = $faa2e61a3361514f$var$useSliderContext($faa2e61a3361514f$var$RANGE_NAME, __scopeSlider);
|
|
348
|
+
const orientation = $faa2e61a3361514f$var$useSliderOrientationContext($faa2e61a3361514f$var$RANGE_NAME, __scopeSlider);
|
|
349
|
+
const ref = $g1Vy2$useRef(null);
|
|
350
|
+
const composedRefs = $g1Vy2$useComposedRefs(forwardedRef, ref);
|
|
351
|
+
const valuesCount = context.values.length;
|
|
352
|
+
const percentages = context.values.map((value)=>$faa2e61a3361514f$var$convertValueToPercentage(value, context.min, context.max)
|
|
353
|
+
);
|
|
354
|
+
const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0;
|
|
355
|
+
const offsetEnd = 100 - Math.max(...percentages);
|
|
356
|
+
return /*#__PURE__*/ $g1Vy2$createElement($g1Vy2$Primitive.span, $g1Vy2$babelruntimehelpersesmextends({
|
|
357
|
+
"data-orientation": context.orientation,
|
|
358
|
+
"data-disabled": context.disabled ? '' : undefined
|
|
359
|
+
}, rangeProps, {
|
|
360
|
+
ref: composedRefs,
|
|
361
|
+
style: {
|
|
362
|
+
...props.style,
|
|
363
|
+
[orientation.startEdge]: offsetStart + '%',
|
|
364
|
+
[orientation.endEdge]: offsetEnd + '%'
|
|
365
|
+
}
|
|
366
|
+
}));
|
|
367
|
+
});
|
|
368
|
+
/*#__PURE__*/ Object.assign($faa2e61a3361514f$export$a5cf38a7a000fe77, {
|
|
369
|
+
displayName: $faa2e61a3361514f$var$RANGE_NAME
|
|
370
|
+
});
|
|
371
|
+
/* -------------------------------------------------------------------------------------------------
|
|
372
|
+
* SliderThumb
|
|
373
|
+
* -----------------------------------------------------------------------------------------------*/ const $faa2e61a3361514f$var$THUMB_NAME = 'SliderThumb';
|
|
374
|
+
const $faa2e61a3361514f$export$2c1b491743890dec = /*#__PURE__*/ $g1Vy2$forwardRef((props, forwardedRef)=>{
|
|
375
|
+
const getItems = $faa2e61a3361514f$var$useCollection(props.__scopeSlider);
|
|
376
|
+
const [thumb, setThumb] = $g1Vy2$useState(null);
|
|
377
|
+
const composedRefs = $g1Vy2$useComposedRefs(forwardedRef, (node)=>setThumb(node)
|
|
378
|
+
);
|
|
379
|
+
const index = $g1Vy2$useMemo(()=>thumb ? getItems().findIndex((item)=>item.ref.current === thumb
|
|
380
|
+
) : -1
|
|
381
|
+
, [
|
|
382
|
+
getItems,
|
|
383
|
+
thumb
|
|
384
|
+
]);
|
|
385
|
+
return /*#__PURE__*/ $g1Vy2$createElement($faa2e61a3361514f$var$SliderThumbImpl, $g1Vy2$babelruntimehelpersesmextends({}, props, {
|
|
386
|
+
ref: composedRefs,
|
|
387
|
+
index: index
|
|
388
|
+
}));
|
|
389
|
+
});
|
|
390
|
+
const $faa2e61a3361514f$var$SliderThumbImpl = /*#__PURE__*/ $g1Vy2$forwardRef((props, forwardedRef)=>{
|
|
391
|
+
const { __scopeSlider: __scopeSlider , index: index , ...thumbProps } = props;
|
|
392
|
+
const context = $faa2e61a3361514f$var$useSliderContext($faa2e61a3361514f$var$THUMB_NAME, __scopeSlider);
|
|
393
|
+
const orientation = $faa2e61a3361514f$var$useSliderOrientationContext($faa2e61a3361514f$var$THUMB_NAME, __scopeSlider);
|
|
394
|
+
const [thumb, setThumb] = $g1Vy2$useState(null);
|
|
395
|
+
const composedRefs = $g1Vy2$useComposedRefs(forwardedRef, (node)=>setThumb(node)
|
|
396
|
+
);
|
|
397
|
+
const size = $g1Vy2$useSize(thumb); // We cast because index could be `-1` which would return undefined
|
|
398
|
+
const value = context.values[index];
|
|
399
|
+
const percent = value === undefined ? 0 : $faa2e61a3361514f$var$convertValueToPercentage(value, context.min, context.max);
|
|
400
|
+
const label = $faa2e61a3361514f$var$getLabel(index, context.values.length);
|
|
401
|
+
const orientationSize = size === null || size === void 0 ? void 0 : size[orientation.size];
|
|
402
|
+
const thumbInBoundsOffset = orientationSize ? $faa2e61a3361514f$var$getThumbInBoundsOffset(orientationSize, percent, orientation.direction) : 0;
|
|
403
|
+
$g1Vy2$useEffect(()=>{
|
|
404
|
+
if (thumb) {
|
|
405
|
+
context.thumbs.add(thumb);
|
|
406
|
+
return ()=>{
|
|
407
|
+
context.thumbs.delete(thumb);
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
}, [
|
|
411
|
+
thumb,
|
|
412
|
+
context.thumbs
|
|
413
|
+
]);
|
|
414
|
+
return /*#__PURE__*/ $g1Vy2$createElement("span", {
|
|
415
|
+
style: {
|
|
416
|
+
transform: 'var(--radix-slider-thumb-transform)',
|
|
417
|
+
position: 'absolute',
|
|
418
|
+
[orientation.startEdge]: `calc(${percent}% + ${thumbInBoundsOffset}px)`
|
|
419
|
+
}
|
|
420
|
+
}, /*#__PURE__*/ $g1Vy2$createElement($faa2e61a3361514f$var$Collection.ItemSlot, {
|
|
421
|
+
scope: props.__scopeSlider
|
|
422
|
+
}, /*#__PURE__*/ $g1Vy2$createElement($g1Vy2$Primitive.span, $g1Vy2$babelruntimehelpersesmextends({
|
|
423
|
+
role: "slider",
|
|
424
|
+
"aria-label": props['aria-label'] || label,
|
|
425
|
+
"aria-valuemin": context.min,
|
|
426
|
+
"aria-valuenow": value,
|
|
427
|
+
"aria-valuemax": context.max,
|
|
428
|
+
"aria-orientation": context.orientation,
|
|
429
|
+
"data-orientation": context.orientation,
|
|
430
|
+
"data-disabled": context.disabled ? '' : undefined,
|
|
431
|
+
tabIndex: context.disabled ? undefined : 0
|
|
432
|
+
}, thumbProps, {
|
|
433
|
+
ref: composedRefs,
|
|
434
|
+
style: value === undefined ? {
|
|
435
|
+
display: 'none'
|
|
436
|
+
} : props.style,
|
|
437
|
+
onFocus: $g1Vy2$composeEventHandlers(props.onFocus, ()=>{
|
|
438
|
+
context.valueIndexToChangeRef.current = index;
|
|
439
|
+
})
|
|
440
|
+
}))));
|
|
441
|
+
});
|
|
442
|
+
/*#__PURE__*/ Object.assign($faa2e61a3361514f$export$2c1b491743890dec, {
|
|
443
|
+
displayName: $faa2e61a3361514f$var$THUMB_NAME
|
|
444
|
+
});
|
|
445
|
+
/* -----------------------------------------------------------------------------------------------*/ const $faa2e61a3361514f$var$BubbleInput = (props)=>{
|
|
446
|
+
const { value: value , ...inputProps } = props;
|
|
447
|
+
const ref = $g1Vy2$useRef(null);
|
|
448
|
+
const prevValue = $g1Vy2$usePrevious(value); // Bubble value change to parents (e.g form change event)
|
|
449
|
+
$g1Vy2$useEffect(()=>{
|
|
450
|
+
const input = ref.current;
|
|
451
|
+
const inputProto = window.HTMLInputElement.prototype;
|
|
452
|
+
const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'value');
|
|
453
|
+
const setValue = descriptor.set;
|
|
454
|
+
if (prevValue !== value && setValue) {
|
|
455
|
+
const event = new Event('input', {
|
|
456
|
+
bubbles: true
|
|
457
|
+
});
|
|
458
|
+
setValue.call(input, value);
|
|
459
|
+
input.dispatchEvent(event);
|
|
460
|
+
}
|
|
461
|
+
}, [
|
|
462
|
+
prevValue,
|
|
463
|
+
value
|
|
464
|
+
]);
|
|
465
|
+
/**
|
|
466
|
+
* We purposefully do not use `type="hidden"` here otherwise forms that
|
|
467
|
+
* wrap it will not be able to access its value via the FormData API.
|
|
468
|
+
*
|
|
469
|
+
* We purposefully do not add the `value` attribute here to allow the value
|
|
470
|
+
* to be set programatically and bubble to any parent form `onChange` event.
|
|
471
|
+
* Adding the `value` will cause React to consider the programatic
|
|
472
|
+
* dispatch a duplicate and it will get swallowed.
|
|
473
|
+
*/ return /*#__PURE__*/ $g1Vy2$createElement("input", $g1Vy2$babelruntimehelpersesmextends({
|
|
474
|
+
style: {
|
|
475
|
+
display: 'none'
|
|
476
|
+
}
|
|
477
|
+
}, inputProps, {
|
|
478
|
+
ref: ref,
|
|
479
|
+
defaultValue: value
|
|
480
|
+
}));
|
|
481
|
+
};
|
|
482
|
+
function $faa2e61a3361514f$var$getNextSortedValues(prevValues = [], nextValue, atIndex) {
|
|
483
|
+
const nextValues = [
|
|
484
|
+
...prevValues
|
|
485
|
+
];
|
|
486
|
+
nextValues[atIndex] = nextValue;
|
|
487
|
+
return nextValues.sort((a, b)=>a - b
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
function $faa2e61a3361514f$var$convertValueToPercentage(value, min, max) {
|
|
491
|
+
const maxSteps = max - min;
|
|
492
|
+
const percentPerStep = 100 / maxSteps;
|
|
493
|
+
return percentPerStep * (value - min);
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Returns a label for each thumb when there are two or more thumbs
|
|
497
|
+
*/ function $faa2e61a3361514f$var$getLabel(index, totalValues) {
|
|
498
|
+
if (totalValues > 2) return `Value ${index + 1} of ${totalValues}`;
|
|
499
|
+
else if (totalValues === 2) return [
|
|
500
|
+
'Minimum',
|
|
501
|
+
'Maximum'
|
|
502
|
+
][index];
|
|
503
|
+
else return undefined;
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Given a `values` array and a `nextValue`, determine which value in
|
|
507
|
+
* the array is closest to `nextValue` and return its index.
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* // returns 1
|
|
511
|
+
* getClosestValueIndex([10, 30], 25);
|
|
512
|
+
*/ function $faa2e61a3361514f$var$getClosestValueIndex(values, nextValue) {
|
|
513
|
+
if (values.length === 1) return 0;
|
|
514
|
+
const distances = values.map((value)=>Math.abs(value - nextValue)
|
|
515
|
+
);
|
|
516
|
+
const closestDistance = Math.min(...distances);
|
|
517
|
+
return distances.indexOf(closestDistance);
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Offsets the thumb centre point while sliding to ensure it remains
|
|
521
|
+
* within the bounds of the slider when reaching the edges
|
|
522
|
+
*/ function $faa2e61a3361514f$var$getThumbInBoundsOffset(width, left, direction) {
|
|
523
|
+
const halfWidth = width / 2;
|
|
524
|
+
const halfPercent = 50;
|
|
525
|
+
const offset = $faa2e61a3361514f$var$linearScale([
|
|
526
|
+
0,
|
|
527
|
+
halfPercent
|
|
528
|
+
], [
|
|
529
|
+
0,
|
|
530
|
+
halfWidth
|
|
531
|
+
]);
|
|
532
|
+
return (halfWidth - offset(left) * direction) * direction;
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Gets an array of steps between each value.
|
|
536
|
+
*
|
|
537
|
+
* @example
|
|
538
|
+
* // returns [1, 9]
|
|
539
|
+
* getStepsBetweenValues([10, 11, 20]);
|
|
540
|
+
*/ function $faa2e61a3361514f$var$getStepsBetweenValues(values) {
|
|
541
|
+
return values.slice(0, -1).map((value, index)=>values[index + 1] - value
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Verifies the minimum steps between all values is greater than or equal
|
|
546
|
+
* to the expected minimum steps.
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* // returns false
|
|
550
|
+
* hasMinStepsBetweenValues([1,2,3], 2);
|
|
551
|
+
*
|
|
552
|
+
* @example
|
|
553
|
+
* // returns true
|
|
554
|
+
* hasMinStepsBetweenValues([1,2,3], 1);
|
|
555
|
+
*/ function $faa2e61a3361514f$var$hasMinStepsBetweenValues(values, minStepsBetweenValues) {
|
|
556
|
+
if (minStepsBetweenValues > 0) {
|
|
557
|
+
const stepsBetweenValues = $faa2e61a3361514f$var$getStepsBetweenValues(values);
|
|
558
|
+
const actualMinStepsBetweenValues = Math.min(...stepsBetweenValues);
|
|
559
|
+
return actualMinStepsBetweenValues >= minStepsBetweenValues;
|
|
560
|
+
}
|
|
561
|
+
return true;
|
|
562
|
+
} // https://github.com/tmcw-up-for-adoption/simple-linear-scale/blob/master/index.js
|
|
563
|
+
function $faa2e61a3361514f$var$linearScale(input, output) {
|
|
564
|
+
return (value)=>{
|
|
565
|
+
if (input[0] === input[1] || output[0] === output[1]) return output[0];
|
|
566
|
+
const ratio = (output[1] - output[0]) / (input[1] - input[0]);
|
|
567
|
+
return output[0] + ratio * (value - input[0]);
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
function $faa2e61a3361514f$var$getDecimalCount(value) {
|
|
571
|
+
return (String(value).split('.')[1] || '').length;
|
|
572
|
+
}
|
|
573
|
+
function $faa2e61a3361514f$var$roundValue(value, decimalCount) {
|
|
574
|
+
const rounder = Math.pow(10, decimalCount);
|
|
575
|
+
return Math.round(value * rounder) / rounder;
|
|
576
|
+
}
|
|
577
|
+
const $faa2e61a3361514f$export$be92b6f5f03c0fe9 = $faa2e61a3361514f$export$472062a354075cee;
|
|
578
|
+
const $faa2e61a3361514f$export$13921ac0cc260818 = $faa2e61a3361514f$export$105594979f116971;
|
|
579
|
+
const $faa2e61a3361514f$export$9a58ef0d7ad3278c = $faa2e61a3361514f$export$a5cf38a7a000fe77;
|
|
580
|
+
const $faa2e61a3361514f$export$6521433ed15a34db = $faa2e61a3361514f$export$2c1b491743890dec;
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
export {$faa2e61a3361514f$export$ef72632d7b901f97 as createSliderScope, $faa2e61a3361514f$export$472062a354075cee as Slider, $faa2e61a3361514f$export$105594979f116971 as SliderTrack, $faa2e61a3361514f$export$a5cf38a7a000fe77 as SliderRange, $faa2e61a3361514f$export$2c1b491743890dec as SliderThumb, $faa2e61a3361514f$export$be92b6f5f03c0fe9 as Root, $faa2e61a3361514f$export$13921ac0cc260818 as Track, $faa2e61a3361514f$export$9a58ef0d7ad3278c as Range, $faa2e61a3361514f$export$6521433ed15a34db as Thumb};
|
|
2
586
|
//# sourceMappingURL=index.module.js.map
|