@tamagui/slider 1.0.1-beta.151 → 1.0.1-beta.154
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/cjs/Slider.js +330 -308
- package/dist/cjs/Slider.js.map +2 -2
- package/dist/cjs/SliderImpl.js +65 -59
- package/dist/cjs/SliderImpl.js.map +1 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/helpers.js.map +1 -1
- package/dist/esm/Slider.js +326 -307
- package/dist/esm/Slider.js.map +2 -2
- package/dist/esm/SliderImpl.js +61 -58
- package/dist/esm/SliderImpl.js.map +1 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/Slider.js +231 -216
- package/dist/jsx/Slider.js.map +2 -2
- package/dist/jsx/SliderImpl.js +45 -43
- package/dist/jsx/SliderImpl.js.map +1 -1
- package/dist/jsx/constants.js.map +1 -1
- package/dist/jsx/helpers.js.map +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/package.json +8 -8
package/dist/cjs/Slider.js
CHANGED
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
var Slider_exports = {};
|
|
23
26
|
__export(Slider_exports, {
|
|
@@ -33,6 +36,7 @@ __export(Slider_exports, {
|
|
|
33
36
|
Track: () => Track
|
|
34
37
|
});
|
|
35
38
|
module.exports = __toCommonJS(Slider_exports);
|
|
39
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
40
|
var import_compose_refs = require("@tamagui/compose-refs");
|
|
37
41
|
var import_core = require("@tamagui/core");
|
|
38
42
|
var import_helpers = require("@tamagui/helpers");
|
|
@@ -43,109 +47,115 @@ var React = __toESM(require("react"));
|
|
|
43
47
|
var import_constants = require("./constants");
|
|
44
48
|
var import_helpers2 = require("./helpers");
|
|
45
49
|
var import_SliderImpl = require("./SliderImpl");
|
|
46
|
-
const SliderHorizontal = React.forwardRef(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return /* @__PURE__ */ React.createElement(import_constants.SliderOrientationProvider, {
|
|
59
|
-
scope: props.__scopeSlider,
|
|
60
|
-
startEdge: isDirectionLTR ? "left" : "right",
|
|
61
|
-
endEdge: isDirectionLTR ? "right" : "left",
|
|
62
|
-
direction: isDirectionLTR ? 1 : -1,
|
|
63
|
-
sizeProp: "width",
|
|
64
|
-
size: state.size
|
|
65
|
-
}, /* @__PURE__ */ React.createElement(import_SliderImpl.SliderImpl, {
|
|
66
|
-
ref: (0, import_compose_refs.composeRefs)(forwardedRef, sliderRef),
|
|
67
|
-
dir: direction,
|
|
68
|
-
...sliderProps,
|
|
69
|
-
orientation: "horizontal",
|
|
70
|
-
onLayout: () => {
|
|
71
|
-
var _a;
|
|
72
|
-
(_a = sliderRef.current) == null ? void 0 : _a.measure((_x, _y, width, _height, pageX, _pageY) => {
|
|
73
|
-
setState({
|
|
74
|
-
size: width,
|
|
75
|
-
offset: pageX
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
},
|
|
79
|
-
onSlideStart: (event, target) => {
|
|
80
|
-
const value = getValueFromPointer(event.nativeEvent.locationX);
|
|
81
|
-
if (value) {
|
|
82
|
-
onSlideStart == null ? void 0 : onSlideStart(value, target);
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
onSlideMove: (event) => {
|
|
86
|
-
const value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
|
|
87
|
-
if (value) {
|
|
88
|
-
onSlideMove == null ? void 0 : onSlideMove(value);
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
onSlideEnd: () => {
|
|
92
|
-
},
|
|
93
|
-
onStepKeyDown: (event) => {
|
|
94
|
-
const isBackKey = import_constants.BACK_KEYS[direction].includes(event.key);
|
|
95
|
-
onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
|
|
50
|
+
const SliderHorizontal = React.forwardRef(
|
|
51
|
+
(props, forwardedRef) => {
|
|
52
|
+
const { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props;
|
|
53
|
+
const direction = (0, import_use_direction.useDirection)(dir);
|
|
54
|
+
const isDirectionLTR = direction === "ltr";
|
|
55
|
+
const sliderRef = React.useRef(null);
|
|
56
|
+
const [state, setState] = React.useState(() => ({ size: 0, offset: 0 }));
|
|
57
|
+
function getValueFromPointer(pointerPosition) {
|
|
58
|
+
const input = [0, state.size];
|
|
59
|
+
const output = isDirectionLTR ? [min, max] : [max, min];
|
|
60
|
+
const value = (0, import_helpers2.linearScale)(input, output);
|
|
61
|
+
return value(pointerPosition);
|
|
96
62
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
63
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_constants.SliderOrientationProvider, {
|
|
64
|
+
scope: props.__scopeSlider,
|
|
65
|
+
startEdge: isDirectionLTR ? "left" : "right",
|
|
66
|
+
endEdge: isDirectionLTR ? "right" : "left",
|
|
67
|
+
direction: isDirectionLTR ? 1 : -1,
|
|
68
|
+
sizeProp: "width",
|
|
69
|
+
size: state.size,
|
|
70
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SliderImpl.SliderImpl, {
|
|
71
|
+
ref: (0, import_compose_refs.composeRefs)(forwardedRef, sliderRef),
|
|
72
|
+
dir: direction,
|
|
73
|
+
...sliderProps,
|
|
74
|
+
orientation: "horizontal",
|
|
75
|
+
onLayout: () => {
|
|
76
|
+
var _a;
|
|
77
|
+
(_a = sliderRef.current) == null ? void 0 : _a.measure((_x, _y, width, _height, pageX, _pageY) => {
|
|
78
|
+
setState({
|
|
79
|
+
size: width,
|
|
80
|
+
offset: pageX
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
onSlideStart: (event, target) => {
|
|
85
|
+
const value = getValueFromPointer(event.nativeEvent.locationX);
|
|
86
|
+
if (value) {
|
|
87
|
+
onSlideStart == null ? void 0 : onSlideStart(value, target);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
onSlideMove: (event) => {
|
|
91
|
+
const value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
|
|
92
|
+
if (value) {
|
|
93
|
+
onSlideMove == null ? void 0 : onSlideMove(value);
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
onSlideEnd: () => {
|
|
97
|
+
},
|
|
98
|
+
onStepKeyDown: (event) => {
|
|
99
|
+
const isBackKey = import_constants.BACK_KEYS[direction].includes(event.key);
|
|
100
|
+
onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
});
|
|
108
104
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
onLayout: () => {
|
|
121
|
-
var _a;
|
|
122
|
-
(_a = sliderRef.current) == null ? void 0 : _a.measure((_x, _y, _width, height, _pageX, pageY) => {
|
|
123
|
-
setState({
|
|
124
|
-
size: height,
|
|
125
|
-
offset: pageY
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
},
|
|
129
|
-
onSlideStart: (event, target) => {
|
|
130
|
-
const value = getValueFromPointer(event.nativeEvent.locationY);
|
|
131
|
-
if (value) {
|
|
132
|
-
onSlideStart == null ? void 0 : onSlideStart(value, target);
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
onSlideMove: (event) => {
|
|
136
|
-
const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
|
|
137
|
-
if (value) {
|
|
138
|
-
onSlideMove == null ? void 0 : onSlideMove(value);
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
|
-
onSlideEnd: () => {
|
|
142
|
-
},
|
|
143
|
-
onStepKeyDown: (event) => {
|
|
144
|
-
const isBackKey = import_constants.BACK_KEYS.ltr.includes(event.key);
|
|
145
|
-
onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
|
|
105
|
+
);
|
|
106
|
+
const SliderVertical = React.forwardRef(
|
|
107
|
+
(props, forwardedRef) => {
|
|
108
|
+
const { min, max, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props;
|
|
109
|
+
const [state, setState] = React.useState(() => ({ size: 0, offset: 0 }));
|
|
110
|
+
const sliderRef = React.useRef(null);
|
|
111
|
+
function getValueFromPointer(pointerPosition) {
|
|
112
|
+
const input = [0, state.size];
|
|
113
|
+
const output = [max, min];
|
|
114
|
+
const value = (0, import_helpers2.linearScale)(input, output);
|
|
115
|
+
return value(pointerPosition);
|
|
146
116
|
}
|
|
147
|
-
|
|
148
|
-
|
|
117
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_constants.SliderOrientationProvider, {
|
|
118
|
+
scope: props.__scopeSlider,
|
|
119
|
+
startEdge: "bottom",
|
|
120
|
+
endEdge: "top",
|
|
121
|
+
sizeProp: "height",
|
|
122
|
+
size: state.size,
|
|
123
|
+
direction: 1,
|
|
124
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SliderImpl.SliderImpl, {
|
|
125
|
+
ref: (0, import_compose_refs.composeRefs)(forwardedRef, sliderRef),
|
|
126
|
+
...sliderProps,
|
|
127
|
+
orientation: "vertical",
|
|
128
|
+
onLayout: () => {
|
|
129
|
+
var _a;
|
|
130
|
+
(_a = sliderRef.current) == null ? void 0 : _a.measure((_x, _y, _width, height, _pageX, pageY) => {
|
|
131
|
+
setState({
|
|
132
|
+
size: height,
|
|
133
|
+
offset: pageY
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
onSlideStart: (event, target) => {
|
|
138
|
+
const value = getValueFromPointer(event.nativeEvent.locationY);
|
|
139
|
+
if (value) {
|
|
140
|
+
onSlideStart == null ? void 0 : onSlideStart(value, target);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
onSlideMove: (event) => {
|
|
144
|
+
const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
|
|
145
|
+
if (value) {
|
|
146
|
+
onSlideMove == null ? void 0 : onSlideMove(value);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
onSlideEnd: () => {
|
|
150
|
+
},
|
|
151
|
+
onStepKeyDown: (event) => {
|
|
152
|
+
const isBackKey = import_constants.BACK_KEYS.ltr.includes(event.key);
|
|
153
|
+
onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
);
|
|
149
159
|
const TRACK_NAME = "SliderTrack";
|
|
150
160
|
const SliderTrackFrame = (0, import_core.styled)(import_SliderImpl.SliderFrame, {
|
|
151
161
|
name: "SliderTrack",
|
|
@@ -156,18 +166,20 @@ const SliderTrackFrame = (0, import_core.styled)(import_SliderImpl.SliderFrame,
|
|
|
156
166
|
borderRadius: 1e5,
|
|
157
167
|
overflow: "hidden"
|
|
158
168
|
});
|
|
159
|
-
const SliderTrack = React.forwardRef(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
});
|
|
169
|
+
const SliderTrack = React.forwardRef(
|
|
170
|
+
(props, forwardedRef) => {
|
|
171
|
+
const { __scopeSlider, ...trackProps } = props;
|
|
172
|
+
const context = (0, import_constants.useSliderContext)(TRACK_NAME, __scopeSlider);
|
|
173
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SliderTrackFrame, {
|
|
174
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
175
|
+
"data-orientation": context.orientation,
|
|
176
|
+
orientation: context.orientation,
|
|
177
|
+
size: context.size,
|
|
178
|
+
...trackProps,
|
|
179
|
+
ref: forwardedRef
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
);
|
|
171
183
|
SliderTrack.displayName = TRACK_NAME;
|
|
172
184
|
const RANGE_NAME = "SliderTrackActive";
|
|
173
185
|
const SliderTrackActiveFrame = (0, import_core.styled)(import_SliderImpl.SliderFrame, {
|
|
@@ -175,35 +187,39 @@ const SliderTrackActiveFrame = (0, import_core.styled)(import_SliderImpl.SliderF
|
|
|
175
187
|
backgroundColor: "$background",
|
|
176
188
|
position: "absolute"
|
|
177
189
|
});
|
|
178
|
-
const SliderTrackActive = React.forwardRef(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
190
|
+
const SliderTrackActive = React.forwardRef(
|
|
191
|
+
(props, forwardedRef) => {
|
|
192
|
+
const { __scopeSlider, ...rangeProps } = props;
|
|
193
|
+
const context = (0, import_constants.useSliderContext)(RANGE_NAME, __scopeSlider);
|
|
194
|
+
const orientation = (0, import_constants.useSliderOrientationContext)(RANGE_NAME, __scopeSlider);
|
|
195
|
+
const ref = React.useRef(null);
|
|
196
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
197
|
+
const valuesCount = context.values.length;
|
|
198
|
+
const percentages = context.values.map(
|
|
199
|
+
(value) => (0, import_helpers2.convertValueToPercentage)(value, context.min, context.max)
|
|
200
|
+
);
|
|
201
|
+
const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0;
|
|
202
|
+
const offsetEnd = 100 - Math.max(...percentages);
|
|
203
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SliderTrackActiveFrame, {
|
|
204
|
+
orientation: context.orientation,
|
|
205
|
+
"data-orientation": context.orientation,
|
|
206
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
207
|
+
size: context.size,
|
|
208
|
+
...rangeProps,
|
|
209
|
+
ref: composedRefs,
|
|
210
|
+
...{
|
|
211
|
+
[orientation.startEdge]: offsetStart + "%",
|
|
212
|
+
[orientation.endEdge]: offsetEnd + "%"
|
|
213
|
+
},
|
|
214
|
+
...orientation.sizeProp === "width" ? {
|
|
215
|
+
height: "100%"
|
|
216
|
+
} : {
|
|
217
|
+
left: 0,
|
|
218
|
+
right: 0
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
);
|
|
207
223
|
SliderTrackActive.displayName = RANGE_NAME;
|
|
208
224
|
const THUMB_NAME = "SliderThumb";
|
|
209
225
|
const getThumbSize = (val) => {
|
|
@@ -230,178 +246,184 @@ const SliderThumbFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
|
230
246
|
}
|
|
231
247
|
}
|
|
232
248
|
});
|
|
233
|
-
const SliderThumb = React.forwardRef(
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (thumb) {
|
|
249
|
-
context.thumbs.add(thumb);
|
|
250
|
-
return () => {
|
|
251
|
-
context.thumbs.delete(thumb);
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
}, [thumb, context.thumbs]);
|
|
255
|
-
return /* @__PURE__ */ React.createElement(SliderThumbFrame, {
|
|
256
|
-
ref: composedRefs,
|
|
257
|
-
role: "slider",
|
|
258
|
-
"aria-label": props["aria-label"] || label,
|
|
259
|
-
"aria-valuemin": context.min,
|
|
260
|
-
"aria-valuenow": value,
|
|
261
|
-
"aria-valuemax": context.max,
|
|
262
|
-
"aria-orientation": context.orientation,
|
|
263
|
-
"data-orientation": context.orientation,
|
|
264
|
-
"data-disabled": context.disabled ? "" : void 0,
|
|
265
|
-
tabIndex: context.disabled ? void 0 : 0,
|
|
266
|
-
...thumbProps,
|
|
267
|
-
...context.orientation === "horizontal" ? {
|
|
268
|
-
x: thumbInBoundsOffset - size / 2,
|
|
269
|
-
y: -size / 2,
|
|
270
|
-
top: "50%",
|
|
271
|
-
...size === 0 && {
|
|
272
|
-
top: "auto",
|
|
273
|
-
bottom: "auto"
|
|
274
|
-
}
|
|
275
|
-
} : {
|
|
276
|
-
x: -size / 2,
|
|
277
|
-
y: size / 2,
|
|
278
|
-
left: "50%",
|
|
279
|
-
...size === 0 && {
|
|
280
|
-
left: "auto",
|
|
281
|
-
right: "auto"
|
|
282
|
-
}
|
|
283
|
-
},
|
|
284
|
-
size: sizeProp ?? context.size ?? "$4",
|
|
285
|
-
onLayout: (e) => {
|
|
286
|
-
setSize(e.nativeEvent.layout[orientation.sizeProp]);
|
|
287
|
-
},
|
|
288
|
-
...{
|
|
289
|
-
[orientation.startEdge]: `${percent}%`
|
|
290
|
-
},
|
|
291
|
-
onFocus: (0, import_helpers.composeEventHandlers)(props.onFocus, () => {
|
|
292
|
-
context.valueIndexToChangeRef.current = index;
|
|
293
|
-
})
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
SliderThumb.displayName = THUMB_NAME;
|
|
297
|
-
const Slider = (0, import_core.withStaticProperties)(React.forwardRef((props, forwardedRef) => {
|
|
298
|
-
const {
|
|
299
|
-
name,
|
|
300
|
-
min = 0,
|
|
301
|
-
max = 100,
|
|
302
|
-
step = 1,
|
|
303
|
-
orientation = "horizontal",
|
|
304
|
-
disabled = false,
|
|
305
|
-
minStepsBetweenThumbs = 0,
|
|
306
|
-
defaultValue = [min],
|
|
307
|
-
value,
|
|
308
|
-
onValueChange = () => {
|
|
309
|
-
},
|
|
310
|
-
size: sizeProp,
|
|
311
|
-
...sliderProps
|
|
312
|
-
} = props;
|
|
313
|
-
const sliderRef = React.useRef(null);
|
|
314
|
-
const composedRefs = (0, import_compose_refs.useComposedRefs)(sliderRef, forwardedRef);
|
|
315
|
-
const thumbRefs = React.useRef(/* @__PURE__ */ new Set());
|
|
316
|
-
const valueIndexToChangeRef = React.useRef(0);
|
|
317
|
-
const isHorizontal = orientation === "horizontal";
|
|
318
|
-
const [values = [], setValues] = (0, import_use_controllable_state.useControllableState)({
|
|
319
|
-
prop: value,
|
|
320
|
-
defaultProp: defaultValue,
|
|
321
|
-
onChange: (value2) => {
|
|
322
|
-
var _a;
|
|
323
|
-
if (import_core.isWeb) {
|
|
324
|
-
const thumbs = [...thumbRefs.current];
|
|
325
|
-
(_a = thumbs[valueIndexToChangeRef.current]) == null ? void 0 : _a.focus();
|
|
326
|
-
}
|
|
327
|
-
onValueChange(value2);
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
if (import_core.isWeb) {
|
|
249
|
+
const SliderThumb = React.forwardRef(
|
|
250
|
+
(props, forwardedRef) => {
|
|
251
|
+
const { __scopeSlider, index, size: sizeProp, ...thumbProps } = props;
|
|
252
|
+
const context = (0, import_constants.useSliderContext)(THUMB_NAME, __scopeSlider);
|
|
253
|
+
const orientation = (0, import_constants.useSliderOrientationContext)(THUMB_NAME, __scopeSlider);
|
|
254
|
+
const [thumb, setThumb] = React.useState(null);
|
|
255
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, (node) => setThumb(node));
|
|
256
|
+
const value = context.values[index];
|
|
257
|
+
const percent = value === void 0 ? 0 : (0, import_helpers2.convertValueToPercentage)(value, context.min, context.max);
|
|
258
|
+
const label = (0, import_helpers2.getLabel)(index, context.values.length);
|
|
259
|
+
const [size, setSize] = React.useState(() => {
|
|
260
|
+
const estimatedSize = (0, import_core.getVariableValue)(getThumbSize(sizeProp).width);
|
|
261
|
+
return estimatedSize;
|
|
262
|
+
});
|
|
263
|
+
const thumbInBoundsOffset = size ? (0, import_helpers2.getThumbInBoundsOffset)(size, percent, orientation.direction) : 0;
|
|
331
264
|
React.useEffect(() => {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
return
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
};
|
|
338
|
-
node.addEventListener("touchstart", preventDefault);
|
|
339
|
-
return () => {
|
|
340
|
-
node.removeEventListener("touchstart", preventDefault);
|
|
341
|
-
};
|
|
342
|
-
}, []);
|
|
343
|
-
}
|
|
344
|
-
function handleSlideMove(value2) {
|
|
345
|
-
updateValues(value2, valueIndexToChangeRef.current);
|
|
346
|
-
}
|
|
347
|
-
function updateValues(value2, atIndex) {
|
|
348
|
-
const decimalCount = (0, import_helpers2.getDecimalCount)(step);
|
|
349
|
-
const snapToStep = (0, import_helpers2.roundValue)(Math.round((value2 - min) / step) * step + min, decimalCount);
|
|
350
|
-
const nextValue = (0, import_helpers.clamp)(snapToStep, [min, max]);
|
|
351
|
-
setValues((prevValues = []) => {
|
|
352
|
-
const nextValues = (0, import_helpers2.getNextSortedValues)(prevValues, nextValue, atIndex);
|
|
353
|
-
if ((0, import_helpers2.hasMinStepsBetweenValues)(nextValues, minStepsBetweenThumbs * step)) {
|
|
354
|
-
valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
|
|
355
|
-
return String(nextValues) === String(prevValues) ? prevValues : nextValues;
|
|
356
|
-
} else {
|
|
357
|
-
return prevValues;
|
|
265
|
+
if (thumb) {
|
|
266
|
+
context.thumbs.add(thumb);
|
|
267
|
+
return () => {
|
|
268
|
+
context.thumbs.delete(thumb);
|
|
269
|
+
};
|
|
358
270
|
}
|
|
271
|
+
}, [thumb, context.thumbs]);
|
|
272
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SliderThumbFrame, {
|
|
273
|
+
ref: composedRefs,
|
|
274
|
+
role: "slider",
|
|
275
|
+
"aria-label": props["aria-label"] || label,
|
|
276
|
+
"aria-valuemin": context.min,
|
|
277
|
+
"aria-valuenow": value,
|
|
278
|
+
"aria-valuemax": context.max,
|
|
279
|
+
"aria-orientation": context.orientation,
|
|
280
|
+
"data-orientation": context.orientation,
|
|
281
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
282
|
+
tabIndex: context.disabled ? void 0 : 0,
|
|
283
|
+
...thumbProps,
|
|
284
|
+
...context.orientation === "horizontal" ? {
|
|
285
|
+
x: thumbInBoundsOffset - size / 2,
|
|
286
|
+
y: -size / 2,
|
|
287
|
+
top: "50%",
|
|
288
|
+
...size === 0 && {
|
|
289
|
+
top: "auto",
|
|
290
|
+
bottom: "auto"
|
|
291
|
+
}
|
|
292
|
+
} : {
|
|
293
|
+
x: -size / 2,
|
|
294
|
+
y: size / 2,
|
|
295
|
+
left: "50%",
|
|
296
|
+
...size === 0 && {
|
|
297
|
+
left: "auto",
|
|
298
|
+
right: "auto"
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
size: sizeProp ?? context.size ?? "$4",
|
|
302
|
+
onLayout: (e) => {
|
|
303
|
+
setSize(e.nativeEvent.layout[orientation.sizeProp]);
|
|
304
|
+
},
|
|
305
|
+
...{
|
|
306
|
+
[orientation.startEdge]: `${percent}%`
|
|
307
|
+
},
|
|
308
|
+
onFocus: (0, import_helpers.composeEventHandlers)(props.onFocus, () => {
|
|
309
|
+
context.valueIndexToChangeRef.current = index;
|
|
310
|
+
})
|
|
359
311
|
});
|
|
360
312
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const stepInDirection = step * multiplier * stepDirection;
|
|
396
|
-
updateValues(value2 + stepInDirection, atIndex);
|
|
313
|
+
);
|
|
314
|
+
SliderThumb.displayName = THUMB_NAME;
|
|
315
|
+
const Slider = (0, import_core.withStaticProperties)(
|
|
316
|
+
React.forwardRef((props, forwardedRef) => {
|
|
317
|
+
const {
|
|
318
|
+
name,
|
|
319
|
+
min = 0,
|
|
320
|
+
max = 100,
|
|
321
|
+
step = 1,
|
|
322
|
+
orientation = "horizontal",
|
|
323
|
+
disabled = false,
|
|
324
|
+
minStepsBetweenThumbs = 0,
|
|
325
|
+
defaultValue = [min],
|
|
326
|
+
value,
|
|
327
|
+
onValueChange = () => {
|
|
328
|
+
},
|
|
329
|
+
size: sizeProp,
|
|
330
|
+
...sliderProps
|
|
331
|
+
} = props;
|
|
332
|
+
const sliderRef = React.useRef(null);
|
|
333
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(sliderRef, forwardedRef);
|
|
334
|
+
const thumbRefs = React.useRef(/* @__PURE__ */ new Set());
|
|
335
|
+
const valueIndexToChangeRef = React.useRef(0);
|
|
336
|
+
const isHorizontal = orientation === "horizontal";
|
|
337
|
+
const [values = [], setValues] = (0, import_use_controllable_state.useControllableState)({
|
|
338
|
+
prop: value,
|
|
339
|
+
defaultProp: defaultValue,
|
|
340
|
+
onChange: (value2) => {
|
|
341
|
+
var _a;
|
|
342
|
+
if (import_core.isWeb) {
|
|
343
|
+
const thumbs = [...thumbRefs.current];
|
|
344
|
+
(_a = thumbs[valueIndexToChangeRef.current]) == null ? void 0 : _a.focus();
|
|
345
|
+
}
|
|
346
|
+
onValueChange(value2);
|
|
397
347
|
}
|
|
348
|
+
});
|
|
349
|
+
if (import_core.isWeb) {
|
|
350
|
+
React.useEffect(() => {
|
|
351
|
+
const node = sliderRef.current;
|
|
352
|
+
if (!node)
|
|
353
|
+
return;
|
|
354
|
+
const preventDefault = (e) => {
|
|
355
|
+
e.preventDefault();
|
|
356
|
+
};
|
|
357
|
+
node.addEventListener("touchstart", preventDefault);
|
|
358
|
+
return () => {
|
|
359
|
+
node.removeEventListener("touchstart", preventDefault);
|
|
360
|
+
};
|
|
361
|
+
}, []);
|
|
398
362
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
363
|
+
function handleSlideMove(value2) {
|
|
364
|
+
updateValues(value2, valueIndexToChangeRef.current);
|
|
365
|
+
}
|
|
366
|
+
function updateValues(value2, atIndex) {
|
|
367
|
+
const decimalCount = (0, import_helpers2.getDecimalCount)(step);
|
|
368
|
+
const snapToStep = (0, import_helpers2.roundValue)(Math.round((value2 - min) / step) * step + min, decimalCount);
|
|
369
|
+
const nextValue = (0, import_helpers.clamp)(snapToStep, [min, max]);
|
|
370
|
+
setValues((prevValues = []) => {
|
|
371
|
+
const nextValues = (0, import_helpers2.getNextSortedValues)(prevValues, nextValue, atIndex);
|
|
372
|
+
if ((0, import_helpers2.hasMinStepsBetweenValues)(nextValues, minStepsBetweenThumbs * step)) {
|
|
373
|
+
valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
|
|
374
|
+
return String(nextValues) === String(prevValues) ? prevValues : nextValues;
|
|
375
|
+
} else {
|
|
376
|
+
return prevValues;
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
|
|
381
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_constants.SliderProvider, {
|
|
382
|
+
scope: props.__scopeSlider,
|
|
383
|
+
disabled,
|
|
384
|
+
min,
|
|
385
|
+
max,
|
|
386
|
+
valueIndexToChangeRef,
|
|
387
|
+
thumbs: thumbRefs.current,
|
|
388
|
+
values,
|
|
389
|
+
orientation,
|
|
390
|
+
size: sizeProp,
|
|
391
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SliderOriented, {
|
|
392
|
+
"aria-disabled": disabled,
|
|
393
|
+
"data-disabled": disabled ? "" : void 0,
|
|
394
|
+
...sliderProps,
|
|
395
|
+
ref: composedRefs,
|
|
396
|
+
min,
|
|
397
|
+
max,
|
|
398
|
+
onSlideStart: disabled ? void 0 : (value2, target) => {
|
|
399
|
+
if (target !== "thumb") {
|
|
400
|
+
const closestIndex = (0, import_helpers2.getClosestValueIndex)(values, value2);
|
|
401
|
+
updateValues(value2, closestIndex);
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
onSlideMove: disabled ? void 0 : handleSlideMove,
|
|
405
|
+
onHomeKeyDown: () => !disabled && updateValues(min, 0),
|
|
406
|
+
onEndKeyDown: () => !disabled && updateValues(max, values.length - 1),
|
|
407
|
+
onStepKeyDown: ({ event, direction: stepDirection }) => {
|
|
408
|
+
if (!disabled) {
|
|
409
|
+
const isPageKey = import_constants.PAGE_KEYS.includes(event.key);
|
|
410
|
+
const isSkipKey = isPageKey || event.shiftKey && import_constants.ARROW_KEYS.includes(event.key);
|
|
411
|
+
const multiplier = isSkipKey ? 10 : 1;
|
|
412
|
+
const atIndex = valueIndexToChangeRef.current;
|
|
413
|
+
const value2 = values[atIndex];
|
|
414
|
+
const stepInDirection = step * multiplier * stepDirection;
|
|
415
|
+
updateValues(value2 + stepInDirection, atIndex);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
})
|
|
419
|
+
});
|
|
420
|
+
}),
|
|
421
|
+
{
|
|
422
|
+
Track: SliderTrack,
|
|
423
|
+
TrackActive: SliderTrackActive,
|
|
424
|
+
Thumb: SliderThumb
|
|
425
|
+
}
|
|
426
|
+
);
|
|
405
427
|
Slider.displayName = import_constants.SLIDER_NAME;
|
|
406
428
|
const Track = SliderTrack;
|
|
407
429
|
const Range = SliderTrackActive;
|