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