@tamagui/slider 1.0.1-beta.26 → 1.0.1-beta.27
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 +107 -85
- package/dist/cjs/Slider.js.map +2 -2
- package/dist/cjs/SliderImpl.js +29 -9
- package/dist/cjs/SliderImpl.js.map +2 -2
- package/dist/cjs/constants.js +62 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/index.js +18 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/Slider.js +92 -66
- package/dist/esm/Slider.js.map +2 -2
- package/dist/esm/SliderImpl.js +27 -7
- package/dist/esm/SliderImpl.js.map +2 -2
- package/dist/esm/constants.js +30 -0
- package/dist/esm/constants.js.map +7 -0
- package/dist/esm/index.js +7 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/Slider.js +84 -58
- package/dist/jsx/SliderImpl.js +27 -8
- package/dist/jsx/constants.js +29 -0
- package/dist/jsx/index.js +7 -1
- package/package.json +8 -8
- package/types/Slider.d.ts.map +1 -1
- package/types/SliderImpl.d.ts.map +1 -1
- package/types/constants.d.ts +53 -0
- package/types/constants.d.ts.map +1 -0
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +3 -3
- package/types/types.d.ts.map +1 -1
package/dist/cjs/Slider.js
CHANGED
|
@@ -59,7 +59,6 @@ __export(Slider_exports, {
|
|
|
59
59
|
Track: () => Track
|
|
60
60
|
});
|
|
61
61
|
module.exports = __toCommonJS(Slider_exports);
|
|
62
|
-
var import_react_use_previous = require("@radix-ui/react-use-previous");
|
|
63
62
|
var import_compose_refs = require("@tamagui/compose-refs");
|
|
64
63
|
var import_core = require("@tamagui/core");
|
|
65
64
|
var import_helpers = require("@tamagui/helpers");
|
|
@@ -67,20 +66,14 @@ var import_stacks = require("@tamagui/stacks");
|
|
|
67
66
|
var import_use_controllable_state = require("@tamagui/use-controllable-state");
|
|
68
67
|
var import_use_direction = require("@tamagui/use-direction");
|
|
69
68
|
var React = __toESM(require("react"));
|
|
70
|
-
var
|
|
69
|
+
var import_constants = require("./constants");
|
|
71
70
|
var import_helpers2 = require("./helpers");
|
|
72
71
|
var import_SliderImpl = require("./SliderImpl");
|
|
73
|
-
const PAGE_KEYS = ["PageUp", "PageDown"];
|
|
74
|
-
const ARROW_KEYS = ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"];
|
|
75
|
-
const BACK_KEYS = {
|
|
76
|
-
ltr: ["ArrowDown", "Home", "ArrowLeft", "PageDown"],
|
|
77
|
-
rtl: ["ArrowDown", "Home", "ArrowRight", "PageDown"]
|
|
78
|
-
};
|
|
79
72
|
const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
|
|
80
73
|
const _a = props, { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown } = _a, sliderProps = __objRest(_a, ["min", "max", "dir", "onSlideStart", "onSlideMove", "onStepKeyDown"]);
|
|
81
|
-
const layoutRef = React.useRef(null);
|
|
82
74
|
const direction = (0, import_use_direction.useDirection)(dir);
|
|
83
75
|
const isDirectionLTR = direction === "ltr";
|
|
76
|
+
const layoutRef = React.useRef(null);
|
|
84
77
|
const [size, setSize] = React.useState(0);
|
|
85
78
|
function getValueFromPointer(pointerPosition) {
|
|
86
79
|
const layout = layoutRef.current;
|
|
@@ -89,10 +82,10 @@ const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
|
|
|
89
82
|
const input = [0, layout.width];
|
|
90
83
|
const output = isDirectionLTR ? [min, max] : [max, min];
|
|
91
84
|
const value = (0, import_helpers2.linearScale)(input, output);
|
|
92
|
-
return value(pointerPosition
|
|
85
|
+
return value(pointerPosition);
|
|
93
86
|
}
|
|
94
87
|
__name(getValueFromPointer, "getValueFromPointer");
|
|
95
|
-
return /* @__PURE__ */ React.createElement(
|
|
88
|
+
return /* @__PURE__ */ React.createElement(import_constants.SliderOrientationProvider, {
|
|
96
89
|
scope: props.__scopeSlider,
|
|
97
90
|
startEdge: isDirectionLTR ? "left" : "right",
|
|
98
91
|
endEdge: isDirectionLTR ? "right" : "left",
|
|
@@ -100,23 +93,23 @@ const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
|
|
|
100
93
|
sizeProp: "width",
|
|
101
94
|
size
|
|
102
95
|
}, /* @__PURE__ */ React.createElement(import_SliderImpl.SliderImpl, __spreadProps(__spreadValues({
|
|
103
|
-
|
|
104
|
-
|
|
96
|
+
ref: forwardedRef,
|
|
97
|
+
dir: direction
|
|
105
98
|
}, sliderProps), {
|
|
99
|
+
orientation: "horizontal",
|
|
106
100
|
onLayout: (e) => {
|
|
107
101
|
const layout = e.nativeEvent.layout;
|
|
108
102
|
layoutRef.current = layout;
|
|
109
103
|
setSize(layout.height);
|
|
110
104
|
},
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const value = getValueFromPointer(event.nativeEvent.pageX);
|
|
105
|
+
onSlideStart: (event, target) => {
|
|
106
|
+
const value = getValueFromPointer(event.nativeEvent.locationX);
|
|
114
107
|
if (value) {
|
|
115
|
-
onSlideStart == null ? void 0 : onSlideStart(value);
|
|
108
|
+
onSlideStart == null ? void 0 : onSlideStart(value, target);
|
|
116
109
|
}
|
|
117
110
|
},
|
|
118
111
|
onSlideMove: (event) => {
|
|
119
|
-
const value = getValueFromPointer(event.nativeEvent.
|
|
112
|
+
const value = getValueFromPointer(event.nativeEvent.locationX);
|
|
120
113
|
if (value) {
|
|
121
114
|
onSlideMove == null ? void 0 : onSlideMove(value);
|
|
122
115
|
}
|
|
@@ -124,61 +117,78 @@ const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
|
|
|
124
117
|
onSlideEnd: () => {
|
|
125
118
|
},
|
|
126
119
|
onStepKeyDown: (event) => {
|
|
127
|
-
const isBackKey = BACK_KEYS[direction].includes(event.key);
|
|
120
|
+
const isBackKey = import_constants.BACK_KEYS[direction].includes(event.key);
|
|
128
121
|
onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
|
|
129
122
|
}
|
|
130
123
|
})));
|
|
131
124
|
});
|
|
132
125
|
const SliderVertical = React.forwardRef((props, forwardedRef) => {
|
|
133
126
|
const _a = props, { min, max, onSlideStart, onSlideMove, onStepKeyDown } = _a, sliderProps = __objRest(_a, ["min", "max", "onSlideStart", "onSlideMove", "onStepKeyDown"]);
|
|
134
|
-
const
|
|
135
|
-
const
|
|
136
|
-
const rectRef = React.useRef();
|
|
127
|
+
const layoutRef = React.useRef(null);
|
|
128
|
+
const [size, setSize] = React.useState(0);
|
|
137
129
|
function getValueFromPointer(pointerPosition) {
|
|
138
|
-
const
|
|
139
|
-
|
|
130
|
+
const layout = layoutRef.current;
|
|
131
|
+
if (!layout)
|
|
132
|
+
return;
|
|
133
|
+
const input = [0, layout.height];
|
|
140
134
|
const output = [max, min];
|
|
141
135
|
const value = (0, import_helpers2.linearScale)(input, output);
|
|
142
|
-
|
|
143
|
-
return value(pointerPosition - rect.top);
|
|
136
|
+
return value(pointerPosition);
|
|
144
137
|
}
|
|
145
138
|
__name(getValueFromPointer, "getValueFromPointer");
|
|
146
|
-
return /* @__PURE__ */ React.createElement(
|
|
139
|
+
return /* @__PURE__ */ React.createElement(import_constants.SliderOrientationProvider, {
|
|
147
140
|
scope: props.__scopeSlider,
|
|
148
141
|
startEdge: "bottom",
|
|
149
142
|
endEdge: "top",
|
|
150
143
|
sizeProp: "height",
|
|
151
|
-
size
|
|
144
|
+
size,
|
|
152
145
|
direction: 1
|
|
153
|
-
}, /* @__PURE__ */ React.createElement(import_SliderImpl.SliderImpl, __spreadProps(__spreadValues({
|
|
146
|
+
}, /* @__PURE__ */ React.createElement(import_SliderImpl.SliderImpl, __spreadProps(__spreadValues({
|
|
147
|
+
ref: forwardedRef
|
|
148
|
+
}, sliderProps), {
|
|
154
149
|
orientation: "vertical",
|
|
155
|
-
|
|
156
|
-
|
|
150
|
+
onLayout: (e) => {
|
|
151
|
+
const layout = e.nativeEvent.layout;
|
|
152
|
+
layoutRef.current = layout;
|
|
153
|
+
setSize(layout.height);
|
|
154
|
+
},
|
|
155
|
+
onSlideStart: (event, target) => {
|
|
157
156
|
const value = getValueFromPointer(event.nativeEvent.locationY);
|
|
158
|
-
|
|
157
|
+
if (value) {
|
|
158
|
+
onSlideStart == null ? void 0 : onSlideStart(value, target);
|
|
159
|
+
}
|
|
159
160
|
},
|
|
160
161
|
onSlideMove: (event) => {
|
|
161
162
|
const value = getValueFromPointer(event.nativeEvent.locationY);
|
|
162
|
-
|
|
163
|
+
if (value) {
|
|
164
|
+
onSlideMove == null ? void 0 : onSlideMove(value);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
onSlideEnd: () => {
|
|
163
168
|
},
|
|
164
|
-
onSlideEnd: () => rectRef.current = void 0,
|
|
165
169
|
onStepKeyDown: (event) => {
|
|
166
|
-
const isBackKey = BACK_KEYS.ltr.includes(event.key);
|
|
170
|
+
const isBackKey = import_constants.BACK_KEYS.ltr.includes(event.key);
|
|
167
171
|
onStepKeyDown == null ? void 0 : onStepKeyDown({ event, direction: isBackKey ? -1 : 1 });
|
|
168
172
|
}
|
|
169
173
|
})));
|
|
170
174
|
});
|
|
171
175
|
const TRACK_NAME = "SliderTrack";
|
|
172
176
|
const SliderTrackFrame = (0, import_core.styled)(import_SliderImpl.SliderFrame, {
|
|
173
|
-
name: "
|
|
177
|
+
name: "SliderTrack",
|
|
178
|
+
height: "100%",
|
|
179
|
+
width: "100%",
|
|
180
|
+
backgroundColor: "$background",
|
|
181
|
+
position: "relative",
|
|
182
|
+
borderRadius: 1e5
|
|
174
183
|
});
|
|
175
184
|
const SliderTrack = React.forwardRef((props, forwardedRef) => {
|
|
176
185
|
const _a = props, { __scopeSlider } = _a, trackProps = __objRest(_a, ["__scopeSlider"]);
|
|
177
|
-
const context = (0,
|
|
186
|
+
const context = (0, import_constants.useSliderContext)(TRACK_NAME, __scopeSlider);
|
|
178
187
|
return /* @__PURE__ */ React.createElement(SliderTrackFrame, __spreadProps(__spreadValues({
|
|
179
188
|
"data-disabled": context.disabled ? "" : void 0,
|
|
180
189
|
"data-orientation": context.orientation,
|
|
181
|
-
orientation: context.orientation
|
|
190
|
+
orientation: context.orientation,
|
|
191
|
+
size: context.size
|
|
182
192
|
}, trackProps), {
|
|
183
193
|
ref: forwardedRef
|
|
184
194
|
}));
|
|
@@ -186,57 +196,87 @@ const SliderTrack = React.forwardRef((props, forwardedRef) => {
|
|
|
186
196
|
SliderTrack.displayName = TRACK_NAME;
|
|
187
197
|
const RANGE_NAME = "SliderTrackActive";
|
|
188
198
|
const SliderTrackActiveFrame = (0, import_core.styled)(import_SliderImpl.SliderFrame, {
|
|
189
|
-
name: "SliderTrackActive"
|
|
199
|
+
name: "SliderTrackActive",
|
|
200
|
+
backgroundColor: "$background",
|
|
201
|
+
position: "absolute"
|
|
190
202
|
});
|
|
191
203
|
const SliderTrackActive = React.forwardRef((props, forwardedRef) => {
|
|
192
204
|
const _a = props, { __scopeSlider } = _a, rangeProps = __objRest(_a, ["__scopeSlider"]);
|
|
193
|
-
const context = (0,
|
|
194
|
-
const orientation = (0,
|
|
205
|
+
const context = (0, import_constants.useSliderContext)(RANGE_NAME, __scopeSlider);
|
|
206
|
+
const orientation = (0, import_constants.useSliderOrientationContext)(RANGE_NAME, __scopeSlider);
|
|
195
207
|
const ref = React.useRef(null);
|
|
196
208
|
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref);
|
|
197
209
|
const valuesCount = context.values.length;
|
|
198
210
|
const percentages = context.values.map((value) => (0, import_helpers2.convertValueToPercentage)(value, context.min, context.max));
|
|
199
211
|
const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0;
|
|
200
212
|
const offsetEnd = 100 - Math.max(...percentages);
|
|
201
|
-
return /* @__PURE__ */ React.createElement(SliderTrackActiveFrame, __spreadValues(__spreadProps(__spreadValues({
|
|
213
|
+
return /* @__PURE__ */ React.createElement(SliderTrackActiveFrame, __spreadValues(__spreadValues(__spreadProps(__spreadValues({
|
|
202
214
|
orientation: context.orientation,
|
|
203
215
|
"data-orientation": context.orientation,
|
|
204
|
-
"data-disabled": context.disabled ? "" : void 0
|
|
216
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
217
|
+
size: context.size
|
|
205
218
|
}, rangeProps), {
|
|
206
219
|
ref: composedRefs
|
|
207
220
|
}), {
|
|
208
221
|
[orientation.startEdge]: offsetStart + "%",
|
|
209
222
|
[orientation.endEdge]: offsetEnd + "%"
|
|
223
|
+
}), orientation.sizeProp === "width" ? {
|
|
224
|
+
height: "100%"
|
|
225
|
+
} : {
|
|
226
|
+
left: 0,
|
|
227
|
+
right: 0
|
|
210
228
|
}));
|
|
211
229
|
});
|
|
212
230
|
SliderTrackActive.displayName = RANGE_NAME;
|
|
213
231
|
const THUMB_NAME = "SliderThumb";
|
|
214
|
-
const SliderThumbFrame = (0, import_core.styled)(import_stacks.
|
|
232
|
+
const SliderThumbFrame = (0, import_core.styled)(import_stacks.ThemeableSizableStack, {
|
|
215
233
|
name: "SliderThumb",
|
|
216
|
-
position: "absolute"
|
|
234
|
+
position: "absolute",
|
|
235
|
+
bordered: 2,
|
|
236
|
+
borderWidth: 2,
|
|
237
|
+
pressable: true,
|
|
238
|
+
focusable: true,
|
|
239
|
+
hoverable: true
|
|
217
240
|
});
|
|
218
241
|
const SliderThumb = React.forwardRef((props, forwardedRef) => {
|
|
219
242
|
const _a = props, { __scopeSlider, index, size: sizeProp } = _a, thumbProps = __objRest(_a, ["__scopeSlider", "index", "size"]);
|
|
220
|
-
const context = (0,
|
|
221
|
-
const orientation = (0,
|
|
243
|
+
const context = (0, import_constants.useSliderContext)(THUMB_NAME, __scopeSlider);
|
|
244
|
+
const orientation = (0, import_constants.useSliderOrientationContext)(THUMB_NAME, __scopeSlider);
|
|
245
|
+
const [thumb, setThumb] = React.useState(null);
|
|
246
|
+
const composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, (node) => setThumb(node));
|
|
222
247
|
const value = context.values[index];
|
|
223
248
|
const percent = value === void 0 ? 0 : (0, import_helpers2.convertValueToPercentage)(value, context.min, context.max);
|
|
224
249
|
const label = (0, import_helpers2.getLabel)(index, context.values.length);
|
|
225
250
|
const [size, setSize] = React.useState(0);
|
|
226
251
|
const thumbInBoundsOffset = size ? (0, import_helpers2.getThumbInBoundsOffset)(size, percent, orientation.direction) : 0;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
252
|
+
React.useEffect(() => {
|
|
253
|
+
if (thumb) {
|
|
254
|
+
context.thumbs.add(thumb);
|
|
255
|
+
return () => {
|
|
256
|
+
context.thumbs.delete(thumb);
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}, [thumb, context.thumbs]);
|
|
260
|
+
return /* @__PURE__ */ React.createElement(SliderThumbFrame, __spreadProps(__spreadValues(__spreadProps(__spreadValues(__spreadValues({
|
|
261
|
+
ref: composedRefs,
|
|
262
|
+
role: "slider",
|
|
230
263
|
"aria-label": props["aria-label"] || label,
|
|
231
264
|
"aria-valuemin": context.min,
|
|
232
265
|
"aria-valuenow": value,
|
|
233
266
|
"aria-valuemax": context.max,
|
|
234
267
|
"aria-orientation": context.orientation,
|
|
235
268
|
"data-orientation": context.orientation,
|
|
236
|
-
"data-disabled": context.disabled ? "" : void 0
|
|
237
|
-
|
|
238
|
-
|
|
269
|
+
"data-disabled": context.disabled ? "" : void 0,
|
|
270
|
+
tabIndex: context.disabled ? void 0 : 0
|
|
271
|
+
}, thumbProps), context.orientation === "horizontal" ? {
|
|
272
|
+
x: thumbInBoundsOffset - size / 2,
|
|
239
273
|
y: -size / 2,
|
|
274
|
+
top: "50%"
|
|
275
|
+
} : {
|
|
276
|
+
x: -size / 2,
|
|
277
|
+
y: size / 2,
|
|
278
|
+
left: "50%"
|
|
279
|
+
}), {
|
|
240
280
|
size: sizeProp ?? context.size ?? 30,
|
|
241
281
|
onLayout: (e) => {
|
|
242
282
|
setSize(e.nativeEvent.layout[orientation.sizeProp]);
|
|
@@ -285,14 +325,12 @@ const Slider = (0, import_core.withStaticProperties)(React.forwardRef((props, fo
|
|
|
285
325
|
prop: value,
|
|
286
326
|
defaultProp: defaultValue,
|
|
287
327
|
onChange: (value2) => {
|
|
328
|
+
var _a2;
|
|
329
|
+
const thumbs = [...thumbRefs.current];
|
|
330
|
+
(_a2 = thumbs[valueIndexToChangeRef.current]) == null ? void 0 : _a2.focus();
|
|
288
331
|
onValueChange(value2);
|
|
289
332
|
}
|
|
290
333
|
});
|
|
291
|
-
function handleSlideStart(value2) {
|
|
292
|
-
const closestIndex = (0, import_helpers2.getClosestValueIndex)(values, value2);
|
|
293
|
-
updateValues(value2, closestIndex);
|
|
294
|
-
}
|
|
295
|
-
__name(handleSlideStart, "handleSlideStart");
|
|
296
334
|
function handleSlideMove(value2) {
|
|
297
335
|
updateValues(value2, valueIndexToChangeRef.current);
|
|
298
336
|
}
|
|
@@ -313,7 +351,7 @@ const Slider = (0, import_core.withStaticProperties)(React.forwardRef((props, fo
|
|
|
313
351
|
}
|
|
314
352
|
__name(updateValues, "updateValues");
|
|
315
353
|
const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
|
|
316
|
-
return /* @__PURE__ */ React.createElement(
|
|
354
|
+
return /* @__PURE__ */ React.createElement(import_constants.SliderProvider, {
|
|
317
355
|
scope: props.__scopeSlider,
|
|
318
356
|
disabled,
|
|
319
357
|
min,
|
|
@@ -330,14 +368,20 @@ const Slider = (0, import_core.withStaticProperties)(React.forwardRef((props, fo
|
|
|
330
368
|
ref: forwardedRef,
|
|
331
369
|
min,
|
|
332
370
|
max,
|
|
333
|
-
onSlideStart: disabled ? void 0 :
|
|
371
|
+
onSlideStart: disabled ? void 0 : (value2, target) => {
|
|
372
|
+
console.log("target", target);
|
|
373
|
+
if (target !== "thumb") {
|
|
374
|
+
const closestIndex = (0, import_helpers2.getClosestValueIndex)(values, value2);
|
|
375
|
+
updateValues(value2, closestIndex);
|
|
376
|
+
}
|
|
377
|
+
},
|
|
334
378
|
onSlideMove: disabled ? void 0 : handleSlideMove,
|
|
335
379
|
onHomeKeyDown: () => !disabled && updateValues(min, 0),
|
|
336
380
|
onEndKeyDown: () => !disabled && updateValues(max, values.length - 1),
|
|
337
381
|
onStepKeyDown: ({ event, direction: stepDirection }) => {
|
|
338
382
|
if (!disabled) {
|
|
339
|
-
const isPageKey = PAGE_KEYS.includes(event.key);
|
|
340
|
-
const isSkipKey = isPageKey || event.shiftKey && ARROW_KEYS.includes(event.key);
|
|
383
|
+
const isPageKey = import_constants.PAGE_KEYS.includes(event.key);
|
|
384
|
+
const isSkipKey = isPageKey || event.shiftKey && import_constants.ARROW_KEYS.includes(event.key);
|
|
341
385
|
const multiplier = isSkipKey ? 10 : 1;
|
|
342
386
|
const atIndex = valueIndexToChangeRef.current;
|
|
343
387
|
const value2 = values[atIndex];
|
|
@@ -351,29 +395,7 @@ const Slider = (0, import_core.withStaticProperties)(React.forwardRef((props, fo
|
|
|
351
395
|
TrackActive: SliderTrackActive,
|
|
352
396
|
Thumb: SliderThumb
|
|
353
397
|
});
|
|
354
|
-
Slider.displayName =
|
|
355
|
-
const BubbleInput = /* @__PURE__ */ __name((props) => {
|
|
356
|
-
const _a = props, { value } = _a, inputProps = __objRest(_a, ["value"]);
|
|
357
|
-
const ref = React.useRef(null);
|
|
358
|
-
const prevValue = (0, import_react_use_previous.usePrevious)(value);
|
|
359
|
-
React.useEffect(() => {
|
|
360
|
-
const input = ref.current;
|
|
361
|
-
const inputProto = window.HTMLInputElement.prototype;
|
|
362
|
-
const descriptor = Object.getOwnPropertyDescriptor(inputProto, "value");
|
|
363
|
-
const setValue = descriptor.set;
|
|
364
|
-
if (prevValue !== value && setValue) {
|
|
365
|
-
const event = new Event("input", { bubbles: true });
|
|
366
|
-
setValue.call(input, value);
|
|
367
|
-
input.dispatchEvent(event);
|
|
368
|
-
}
|
|
369
|
-
}, [prevValue, value]);
|
|
370
|
-
return /* @__PURE__ */ React.createElement("input", __spreadProps(__spreadValues({
|
|
371
|
-
style: { display: "none" }
|
|
372
|
-
}, inputProps), {
|
|
373
|
-
ref,
|
|
374
|
-
defaultValue: value
|
|
375
|
-
}));
|
|
376
|
-
}, "BubbleInput");
|
|
398
|
+
Slider.displayName = import_constants.SLIDER_NAME;
|
|
377
399
|
const Track = SliderTrack;
|
|
378
400
|
const Range = SliderTrackActive;
|
|
379
401
|
const Thumb = SliderThumb;
|
package/dist/cjs/Slider.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Slider.tsx"],
|
|
4
|
-
"sourcesContent": ["// forked from radix-ui\n\nimport { usePrevious } from '@radix-ui/react-use-previous'\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport { getVariantExtras, styled, withStaticProperties } from '@tamagui/core'\nimport { clamp, composeEventHandlers } from '@tamagui/helpers'\n// import { useSize } from '@tamagui/react-use-size'\nimport { SizableStack, SizableStackProps, YStackProps, getCircleSize } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport { useDirection } from '@tamagui/use-direction'\nimport * as React from 'react'\nimport { LayoutRectangle, View } from 'react-native'\n\nimport {\n SLIDER_NAME,\n SliderOrientationProvider,\n SliderProvider,\n useSliderContext,\n useSliderOrientationContext,\n} from './context'\nimport {\n convertValueToPercentage,\n getClosestValueIndex,\n getDecimalCount,\n getLabel,\n getNextSortedValues,\n getSize,\n getThumbInBoundsOffset,\n hasMinStepsBetweenValues,\n linearScale,\n roundValue,\n} from './helpers'\nimport { SliderFrame, SliderImpl } from './SliderImpl'\nimport {\n Direction,\n ScopedProps,\n SliderContextValue,\n SliderHorizontalProps,\n SliderImplElement,\n SliderProps,\n SliderTrackProps,\n SliderVerticalProps,\n} from './types'\n\nconst PAGE_KEYS = ['PageUp', 'PageDown']\nconst ARROW_KEYS = ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight']\nconst BACK_KEYS: Record<Direction, string[]> = {\n ltr: ['ArrowDown', 'Home', 'ArrowLeft', 'PageDown'],\n rtl: ['ArrowDown', 'Home', 'ArrowRight', 'PageDown'],\n}\n\n/* -------------------------------------------------------------------------------------------------\n * SliderHorizontal\n * -----------------------------------------------------------------------------------------------*/\n\ntype SliderHorizontalElement = SliderImplElement\n\nconst SliderHorizontal = React.forwardRef<SliderHorizontalElement, SliderHorizontalProps>(\n (props: ScopedProps<SliderHorizontalProps>, forwardedRef) => {\n const { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props\n const layoutRef = React.useRef<LayoutRectangle | null>(null)\n const direction = useDirection(dir)\n const isDirectionLTR = direction === 'ltr'\n const [size, setSize] = React.useState(0)\n\n function getValueFromPointer(pointerPosition: number) {\n const layout = layoutRef.current\n if (!layout) return\n const input: [number, number] = [0, layout.width]\n const output: [number, number] = isDirectionLTR ? [min, max] : [max, min]\n const value = linearScale(input, output)\n return value(pointerPosition - layout.x)\n }\n\n return (\n <SliderOrientationProvider\n scope={props.__scopeSlider}\n startEdge={isDirectionLTR ? 'left' : 'right'}\n endEdge={isDirectionLTR ? 'right' : 'left'}\n direction={isDirectionLTR ? 1 : -1}\n sizeProp=\"width\"\n size={size}\n >\n <SliderImpl\n dir={direction}\n orientation=\"horizontal\"\n {...sliderProps}\n onLayout={(e) => {\n const layout = e.nativeEvent.layout\n layoutRef.current = layout\n setSize(layout.height)\n }}\n ref={forwardedRef}\n onSlideStart={(event) => {\n const value = getValueFromPointer(event.nativeEvent.pageX)\n if (value) {\n onSlideStart?.(value)\n }\n }}\n onSlideMove={(event) => {\n const value = getValueFromPointer(event.nativeEvent.pageX)\n if (value) {\n onSlideMove?.(value)\n }\n }}\n onSlideEnd={() => {}}\n onStepKeyDown={(event) => {\n const isBackKey = BACK_KEYS[direction].includes(event.key)\n onStepKeyDown?.({ event, direction: isBackKey ? -1 : 1 })\n }}\n />\n </SliderOrientationProvider>\n )\n }\n)\n\n/* -------------------------------------------------------------------------------------------------\n * SliderVertical\n * -----------------------------------------------------------------------------------------------*/\n\ntype SliderVerticalElement = SliderImplElement\n\nconst SliderVertical = React.forwardRef<SliderVerticalElement, SliderVerticalProps>(\n (props: ScopedProps<SliderVerticalProps>, forwardedRef) => {\n const { min, max, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props\n const sliderRef = React.useRef<SliderImplElement>(null)\n const ref = useComposedRefs(forwardedRef, sliderRef)\n const rectRef = React.useRef<ClientRect>()\n\n function getValueFromPointer(pointerPosition: number) {\n // @ts-ignore\n const rect = rectRef.current || sliderRef.current!.getBoundingClientRect()\n const input: [number, number] = [0, rect.height]\n const output: [number, number] = [max, min]\n const value = linearScale(input, output)\n rectRef.current = rect\n return value(pointerPosition - rect.top)\n }\n\n return (\n <SliderOrientationProvider\n scope={props.__scopeSlider}\n startEdge=\"bottom\"\n endEdge=\"top\"\n sizeProp=\"height\"\n size={0}\n direction={1}\n >\n <SliderImpl\n {...sliderProps}\n orientation=\"vertical\"\n ref={ref}\n onSlideStart={(event) => {\n const value = getValueFromPointer(event.nativeEvent.locationY)\n onSlideStart?.(value)\n }}\n onSlideMove={(event) => {\n const value = getValueFromPointer(event.nativeEvent.locationY)\n onSlideMove?.(value)\n }}\n onSlideEnd={() => (rectRef.current = undefined)}\n onStepKeyDown={(event) => {\n const isBackKey = BACK_KEYS.ltr.includes(event.key)\n onStepKeyDown?.({ event, direction: isBackKey ? -1 : 1 })\n }}\n />\n </SliderOrientationProvider>\n )\n }\n)\n\n/* -------------------------------------------------------------------------------------------------\n * SliderTrack\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRACK_NAME = 'SliderTrack'\n\ntype SliderTrackElement = HTMLElement | View\n\nconst SliderTrackFrame = styled(SliderFrame, {\n name: 'SliderTrackFrame',\n})\n\nconst SliderTrack = React.forwardRef<SliderTrackElement, SliderTrackProps>(\n (props: ScopedProps<SliderTrackProps>, forwardedRef) => {\n const { __scopeSlider, ...trackProps } = props\n const context = useSliderContext(TRACK_NAME, __scopeSlider)\n return (\n <SliderTrackFrame\n data-disabled={context.disabled ? '' : undefined}\n data-orientation={context.orientation}\n orientation={context.orientation}\n {...trackProps}\n ref={forwardedRef}\n />\n )\n }\n)\n\nSliderTrack.displayName = TRACK_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * SliderTrackActive\n * -----------------------------------------------------------------------------------------------*/\n\nconst RANGE_NAME = 'SliderTrackActive'\n\ntype SliderTrackActiveElement = HTMLElement | View\ninterface SliderTrackActiveProps extends YStackProps {}\n\nconst SliderTrackActiveFrame = styled(SliderFrame, {\n name: 'SliderTrackActive',\n})\n\nconst SliderTrackActive = React.forwardRef<SliderTrackActiveElement, SliderTrackActiveProps>(\n (props: ScopedProps<SliderTrackActiveProps>, forwardedRef) => {\n const { __scopeSlider, ...rangeProps } = props\n const context = useSliderContext(RANGE_NAME, __scopeSlider)\n const orientation = useSliderOrientationContext(RANGE_NAME, __scopeSlider)\n const ref = React.useRef<HTMLSpanElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const valuesCount = context.values.length\n const percentages = context.values.map((value) =>\n convertValueToPercentage(value, context.min, context.max)\n )\n const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0\n const offsetEnd = 100 - Math.max(...percentages)\n\n return (\n <SliderTrackActiveFrame\n orientation={context.orientation}\n data-orientation={context.orientation}\n data-disabled={context.disabled ? '' : undefined}\n {...rangeProps}\n ref={composedRefs}\n {...{\n [orientation.startEdge]: offsetStart + '%',\n [orientation.endEdge]: offsetEnd + '%',\n }}\n />\n )\n }\n)\n\nSliderTrackActive.displayName = RANGE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * SliderThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SliderThumb'\n\nconst SliderThumbFrame = styled(SizableStack, {\n name: 'SliderThumb',\n position: 'absolute',\n})\n\ntype SliderThumbElement = HTMLElement | View\ninterface SliderThumbProps extends SizableStackProps {\n index: number\n}\n\nconst SliderThumb = React.forwardRef<SliderThumbElement, SliderThumbProps>(\n (props: ScopedProps<SliderThumbProps>, forwardedRef) => {\n const { __scopeSlider, index, size: sizeProp, ...thumbProps } = props\n const context = useSliderContext(THUMB_NAME, __scopeSlider)\n const orientation = useSliderOrientationContext(THUMB_NAME, __scopeSlider)\n // const [thumb, setThumb] = React.useState<HTMLSpanElement | null>(null)\n // const composedRefs = useComposedRefs(forwardedRef, (node) => setThumb(node))\n\n // We cast because index could be `-1` which would return undefined\n const value = context.values[index] as number | undefined\n const percent =\n value === undefined ? 0 : convertValueToPercentage(value, context.min, context.max)\n const label = getLabel(index, context.values.length)\n const [size, setSize] = React.useState(0)\n\n const thumbInBoundsOffset = size\n ? getThumbInBoundsOffset(size, percent, orientation.direction)\n : 0\n\n console.log('thumbInBoundsOffset', thumbInBoundsOffset, size, percent)\n\n // React.useEffect(() => {\n // if (thumb) {\n // context.thumbs.add(thumb)\n // return () => {\n // context.thumbs.delete(thumb)\n // }\n // }\n // }, [thumb, context.thumbs])\n\n return (\n <SliderThumbFrame\n ref={forwardedRef}\n // role=\"slider\"\n aria-label={props['aria-label'] || label}\n aria-valuemin={context.min}\n aria-valuenow={value}\n aria-valuemax={context.max}\n aria-orientation={context.orientation}\n data-orientation={context.orientation}\n data-disabled={context.disabled ? '' : undefined}\n // tabIndex={context.disabled ? undefined : 0}\n {...thumbProps}\n x={thumbInBoundsOffset}\n y={-size / 2}\n size={sizeProp ?? context.size ?? 30}\n onLayout={(e) => {\n setSize(e.nativeEvent.layout[orientation.sizeProp])\n }}\n {...{\n [orientation.startEdge]: `${percent}%`,\n }}\n /**\n * There will be no value on initial render while we work out the index so we hide thumbs\n * without a value, otherwise SSR will render them in the wrong position before they\n * snap into the correct position during hydration which would be visually jarring for\n * slower connections.\n */\n style={value === undefined ? { display: 'none' } : props.style}\n onFocus={composeEventHandlers(props.onFocus, () => {\n context.valueIndexToChangeRef.current = index\n })}\n />\n )\n }\n)\n\nSliderThumb.displayName = THUMB_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Slider\n * -----------------------------------------------------------------------------------------------*/\n\ntype SliderElement = SliderHorizontalElement | SliderVerticalElement\n\nconst Slider = withStaticProperties(\n React.forwardRef<SliderElement, SliderProps>((props: ScopedProps<SliderProps>, forwardedRef) => {\n const {\n name,\n min = 0,\n max = 100,\n step = 1,\n orientation = 'horizontal',\n disabled = false,\n minStepsBetweenThumbs = 0,\n defaultValue = [min],\n value,\n onValueChange = () => {},\n size: sizeProp,\n ...sliderProps\n } = props\n // const [slider, setSlider] = React.useState<HTMLElement | View | null>(null)\n // const composedRefs = useComposedRefs(forwardedRef, (node) => setSlider(node))\n const thumbRefs = React.useRef<SliderContextValue['thumbs']>(new Set())\n const valueIndexToChangeRef = React.useRef<number>(0)\n const isHorizontal = orientation === 'horizontal'\n // We set this to true by default so that events bubble to forms without JS (SSR)\n // TODO\n // const isFormControl = slider ? Boolean(slider.closest('form')) : true\n\n const [values = [], setValues] = useControllableState({\n prop: value,\n defaultProp: defaultValue,\n onChange: (value) => {\n // const thumbs = [...thumbRefs.current]\n // thumbs[valueIndexToChangeRef.current]?.focus()\n onValueChange(value)\n },\n })\n\n function handleSlideStart(value: number) {\n const closestIndex = getClosestValueIndex(values, value)\n updateValues(value, closestIndex)\n }\n\n function handleSlideMove(value: number) {\n updateValues(value, valueIndexToChangeRef.current)\n }\n\n function updateValues(value: number, atIndex: number) {\n const decimalCount = getDecimalCount(step)\n const snapToStep = roundValue(Math.round((value - min) / step) * step + min, decimalCount)\n const nextValue = clamp(snapToStep, [min, max])\n setValues((prevValues = []) => {\n const nextValues = getNextSortedValues(prevValues, nextValue, atIndex)\n if (hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {\n valueIndexToChangeRef.current = nextValues.indexOf(nextValue)\n return String(nextValues) === String(prevValues) ? prevValues : nextValues\n } else {\n return prevValues\n }\n })\n }\n\n const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical\n\n return (\n <SliderProvider\n scope={props.__scopeSlider}\n disabled={disabled}\n min={min}\n max={max}\n valueIndexToChangeRef={valueIndexToChangeRef}\n thumbs={thumbRefs.current}\n values={values}\n orientation={orientation}\n // @ts-ignore\n size={sizeProp || 20}\n >\n <SliderOriented\n aria-disabled={disabled}\n data-disabled={disabled ? '' : undefined}\n {...sliderProps}\n ref={forwardedRef}\n min={min}\n max={max}\n onSlideStart={disabled ? undefined : handleSlideStart}\n onSlideMove={disabled ? undefined : handleSlideMove}\n onHomeKeyDown={() => !disabled && updateValues(min, 0)}\n onEndKeyDown={() => !disabled && updateValues(max, values.length - 1)}\n onStepKeyDown={({ event, direction: stepDirection }) => {\n if (!disabled) {\n const isPageKey = PAGE_KEYS.includes(event.key)\n const isSkipKey = isPageKey || (event.shiftKey && ARROW_KEYS.includes(event.key))\n const multiplier = isSkipKey ? 10 : 1\n const atIndex = valueIndexToChangeRef.current\n const value = values[atIndex]\n const stepInDirection = step * multiplier * stepDirection\n updateValues(value + stepInDirection, atIndex)\n }\n }}\n />\n {/* {isFormControl &&\n values.map((value, index) => (\n <BubbleInput\n key={index}\n name={name ? name + (values.length > 1 ? '[]' : '') : undefined}\n value={value}\n />\n ))} */}\n </SliderProvider>\n )\n }),\n {\n Track: SliderTrack,\n TrackActive: SliderTrackActive,\n Thumb: SliderThumb,\n }\n)\n\nSlider.displayName = SLIDER_NAME\n\n/* -----------------------------------------------------------------------------------------------*/\n\n// TODO\nconst BubbleInput = (props: any) => {\n const { value, ...inputProps } = props\n const ref = React.useRef<HTMLInputElement>(null)\n const prevValue = usePrevious(value)\n\n // Bubble value change to parents (e.g form change event)\n React.useEffect(() => {\n const input = ref.current!\n const inputProto = window.HTMLInputElement.prototype\n const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'value') as PropertyDescriptor\n const setValue = descriptor.set\n if (prevValue !== value && setValue) {\n const event = new Event('input', { bubbles: true })\n setValue.call(input, value)\n input.dispatchEvent(event)\n }\n }, [prevValue, value])\n\n /**\n * We purposefully do not use `type=\"hidden\"` here otherwise forms that\n * wrap it will not be able to access its value via the FormData API.\n *\n * We purposefully do not add the `value` attribute here to allow the value\n * to be set programatically and bubble to any parent form `onChange` event.\n * Adding the `value` will cause React to consider the programatic\n * dispatch a duplicate and it will get swallowed.\n */\n return <input style={{ display: 'none' }} {...inputProps} ref={ref} defaultValue={value} />\n}\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Track = SliderTrack\nconst Range = SliderTrackActive\nconst Thumb = SliderThumb\n\nexport {\n Slider,\n SliderTrack,\n SliderTrackActive,\n SliderThumb,\n //\n Track,\n Range,\n Thumb,\n}\nexport type { SliderProps, SliderTrackProps, SliderTrackActiveProps, SliderThumbProps }\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,
|
|
4
|
+
"sourcesContent": ["// forked from radix-ui\n\nimport { useComposedRefs } from '@tamagui/compose-refs'\nimport { styled, withStaticProperties } from '@tamagui/core'\nimport { clamp, composeEventHandlers } from '@tamagui/helpers'\nimport { SizableStackProps, ThemeableSizableStack, YStackProps } from '@tamagui/stacks'\nimport { useControllableState } from '@tamagui/use-controllable-state'\nimport { useDirection } from '@tamagui/use-direction'\nimport * as React from 'react'\nimport { LayoutRectangle, View } from 'react-native'\n\nimport {\n ARROW_KEYS,\n BACK_KEYS,\n PAGE_KEYS,\n SLIDER_NAME,\n SliderOrientationProvider,\n SliderProvider,\n useSliderContext,\n useSliderOrientationContext,\n} from './constants'\nimport {\n convertValueToPercentage,\n getClosestValueIndex,\n getDecimalCount,\n getLabel,\n getNextSortedValues,\n getThumbInBoundsOffset,\n hasMinStepsBetweenValues,\n linearScale,\n roundValue,\n} from './helpers'\nimport { SliderFrame, SliderImpl } from './SliderImpl'\nimport {\n Direction,\n ScopedProps,\n SliderContextValue,\n SliderHorizontalProps,\n SliderImplElement,\n SliderProps,\n SliderTrackProps,\n SliderVerticalProps,\n} from './types'\n\n/* -------------------------------------------------------------------------------------------------\n * SliderHorizontal\n * -----------------------------------------------------------------------------------------------*/\n\ntype SliderHorizontalElement = SliderImplElement\n\nconst SliderHorizontal = React.forwardRef<SliderHorizontalElement, SliderHorizontalProps>(\n (props: ScopedProps<SliderHorizontalProps>, forwardedRef) => {\n const { min, max, dir, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props\n const direction = useDirection(dir)\n const isDirectionLTR = direction === 'ltr'\n const layoutRef = React.useRef<LayoutRectangle | null>(null)\n const [size, setSize] = React.useState(0)\n\n function getValueFromPointer(pointerPosition: number) {\n const layout = layoutRef.current\n if (!layout) return\n const input: [number, number] = [0, layout.width]\n const output: [number, number] = isDirectionLTR ? [min, max] : [max, min]\n const value = linearScale(input, output)\n return value(pointerPosition)\n }\n\n return (\n <SliderOrientationProvider\n scope={props.__scopeSlider}\n startEdge={isDirectionLTR ? 'left' : 'right'}\n endEdge={isDirectionLTR ? 'right' : 'left'}\n direction={isDirectionLTR ? 1 : -1}\n sizeProp=\"width\"\n size={size}\n >\n <SliderImpl\n ref={forwardedRef}\n dir={direction}\n {...sliderProps}\n orientation=\"horizontal\"\n onLayout={(e) => {\n const layout = e.nativeEvent.layout\n layoutRef.current = layout\n setSize(layout.height)\n }}\n onSlideStart={(event, target) => {\n const value = getValueFromPointer(event.nativeEvent.locationX)\n if (value) {\n onSlideStart?.(value, target)\n }\n }}\n onSlideMove={(event) => {\n const value = getValueFromPointer(event.nativeEvent.locationX)\n if (value) {\n onSlideMove?.(value)\n }\n }}\n onSlideEnd={() => {}}\n onStepKeyDown={(event) => {\n const isBackKey = BACK_KEYS[direction].includes(event.key)\n onStepKeyDown?.({ event, direction: isBackKey ? -1 : 1 })\n }}\n />\n </SliderOrientationProvider>\n )\n }\n)\n\n/* -------------------------------------------------------------------------------------------------\n * SliderVertical\n * -----------------------------------------------------------------------------------------------*/\n\ntype SliderVerticalElement = SliderImplElement\n\nconst SliderVertical = React.forwardRef<SliderVerticalElement, SliderVerticalProps>(\n (props: ScopedProps<SliderVerticalProps>, forwardedRef) => {\n const { min, max, onSlideStart, onSlideMove, onStepKeyDown, ...sliderProps } = props\n const layoutRef = React.useRef<LayoutRectangle | null>(null)\n const [size, setSize] = React.useState(0)\n\n function getValueFromPointer(pointerPosition: number) {\n const layout = layoutRef.current\n if (!layout) return\n const input: [number, number] = [0, layout.height]\n const output: [number, number] = [max, min]\n const value = linearScale(input, output)\n return value(pointerPosition)\n }\n\n return (\n <SliderOrientationProvider\n scope={props.__scopeSlider}\n startEdge=\"bottom\"\n endEdge=\"top\"\n sizeProp=\"height\"\n size={size}\n direction={1}\n >\n <SliderImpl\n ref={forwardedRef}\n {...sliderProps}\n orientation=\"vertical\"\n onLayout={(e) => {\n const layout = e.nativeEvent.layout\n layoutRef.current = layout\n setSize(layout.height)\n }}\n onSlideStart={(event, target) => {\n const value = getValueFromPointer(event.nativeEvent.locationY)\n if (value) {\n onSlideStart?.(value, target)\n }\n }}\n onSlideMove={(event) => {\n const value = getValueFromPointer(event.nativeEvent.locationY)\n if (value) {\n onSlideMove?.(value)\n }\n }}\n onSlideEnd={() => {}}\n onStepKeyDown={(event) => {\n const isBackKey = BACK_KEYS.ltr.includes(event.key)\n onStepKeyDown?.({ event, direction: isBackKey ? -1 : 1 })\n }}\n />\n </SliderOrientationProvider>\n )\n }\n)\n\n/* -------------------------------------------------------------------------------------------------\n * SliderTrack\n * -----------------------------------------------------------------------------------------------*/\n\nconst TRACK_NAME = 'SliderTrack'\n\ntype SliderTrackElement = HTMLElement | View\n\nconst SliderTrackFrame = styled(SliderFrame, {\n name: 'SliderTrack',\n height: '100%',\n width: '100%',\n backgroundColor: '$background',\n position: 'relative',\n borderRadius: 100_000,\n})\n\nconst SliderTrack = React.forwardRef<SliderTrackElement, SliderTrackProps>(\n (props: ScopedProps<SliderTrackProps>, forwardedRef) => {\n const { __scopeSlider, ...trackProps } = props\n const context = useSliderContext(TRACK_NAME, __scopeSlider)\n return (\n <SliderTrackFrame\n data-disabled={context.disabled ? '' : undefined}\n data-orientation={context.orientation}\n orientation={context.orientation}\n size={context.size}\n {...trackProps}\n ref={forwardedRef}\n />\n )\n }\n)\n\nSliderTrack.displayName = TRACK_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * SliderTrackActive\n * -----------------------------------------------------------------------------------------------*/\n\nconst RANGE_NAME = 'SliderTrackActive'\n\ntype SliderTrackActiveElement = HTMLElement | View\ninterface SliderTrackActiveProps extends YStackProps {}\n\nconst SliderTrackActiveFrame = styled(SliderFrame, {\n name: 'SliderTrackActive',\n backgroundColor: '$background',\n position: 'absolute',\n})\n\nconst SliderTrackActive = React.forwardRef<SliderTrackActiveElement, SliderTrackActiveProps>(\n (props: ScopedProps<SliderTrackActiveProps>, forwardedRef) => {\n const { __scopeSlider, ...rangeProps } = props\n const context = useSliderContext(RANGE_NAME, __scopeSlider)\n const orientation = useSliderOrientationContext(RANGE_NAME, __scopeSlider)\n const ref = React.useRef<HTMLSpanElement>(null)\n const composedRefs = useComposedRefs(forwardedRef, ref)\n const valuesCount = context.values.length\n const percentages = context.values.map((value) =>\n convertValueToPercentage(value, context.min, context.max)\n )\n const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0\n const offsetEnd = 100 - Math.max(...percentages)\n\n return (\n <SliderTrackActiveFrame\n orientation={context.orientation}\n data-orientation={context.orientation}\n data-disabled={context.disabled ? '' : undefined}\n size={context.size}\n {...rangeProps}\n ref={composedRefs}\n {...{\n [orientation.startEdge]: offsetStart + '%',\n [orientation.endEdge]: offsetEnd + '%',\n }}\n {...(orientation.sizeProp === 'width'\n ? {\n height: '100%',\n }\n : {\n left: 0,\n right: 0,\n })}\n />\n )\n }\n)\n\nSliderTrackActive.displayName = RANGE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * SliderThumb\n * -----------------------------------------------------------------------------------------------*/\n\nconst THUMB_NAME = 'SliderThumb'\n\nconst SliderThumbFrame = styled(ThemeableSizableStack, {\n name: 'SliderThumb',\n position: 'absolute',\n // TODO not taking up 2\n bordered: 2,\n // OR THIS\n borderWidth: 2,\n pressable: true,\n focusable: true,\n hoverable: true,\n})\n\ntype SliderThumbElement = HTMLElement | View\ninterface SliderThumbProps extends SizableStackProps {\n index: number\n}\n\nconst SliderThumb = React.forwardRef<SliderThumbElement, SliderThumbProps>(\n (props: ScopedProps<SliderThumbProps>, forwardedRef) => {\n const { __scopeSlider, index, size: sizeProp, ...thumbProps } = props\n const context = useSliderContext(THUMB_NAME, __scopeSlider)\n const orientation = useSliderOrientationContext(THUMB_NAME, __scopeSlider)\n const [thumb, setThumb] = React.useState<View | HTMLElement | null>(null)\n const composedRefs = useComposedRefs(forwardedRef, (node) => setThumb(node))\n\n // We cast because index could be `-1` which would return undefined\n const value = context.values[index] as number | undefined\n const percent =\n value === undefined ? 0 : convertValueToPercentage(value, context.min, context.max)\n const label = getLabel(index, context.values.length)\n const [size, setSize] = React.useState(0)\n\n const thumbInBoundsOffset = size\n ? getThumbInBoundsOffset(size, percent, orientation.direction)\n : 0\n\n React.useEffect(() => {\n if (thumb) {\n context.thumbs.add(thumb)\n return () => {\n context.thumbs.delete(thumb)\n }\n }\n }, [thumb, context.thumbs])\n\n return (\n <SliderThumbFrame\n ref={composedRefs}\n // TODO\n // @ts-ignore\n role=\"slider\"\n aria-label={props['aria-label'] || label}\n aria-valuemin={context.min}\n aria-valuenow={value}\n aria-valuemax={context.max}\n aria-orientation={context.orientation}\n data-orientation={context.orientation}\n data-disabled={context.disabled ? '' : undefined}\n // TODO\n // @ts-ignore\n tabIndex={context.disabled ? undefined : 0}\n {...thumbProps}\n {...(context.orientation === 'horizontal'\n ? {\n x: thumbInBoundsOffset - size / 2,\n y: -size / 2,\n top: '50%',\n }\n : {\n x: -size / 2,\n y: size / 2,\n left: '50%',\n })}\n size={sizeProp ?? context.size ?? 30}\n onLayout={(e) => {\n setSize(e.nativeEvent.layout[orientation.sizeProp])\n }}\n {...{\n [orientation.startEdge]: `${percent}%`,\n }}\n /**\n * There will be no value on initial render while we work out the index so we hide thumbs\n * without a value, otherwise SSR will render them in the wrong position before they\n * snap into the correct position during hydration which would be visually jarring for\n * slower connections.\n */\n style={value === undefined ? { display: 'none' } : props.style}\n onFocus={composeEventHandlers(props.onFocus, () => {\n context.valueIndexToChangeRef.current = index\n })}\n />\n )\n }\n)\n\nSliderThumb.displayName = THUMB_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Slider\n * -----------------------------------------------------------------------------------------------*/\n\ntype SliderElement = SliderHorizontalElement | SliderVerticalElement\n\nconst Slider = withStaticProperties(\n React.forwardRef<SliderElement, SliderProps>((props: ScopedProps<SliderProps>, forwardedRef) => {\n const {\n name,\n min = 0,\n max = 100,\n step = 1,\n orientation = 'horizontal',\n disabled = false,\n minStepsBetweenThumbs = 0,\n defaultValue = [min],\n value,\n onValueChange = () => {},\n size: sizeProp,\n ...sliderProps\n } = props\n // const [slider, setSlider] = React.useState<HTMLElement | View | null>(null)\n // const composedRefs = useComposedRefs(forwardedRef, (node) => setSlider(node))\n const thumbRefs = React.useRef<SliderContextValue['thumbs']>(new Set())\n const valueIndexToChangeRef = React.useRef<number>(0)\n const isHorizontal = orientation === 'horizontal'\n // We set this to true by default so that events bubble to forms without JS (SSR)\n // TODO\n // const isFormControl = slider ? Boolean(slider.closest('form')) : true\n\n const [values = [], setValues] = useControllableState({\n prop: value,\n defaultProp: defaultValue,\n onChange: (value) => {\n const thumbs = [...thumbRefs.current]\n thumbs[valueIndexToChangeRef.current]?.focus()\n onValueChange(value)\n },\n })\n\n function handleSlideMove(value: number) {\n updateValues(value, valueIndexToChangeRef.current)\n }\n\n function updateValues(value: number, atIndex: number) {\n const decimalCount = getDecimalCount(step)\n const snapToStep = roundValue(Math.round((value - min) / step) * step + min, decimalCount)\n const nextValue = clamp(snapToStep, [min, max])\n setValues((prevValues = []) => {\n const nextValues = getNextSortedValues(prevValues, nextValue, atIndex)\n if (hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {\n valueIndexToChangeRef.current = nextValues.indexOf(nextValue)\n return String(nextValues) === String(prevValues) ? prevValues : nextValues\n } else {\n return prevValues\n }\n })\n }\n\n const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical\n\n return (\n <SliderProvider\n scope={props.__scopeSlider}\n disabled={disabled}\n min={min}\n max={max}\n valueIndexToChangeRef={valueIndexToChangeRef}\n thumbs={thumbRefs.current}\n values={values}\n orientation={orientation}\n size={sizeProp || 20}\n >\n <SliderOriented\n aria-disabled={disabled}\n data-disabled={disabled ? '' : undefined}\n {...sliderProps}\n ref={forwardedRef}\n min={min}\n max={max}\n onSlideStart={\n disabled\n ? undefined\n : (value: number, target) => {\n // when starting on the track, move it right away\n // when starting on thumb, dont jump until movemenet as it feels weird\n console.log('target', target)\n if (target !== 'thumb') {\n const closestIndex = getClosestValueIndex(values, value)\n updateValues(value, closestIndex)\n }\n }\n }\n onSlideMove={disabled ? undefined : handleSlideMove}\n onHomeKeyDown={() => !disabled && updateValues(min, 0)}\n onEndKeyDown={() => !disabled && updateValues(max, values.length - 1)}\n onStepKeyDown={({ event, direction: stepDirection }) => {\n if (!disabled) {\n const isPageKey = PAGE_KEYS.includes(event.key)\n const isSkipKey = isPageKey || (event.shiftKey && ARROW_KEYS.includes(event.key))\n const multiplier = isSkipKey ? 10 : 1\n const atIndex = valueIndexToChangeRef.current\n const value = values[atIndex]\n const stepInDirection = step * multiplier * stepDirection\n updateValues(value + stepInDirection, atIndex)\n }\n }}\n />\n {/* {isFormControl &&\n values.map((value, index) => (\n <BubbleInput\n key={index}\n name={name ? name + (values.length > 1 ? '[]' : '') : undefined}\n value={value}\n />\n ))} */}\n </SliderProvider>\n )\n }),\n {\n Track: SliderTrack,\n TrackActive: SliderTrackActive,\n Thumb: SliderThumb,\n }\n)\n\nSlider.displayName = SLIDER_NAME\n\n/* -----------------------------------------------------------------------------------------------*/\n\n// TODO\n// const BubbleInput = (props: any) => {\n// const { value, ...inputProps } = props\n// const ref = React.useRef<HTMLInputElement>(null)\n// const prevValue = usePrevious(value)\n\n// // Bubble value change to parents (e.g form change event)\n// React.useEffect(() => {\n// const input = ref.current!\n// const inputProto = window.HTMLInputElement.prototype\n// const descriptor = Object.getOwnPropertyDescriptor(inputProto, 'value') as PropertyDescriptor\n// const setValue = descriptor.set\n// if (prevValue !== value && setValue) {\n// const event = new Event('input', { bubbles: true })\n// setValue.call(input, value)\n// input.dispatchEvent(event)\n// }\n// }, [prevValue, value])\n\n// /**\n// * We purposefully do not use `type=\"hidden\"` here otherwise forms that\n// * wrap it will not be able to access its value via the FormData API.\n// *\n// * We purposefully do not add the `value` attribute here to allow the value\n// * to be set programatically and bubble to any parent form `onChange` event.\n// * Adding the `value` will cause React to consider the programatic\n// * dispatch a duplicate and it will get swallowed.\n// */\n// return <input style={{ display: 'none' }} {...inputProps} ref={ref} defaultValue={value} />\n// }\n\n/* -----------------------------------------------------------------------------------------------*/\n\nconst Track = SliderTrack\nconst Range = SliderTrackActive\nconst Thumb = SliderThumb\n\nexport {\n Slider,\n SliderTrack,\n SliderTrackActive,\n SliderThumb,\n //\n Track,\n Range,\n Thumb,\n}\nexport type { SliderProps, SliderTrackProps, SliderTrackActiveProps, SliderThumbProps }\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAAgC;AAChC,kBAA6C;AAC7C,qBAA4C;AAC5C,oBAAsE;AACtE,oCAAqC;AACrC,2BAA6B;AAC7B,YAAuB;AAGvB,uBASO;AACP,sBAUO;AACP,wBAAwC;AAkBxC,MAAM,mBAAmB,MAAM,WAC7B,CAAC,OAA2C,iBAAiB;AAC3D,QAAoF,YAA5E,OAAK,KAAK,KAAK,cAAc,aAAa,kBAAkC,IAAhB,wBAAgB,IAAhB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,7 +57,7 @@ module.exports = __toCommonJS(SliderImpl_exports);
|
|
|
57
57
|
var import_core = require("@tamagui/core");
|
|
58
58
|
var import_stacks = require("@tamagui/stacks");
|
|
59
59
|
var React = __toESM(require("react"));
|
|
60
|
-
var
|
|
60
|
+
var import_constants = require("./constants");
|
|
61
61
|
const DirectionalYStack = (0, import_core.styled)(import_stacks.YStack, {
|
|
62
62
|
variants: {
|
|
63
63
|
orientation: {
|
|
@@ -67,22 +67,21 @@ const DirectionalYStack = (0, import_core.styled)(import_stacks.YStack, {
|
|
|
67
67
|
}
|
|
68
68
|
});
|
|
69
69
|
const SliderFrame = (0, import_core.styled)(DirectionalYStack, {
|
|
70
|
-
name: "Slider",
|
|
71
70
|
position: "relative",
|
|
72
71
|
variants: {
|
|
73
72
|
size: (val, extras) => {
|
|
74
73
|
const orientation = extras.props.orientation;
|
|
75
74
|
const circleSize = (0, import_stacks.getCircleSize)(val, extras);
|
|
76
|
-
const size = circleSize /
|
|
75
|
+
const size = circleSize / 10;
|
|
77
76
|
if (orientation === "horizontal") {
|
|
78
77
|
return {
|
|
79
78
|
height: size,
|
|
80
|
-
|
|
79
|
+
borderRadius: size
|
|
81
80
|
};
|
|
82
81
|
}
|
|
83
82
|
return {
|
|
84
83
|
width: size,
|
|
85
|
-
|
|
84
|
+
borderRadius: size
|
|
86
85
|
};
|
|
87
86
|
}
|
|
88
87
|
}
|
|
@@ -105,16 +104,37 @@ const SliderImpl = React.forwardRef((props, forwardedRef) => {
|
|
|
105
104
|
"onEndKeyDown",
|
|
106
105
|
"onStepKeyDown"
|
|
107
106
|
]);
|
|
108
|
-
const context = (0,
|
|
109
|
-
return /* @__PURE__ */ React.createElement(SliderFrame, __spreadProps(__spreadValues({
|
|
107
|
+
const context = (0, import_constants.useSliderContext)(import_constants.SLIDER_NAME, __scopeSlider);
|
|
108
|
+
return /* @__PURE__ */ React.createElement(SliderFrame, __spreadProps(__spreadValues(__spreadProps(__spreadValues({
|
|
110
109
|
size: "$4"
|
|
111
110
|
}, sliderProps), {
|
|
112
111
|
"data-orientation": sliderProps.orientation,
|
|
113
|
-
ref: forwardedRef
|
|
112
|
+
ref: forwardedRef
|
|
113
|
+
}), import_core.isWeb && {
|
|
114
|
+
onKeyDown: (event) => {
|
|
115
|
+
if (event.key === "Home") {
|
|
116
|
+
onHomeKeyDown(event);
|
|
117
|
+
event.preventDefault();
|
|
118
|
+
} else if (event.key === "End") {
|
|
119
|
+
onEndKeyDown(event);
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
} else if (import_constants.PAGE_KEYS.concat(import_constants.ARROW_KEYS).includes(event.key)) {
|
|
122
|
+
onStepKeyDown(event);
|
|
123
|
+
event.preventDefault();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}), {
|
|
114
127
|
onStartShouldSetResponder: () => true,
|
|
115
128
|
onResponderGrant: (0, import_core.composeEventHandlers)(props.onResponderGrant, (event) => {
|
|
129
|
+
const target = event.target;
|
|
130
|
+
const isStartingOnThumb = context.thumbs.has(event.target);
|
|
116
131
|
event.preventDefault();
|
|
117
|
-
|
|
132
|
+
if (target instanceof HTMLElement) {
|
|
133
|
+
if (context.thumbs.has(target)) {
|
|
134
|
+
target.focus();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
onSlideStart(event, isStartingOnThumb ? "thumb" : "track");
|
|
118
138
|
}),
|
|
119
139
|
onResponderMove: (0, import_core.composeEventHandlers)(props.onResponderMove, (event) => {
|
|
120
140
|
onSlideMove(event);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/SliderImpl.tsx"],
|
|
4
|
-
"sourcesContent": ["/* -------------------------------------------------------------------------------------------------\n * SliderImpl\n * -----------------------------------------------------------------------------------------------*/\n\nimport { composeEventHandlers, styled } from '@tamagui/core'\nimport { YStack, getCircleSize } from '@tamagui/stacks'\nimport * as React from 'react'\n\nimport { SLIDER_NAME, useSliderContext } from './
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,
|
|
4
|
+
"sourcesContent": ["/* -------------------------------------------------------------------------------------------------\n * SliderImpl\n * -----------------------------------------------------------------------------------------------*/\n\nimport { composeEventHandlers, isWeb, styled } from '@tamagui/core'\nimport { YStack, getCircleSize } from '@tamagui/stacks'\nimport * as React from 'react'\n\nimport { ARROW_KEYS, PAGE_KEYS, SLIDER_NAME, useSliderContext } from './constants'\nimport { ScopedProps, SliderImplElement, SliderImplProps } from './types'\n\nexport const DirectionalYStack = styled(YStack, {\n variants: {\n orientation: {\n horizontal: {},\n vertical: {},\n },\n },\n})\n\nexport const SliderFrame = styled(DirectionalYStack, {\n position: 'relative',\n\n variants: {\n size: (val, extras) => {\n const orientation = extras.props.orientation\n const circleSize = getCircleSize(val, extras)\n const size = circleSize / 10\n if (orientation === 'horizontal') {\n return {\n height: size,\n borderRadius: size,\n }\n }\n return {\n width: size,\n borderRadius: size,\n }\n },\n },\n})\n\nexport const SliderImpl = React.forwardRef<SliderImplElement, SliderImplProps>(\n (props: ScopedProps<SliderImplProps>, forwardedRef) => {\n const {\n __scopeSlider,\n onSlideStart,\n onSlideMove,\n onSlideEnd,\n onHomeKeyDown,\n onEndKeyDown,\n onStepKeyDown,\n ...sliderProps\n } = props\n const context = useSliderContext(SLIDER_NAME, __scopeSlider)\n return (\n <SliderFrame\n size=\"$4\"\n {...sliderProps}\n data-orientation={sliderProps.orientation}\n ref={forwardedRef}\n {...(isWeb && {\n onKeyDown: (event) => {\n if (event.key === 'Home') {\n onHomeKeyDown(event)\n // Prevent scrolling to page start\n event.preventDefault()\n } else if (event.key === 'End') {\n onEndKeyDown(event)\n // Prevent scrolling to page end\n event.preventDefault()\n } else if (PAGE_KEYS.concat(ARROW_KEYS).includes(event.key)) {\n onStepKeyDown(event)\n // Prevent scrolling for directional key presses\n event.preventDefault()\n }\n },\n })}\n onStartShouldSetResponder={() => true}\n onResponderGrant={composeEventHandlers(props.onResponderGrant, (event) => {\n const target = event.target as HTMLElement | number\n const isStartingOnThumb = context.thumbs.has(event.target)\n // // Prevent browser focus behaviour because we focus a thumb manually when values change.\n event.preventDefault()\n // Touch devices have a delay before focusing so won't focus if touch immediately moves\n // away from target (sliding). We want thumb to focus regardless.\n if (target instanceof HTMLElement) {\n if (context.thumbs.has(target)) {\n target.focus()\n }\n }\n onSlideStart(event, isStartingOnThumb ? 'thumb' : 'track')\n })}\n onResponderMove={composeEventHandlers(props.onResponderMove, (event) => {\n // const target = event.target as HTMLElement\n onSlideMove(event)\n })}\n onResponderRelease={composeEventHandlers(props.onResponderRelease, (event) => {\n // const target = event.target as HTMLElement\n onSlideEnd(event)\n })}\n />\n )\n }\n)\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAAoD;AACpD,oBAAsC;AACtC,YAAuB;AAEvB,uBAAqE;AAG9D,MAAM,oBAAoB,wBAAO,sBAAQ;AAAA,EAC9C,UAAU;AAAA,IACR,aAAa;AAAA,MACX,YAAY,CAAC;AAAA,MACb,UAAU,CAAC;AAAA,IACb;AAAA,EACF;AACF,CAAC;AAEM,MAAM,cAAc,wBAAO,mBAAmB;AAAA,EACnD,UAAU;AAAA,EAEV,UAAU;AAAA,IACR,MAAM,CAAC,KAAK,WAAW;AACrB,YAAM,cAAc,OAAO,MAAM;AACjC,YAAM,aAAa,iCAAc,KAAK,MAAM;AAC5C,YAAM,OAAO,aAAa;AAC1B,UAAI,gBAAgB,cAAc;AAChC,eAAO;AAAA,UACL,QAAQ;AAAA,UACR,cAAc;AAAA,QAChB;AAAA,MACF;AACA,aAAO;AAAA,QACL,OAAO;AAAA,QACP,cAAc;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF,CAAC;A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