@tamagui/slider 2.0.0-rc.8 → 2.0.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.
Files changed (89) hide show
  1. package/dist/cjs/Slider.cjs +450 -429
  2. package/dist/cjs/Slider.native.js +452 -458
  3. package/dist/cjs/Slider.native.js.map +1 -1
  4. package/dist/cjs/SliderImpl.cjs +127 -100
  5. package/dist/cjs/SliderImpl.native.js +147 -117
  6. package/dist/cjs/SliderImpl.native.js.map +1 -1
  7. package/dist/cjs/constants.cjs +39 -37
  8. package/dist/cjs/constants.native.js +40 -38
  9. package/dist/cjs/constants.native.js.map +1 -1
  10. package/dist/cjs/helpers.cjs +32 -20
  11. package/dist/cjs/helpers.native.js +34 -26
  12. package/dist/cjs/helpers.native.js.map +1 -1
  13. package/dist/cjs/index.cjs +15 -13
  14. package/dist/cjs/index.native.js +15 -13
  15. package/dist/cjs/index.native.js.map +1 -1
  16. package/dist/cjs/types.cjs +7 -5
  17. package/dist/cjs/types.native.js +7 -5
  18. package/dist/cjs/types.native.js.map +1 -1
  19. package/dist/esm/Slider.mjs +407 -395
  20. package/dist/esm/Slider.mjs.map +1 -1
  21. package/dist/esm/Slider.native.js +408 -423
  22. package/dist/esm/Slider.native.js.map +1 -1
  23. package/dist/esm/SliderImpl.mjs +95 -70
  24. package/dist/esm/SliderImpl.mjs.map +1 -1
  25. package/dist/esm/SliderImpl.native.js +115 -87
  26. package/dist/esm/SliderImpl.native.js.map +1 -1
  27. package/dist/esm/constants.mjs +27 -27
  28. package/dist/esm/constants.mjs.map +1 -1
  29. package/dist/esm/constants.native.js +27 -27
  30. package/dist/esm/constants.native.js.map +1 -1
  31. package/dist/esm/helpers.mjs +20 -10
  32. package/dist/esm/helpers.mjs.map +1 -1
  33. package/dist/esm/helpers.native.js +22 -16
  34. package/dist/esm/helpers.native.js.map +1 -1
  35. package/dist/esm/index.js +4 -7
  36. package/dist/esm/index.js.map +1 -6
  37. package/dist/jsx/Slider.mjs +407 -395
  38. package/dist/jsx/Slider.mjs.map +1 -1
  39. package/dist/jsx/Slider.native.js +452 -458
  40. package/dist/jsx/Slider.native.js.map +1 -1
  41. package/dist/jsx/SliderImpl.mjs +95 -70
  42. package/dist/jsx/SliderImpl.mjs.map +1 -1
  43. package/dist/jsx/SliderImpl.native.js +147 -117
  44. package/dist/jsx/SliderImpl.native.js.map +1 -1
  45. package/dist/jsx/constants.mjs +27 -27
  46. package/dist/jsx/constants.mjs.map +1 -1
  47. package/dist/jsx/constants.native.js +40 -38
  48. package/dist/jsx/constants.native.js.map +1 -1
  49. package/dist/jsx/helpers.mjs +20 -10
  50. package/dist/jsx/helpers.mjs.map +1 -1
  51. package/dist/jsx/helpers.native.js +34 -26
  52. package/dist/jsx/helpers.native.js.map +1 -1
  53. package/dist/jsx/index.js +4 -7
  54. package/dist/jsx/index.js.map +1 -6
  55. package/dist/jsx/index.native.js +15 -13
  56. package/dist/jsx/types.native.js +7 -5
  57. package/package.json +17 -21
  58. package/dist/cjs/Slider.js +0 -486
  59. package/dist/cjs/Slider.js.map +0 -6
  60. package/dist/cjs/SliderImpl.js +0 -115
  61. package/dist/cjs/SliderImpl.js.map +0 -6
  62. package/dist/cjs/constants.js +0 -47
  63. package/dist/cjs/constants.js.map +0 -6
  64. package/dist/cjs/helpers.js +0 -74
  65. package/dist/cjs/helpers.js.map +0 -6
  66. package/dist/cjs/index.js +0 -23
  67. package/dist/cjs/index.js.map +0 -6
  68. package/dist/cjs/types.js +0 -14
  69. package/dist/cjs/types.js.map +0 -6
  70. package/dist/esm/Slider.js +0 -499
  71. package/dist/esm/Slider.js.map +0 -6
  72. package/dist/esm/SliderImpl.js +0 -98
  73. package/dist/esm/SliderImpl.js.map +0 -6
  74. package/dist/esm/constants.js +0 -31
  75. package/dist/esm/constants.js.map +0 -6
  76. package/dist/esm/helpers.js +0 -58
  77. package/dist/esm/helpers.js.map +0 -6
  78. package/dist/esm/types.js +0 -1
  79. package/dist/esm/types.js.map +0 -6
  80. package/dist/jsx/Slider.js +0 -499
  81. package/dist/jsx/Slider.js.map +0 -6
  82. package/dist/jsx/SliderImpl.js +0 -98
  83. package/dist/jsx/SliderImpl.js.map +0 -6
  84. package/dist/jsx/constants.js +0 -31
  85. package/dist/jsx/constants.js.map +0 -6
  86. package/dist/jsx/helpers.js +0 -58
  87. package/dist/jsx/helpers.js.map +0 -6
  88. package/dist/jsx/types.js +0 -1
  89. package/dist/jsx/types.js.map +0 -6
@@ -12,33 +12,32 @@ import { convertValueToPercentage, getClosestValueIndex, getDecimalCount, getLab
12
12
  import { SliderFrame, SliderImpl } from "./SliderImpl.mjs";
13
13
  import { jsx } from "react/jsx-runtime";
14
14
  const activeSliderMeasureListeners = /* @__PURE__ */new Set();
15
- process.env.TAMAGUI_DISABLE_SLIDER_INTERVAL || setInterval?.(() => {
15
+ if (!process.env.TAMAGUI_DISABLE_SLIDER_INTERVAL) setInterval?.(() => {
16
16
  activeSliderMeasureListeners.forEach(cb => cb());
17
17
  },
18
18
  // really doesn't need to be super often
19
19
  1e3);
20
20
  const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
21
21
  const {
22
- min,
23
- max,
24
- dir,
25
- onSlideStart,
26
- onSlideMove,
27
- onStepKeyDown,
28
- onSlideEnd,
29
- ...sliderProps
30
- } = props,
31
- direction = useDirection(dir),
32
- isDirectionLTR = direction === "ltr",
33
- sliderRef = React.useRef(null),
34
- [state, setState_] = React.useState(() => ({
35
- size: 0,
36
- offset: 0
37
- })),
38
- setState = useCreateShallowSetState(setState_);
22
+ min,
23
+ max,
24
+ dir,
25
+ onSlideStart,
26
+ onSlideMove,
27
+ onStepKeyDown,
28
+ onSlideEnd,
29
+ ...sliderProps
30
+ } = props;
31
+ const direction = useDirection(dir);
32
+ const isDirectionLTR = direction === "ltr";
33
+ const sliderRef = React.useRef(null);
34
+ const [state, setState_] = React.useState(() => ({
35
+ size: 0,
36
+ offset: 0
37
+ }));
38
+ const setState = useCreateShallowSetState(setState_);
39
39
  function getValueFromPointer(pointerPosition) {
40
- const input = [0, state.size];
41
- return linearScale(input, isDirectionLTR ? [min, max] : [max, min])(pointerPosition);
40
+ return linearScale([0, state.size], isDirectionLTR ? [min, max] : [max, min])(pointerPosition);
42
41
  }
43
42
  const measure = () => {
44
43
  sliderRef.current?.measure((_x, _y, width, _height, pageX, _pageY) => {
@@ -48,7 +47,8 @@ const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
48
47
  });
49
48
  });
50
49
  };
51
- return useSliderMeasure(sliderRef, measure), /* @__PURE__ */jsx(SliderOrientationProvider, {
50
+ useSliderMeasure(sliderRef, measure);
51
+ return /* @__PURE__ */jsx(SliderOrientationProvider, {
52
52
  scope: props.__scopeSlider,
53
53
  startEdge: isDirectionLTR ? "left" : "right",
54
54
  endEdge: isDirectionLTR ? "right" : "left",
@@ -63,15 +63,15 @@ const SliderHorizontal = React.forwardRef((props, forwardedRef) => {
63
63
  onLayout: measure,
64
64
  onSlideStart: (event, target) => {
65
65
  const value = getValueFromPointer(event.nativeEvent.locationX);
66
- value && onSlideStart?.(value, target, event);
66
+ if (value) onSlideStart?.(value, target, event);
67
67
  },
68
68
  onSlideMove: event => {
69
69
  const value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
70
- value && onSlideMove?.(value, event);
70
+ if (value) onSlideMove?.(value, event);
71
71
  },
72
72
  onSlideEnd: event => {
73
73
  const value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
74
- value && onSlideEnd?.(event, value);
74
+ if (value) onSlideEnd?.(event, value);
75
75
  },
76
76
  onStepKeyDown: event => {
77
77
  const isBackKey = BACK_KEYS[direction].includes(event.key);
@@ -87,409 +87,421 @@ function useOnDebouncedWindowResize(callback, amt = 200) {
87
87
  React.useEffect(() => {
88
88
  let last;
89
89
  const onResize = () => {
90
- clearTimeout(last), last = setTimeout(callback, amt);
90
+ clearTimeout(last);
91
+ last = setTimeout(callback, amt);
91
92
  };
92
- return window.addEventListener("resize", onResize), () => {
93
- clearTimeout(last), window.removeEventListener("resize", onResize);
93
+ window.addEventListener("resize", onResize);
94
+ return () => {
95
+ clearTimeout(last);
96
+ window.removeEventListener("resize", onResize);
94
97
  };
95
98
  }, []);
96
99
  }
97
100
  function useSliderMeasure(sliderRef, measure) {
98
- useOnDebouncedWindowResize(measure), React.useEffect(() => {
101
+ useOnDebouncedWindowResize(measure);
102
+ React.useEffect(() => {
99
103
  const node = sliderRef.current;
100
104
  if (!node) return;
101
105
  let measureTm;
102
106
  const debouncedMeasure = () => {
103
- clearTimeout(measureTm), measureTm = setTimeout(() => {
104
- measure();
105
- }, 200);
106
- },
107
- io = new IntersectionObserver(entries => {
108
- debouncedMeasure(), entries?.[0].isIntersecting ? activeSliderMeasureListeners.add(debouncedMeasure) : activeSliderMeasureListeners.delete(debouncedMeasure);
109
- }, {
110
- root: null,
111
- rootMargin: "0px",
112
- threshold: [0, 0.5, 1]
113
- });
114
- return io.observe(node), () => {
115
- activeSliderMeasureListeners.delete(debouncedMeasure), io.disconnect();
107
+ clearTimeout(measureTm);
108
+ measureTm = setTimeout(() => {
109
+ measure();
110
+ }, 200);
111
+ };
112
+ const io = new IntersectionObserver(entries => {
113
+ debouncedMeasure();
114
+ if (entries?.[0].isIntersecting) activeSliderMeasureListeners.add(debouncedMeasure);else activeSliderMeasureListeners.delete(debouncedMeasure);
115
+ }, {
116
+ root: null,
117
+ rootMargin: "0px",
118
+ threshold: [0, .5, 1]
119
+ });
120
+ io.observe(node);
121
+ return () => {
122
+ activeSliderMeasureListeners.delete(debouncedMeasure);
123
+ io.disconnect();
116
124
  };
117
125
  }, []);
118
126
  }
119
127
  const SliderVertical = React.forwardRef((props, forwardedRef) => {
120
- const {
121
- min,
122
- max,
123
- onSlideStart,
124
- onSlideMove,
125
- onStepKeyDown,
126
- onSlideEnd,
127
- ...sliderProps
128
- } = props,
129
- [state, setState_] = React.useState(() => ({
130
- size: 0,
131
- offset: 0
132
- })),
133
- setState = useCreateShallowSetState(setState_),
134
- sliderRef = React.useRef(null),
135
- configuration = useConfiguration(),
136
- insets = isIos && configuration.insets ? configuration.insets : {
137
- top: 0,
138
- bottom: 0
139
- };
140
- function getValueFromPointer(pointerPosition) {
141
- const input = [0, state.size];
142
- return linearScale(input, [max, min])(pointerPosition);
143
- }
144
- const measure = () => {
145
- sliderRef.current?.measure((_x, _y, _width, height, _pageX, pageY) => {
146
- setState({
147
- size: height,
148
- offset: pageY + (isIos ? insets.top : 0)
149
- });
128
+ const {
129
+ min,
130
+ max,
131
+ onSlideStart,
132
+ onSlideMove,
133
+ onStepKeyDown,
134
+ onSlideEnd,
135
+ ...sliderProps
136
+ } = props;
137
+ const [state, setState_] = React.useState(() => ({
138
+ size: 0,
139
+ offset: 0
140
+ }));
141
+ const setState = useCreateShallowSetState(setState_);
142
+ const sliderRef = React.useRef(null);
143
+ const configuration = useConfiguration();
144
+ const insets = isIos && configuration.insets ? configuration.insets : {
145
+ top: 0,
146
+ bottom: 0
147
+ };
148
+ function getValueFromPointer(pointerPosition) {
149
+ return linearScale([0, state.size], [max, min])(pointerPosition);
150
+ }
151
+ const measure = () => {
152
+ sliderRef.current?.measure((_x, _y, _width, height, _pageX, pageY) => {
153
+ setState({
154
+ size: height,
155
+ offset: pageY + (isIos ? insets.top : 0)
150
156
  });
151
- };
152
- return useSliderMeasure(sliderRef, measure), /* @__PURE__ */jsx(SliderOrientationProvider, {
153
- scope: props.__scopeSlider,
154
- startEdge: "bottom",
155
- endEdge: "top",
156
- sizeProp: "height",
157
- size: state.size,
158
- direction: 1,
159
- children: /* @__PURE__ */jsx(SliderImpl, {
160
- ref: composeRefs(forwardedRef, sliderRef),
161
- ...sliderProps,
162
- orientation: "vertical",
163
- onLayout: measure,
164
- onSlideStart: (event, target) => {
165
- const value = getValueFromPointer(event.nativeEvent.locationY);
166
- value && onSlideStart?.(value, target, event);
167
- },
168
- onSlideMove: event => {
169
- const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
170
- value && onSlideMove?.(value, event);
171
- },
172
- onSlideEnd: event => {
173
- const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
174
- onSlideEnd?.(event, value);
175
- },
176
- onStepKeyDown: event => {
177
- const isBackKey = BACK_KEYS.ltr.includes(event.key);
178
- onStepKeyDown?.({
179
- event,
180
- direction: isBackKey ? -1 : 1
181
- });
182
- }
183
- })
184
157
  });
185
- }),
186
- SliderTrackFrame = styled(SliderFrame, {
187
- name: "Slider",
188
- variants: {
189
- unstyled: {
190
- false: {
191
- height: "100%",
192
- width: "100%",
193
- backgroundColor: "$background",
194
- position: "relative",
195
- borderRadius: 1e5,
196
- overflow: "hidden"
197
- }
158
+ };
159
+ useSliderMeasure(sliderRef, measure);
160
+ return /* @__PURE__ */jsx(SliderOrientationProvider, {
161
+ scope: props.__scopeSlider,
162
+ startEdge: "bottom",
163
+ endEdge: "top",
164
+ sizeProp: "height",
165
+ size: state.size,
166
+ direction: 1,
167
+ children: /* @__PURE__ */jsx(SliderImpl, {
168
+ ref: composeRefs(forwardedRef, sliderRef),
169
+ ...sliderProps,
170
+ orientation: "vertical",
171
+ onLayout: measure,
172
+ onSlideStart: (event, target) => {
173
+ const value = getValueFromPointer(event.nativeEvent.locationY);
174
+ if (value) onSlideStart?.(value, target, event);
175
+ },
176
+ onSlideMove: event => {
177
+ const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
178
+ if (value) onSlideMove?.(value, event);
179
+ },
180
+ onSlideEnd: event => {
181
+ const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
182
+ onSlideEnd?.(event, value);
183
+ },
184
+ onStepKeyDown: event => {
185
+ const isBackKey = BACK_KEYS.ltr.includes(event.key);
186
+ onStepKeyDown?.({
187
+ event,
188
+ direction: isBackKey ? -1 : 1
189
+ });
190
+ }
191
+ })
192
+ });
193
+ });
194
+ const SliderTrackFrame = styled(SliderFrame, {
195
+ name: "Slider",
196
+ variants: {
197
+ unstyled: {
198
+ false: {
199
+ height: "100%",
200
+ width: "100%",
201
+ backgroundColor: "$background",
202
+ position: "relative",
203
+ borderRadius: 1e5,
204
+ overflow: "hidden"
198
205
  }
199
- },
200
- defaultVariants: {
201
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
202
206
  }
203
- }),
204
- SliderTrack = React.forwardRef(function (props, forwardedRef) {
205
- const {
206
- __scopeSlider,
207
- ...trackProps
208
- } = props,
209
- context = useSliderContext(__scopeSlider);
210
- return /* @__PURE__ */jsx(SliderTrackFrame, {
211
- "data-disabled": context.disabled ? "" : void 0,
212
- "data-orientation": context.orientation,
213
- orientation: context.orientation,
214
- size: context.size,
215
- ...trackProps,
216
- ref: forwardedRef
217
- });
218
- }),
219
- SliderActiveFrame = styled(SliderFrame, {
220
- name: "SliderActive",
221
- position: "absolute",
222
- pointerEvents: "box-none",
223
- variants: {
224
- unstyled: {
225
- false: {
226
- backgroundColor: "$background",
227
- borderRadius: 1e5
228
- }
207
+ },
208
+ defaultVariants: {
209
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
210
+ }
211
+ });
212
+ const SliderTrack = React.forwardRef(function SliderTrack2(props, forwardedRef) {
213
+ const {
214
+ __scopeSlider,
215
+ ...trackProps
216
+ } = props;
217
+ const context = useSliderContext(__scopeSlider);
218
+ return /* @__PURE__ */jsx(SliderTrackFrame, {
219
+ "data-disabled": context.disabled ? "" : void 0,
220
+ "data-orientation": context.orientation,
221
+ orientation: context.orientation,
222
+ size: context.size,
223
+ ...trackProps,
224
+ ref: forwardedRef
225
+ });
226
+ });
227
+ const SliderActiveFrame = styled(SliderFrame, {
228
+ name: "SliderActive",
229
+ position: "absolute",
230
+ pointerEvents: "box-none",
231
+ variants: {
232
+ unstyled: {
233
+ false: {
234
+ backgroundColor: "$background",
235
+ borderRadius: 1e5
229
236
  }
230
- },
231
- defaultVariants: {
232
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
233
237
  }
234
- }),
235
- SliderActive = React.forwardRef(function (props, forwardedRef) {
236
- const {
237
- __scopeSlider,
238
- ...rangeProps
239
- } = props,
240
- context = useSliderContext(__scopeSlider),
241
- orientation = useSliderOrientationContext(__scopeSlider),
242
- ref = React.useRef(null),
243
- composedRefs = useComposedRefs(forwardedRef, ref),
244
- valuesCount = context.values.length,
245
- percentages = context.values.map(value => convertValueToPercentage(value, context.min, context.max)),
246
- offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0,
247
- offsetEnd = 100 - Math.max(...percentages);
248
- return /* @__PURE__ */jsx(SliderActiveFrame, {
249
- orientation: context.orientation,
250
- "data-orientation": context.orientation,
251
- "data-disabled": context.disabled ? "" : void 0,
252
- size: context.size,
253
- animateOnly: ["left", "top", "right", "bottom"],
254
- ...rangeProps,
255
- ref: composedRefs,
256
- [orientation.startEdge]: `${offsetStart}%`,
257
- [orientation.endEdge]: `${offsetEnd}%`,
258
- ...(orientation.sizeProp === "width" ? {
259
- height: "100%"
260
- } : {
261
- left: 0,
262
- right: 0
263
- })
264
- });
265
- }),
266
- getThumbSize = val => {
267
- const tokens = getTokens(),
268
- size = typeof val == "number" ? val : getSize(tokens.size[val], {
269
- shift: -1
270
- });
271
- return {
272
- width: size,
273
- height: size,
274
- minWidth: size,
275
- minHeight: size
276
- };
277
238
  },
278
- SliderThumbFrame = styled(ThemeableStack, {
279
- name: "SliderThumb",
280
- variants: {
281
- size: {
282
- "...size": getThumbSize,
283
- ":number": getThumbSize
284
- },
285
- unstyled: {
286
- false: {
287
- position: "absolute",
288
- borderWidth: 2,
289
- borderColor: "$borderColor",
290
- backgroundColor: "$background",
291
- pressStyle: {
292
- backgroundColor: "$backgroundPress",
293
- borderColor: "$borderColorPress"
294
- },
295
- hoverStyle: {
296
- backgroundColor: "$backgroundHover",
297
- borderColor: "$borderColorHover"
298
- },
299
- focusVisibleStyle: {
300
- outlineStyle: "solid",
301
- outlineWidth: 2,
302
- outlineColor: "$outlineColor"
303
- }
239
+ defaultVariants: {
240
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
241
+ }
242
+ });
243
+ const SliderActive = React.forwardRef(function SliderActive2(props, forwardedRef) {
244
+ const {
245
+ __scopeSlider,
246
+ ...rangeProps
247
+ } = props;
248
+ const context = useSliderContext(__scopeSlider);
249
+ const orientation = useSliderOrientationContext(__scopeSlider);
250
+ const composedRefs = useComposedRefs(forwardedRef, React.useRef(null));
251
+ const valuesCount = context.values.length;
252
+ const percentages = context.values.map(value => convertValueToPercentage(value, context.min, context.max));
253
+ const offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0;
254
+ const offsetEnd = 100 - Math.max(...percentages);
255
+ return /* @__PURE__ */jsx(SliderActiveFrame, {
256
+ orientation: context.orientation,
257
+ "data-orientation": context.orientation,
258
+ "data-disabled": context.disabled ? "" : void 0,
259
+ size: context.size,
260
+ animateOnly: ["left", "top", "right", "bottom"],
261
+ ...rangeProps,
262
+ ref: composedRefs,
263
+ [orientation.startEdge]: `${offsetStart}%`,
264
+ [orientation.endEdge]: `${offsetEnd}%`,
265
+ ...(orientation.sizeProp === "width" ? {
266
+ height: "100%"
267
+ } : {
268
+ left: 0,
269
+ right: 0
270
+ })
271
+ });
272
+ });
273
+ const getThumbSize = val => {
274
+ const tokens = getTokens();
275
+ const size = typeof val === "number" ? val : getSize(tokens.size[val], {
276
+ shift: -1
277
+ });
278
+ return {
279
+ width: size,
280
+ height: size,
281
+ minWidth: size,
282
+ minHeight: size
283
+ };
284
+ };
285
+ const SliderThumbFrame = styled(ThemeableStack, {
286
+ name: "SliderThumb",
287
+ variants: {
288
+ size: {
289
+ "...size": getThumbSize,
290
+ ":number": getThumbSize
291
+ },
292
+ unstyled: {
293
+ false: {
294
+ position: "absolute",
295
+ borderWidth: 2,
296
+ borderColor: "$borderColor",
297
+ backgroundColor: "$background",
298
+ pressStyle: {
299
+ backgroundColor: "$backgroundPress",
300
+ borderColor: "$borderColorPress"
301
+ },
302
+ hoverStyle: {
303
+ backgroundColor: "$backgroundHover",
304
+ borderColor: "$borderColorHover"
305
+ },
306
+ focusVisibleStyle: {
307
+ outlineStyle: "solid",
308
+ outlineWidth: 2,
309
+ outlineColor: "$outlineColor"
304
310
  }
305
311
  }
306
- },
307
- defaultVariants: {
308
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
309
312
  }
310
- }),
311
- SliderThumb = SliderThumbFrame.styleable(function (props, forwardedRef) {
312
- const {
313
- __scopeSlider,
314
- index = 0,
315
- circular,
316
- size: sizeProp,
317
- ...thumbProps
318
- } = props,
319
- context = useSliderContext(__scopeSlider),
320
- orientation = useSliderOrientationContext(__scopeSlider),
321
- [thumb, setThumb] = React.useState(null),
322
- composedRefs = useComposedRefs(forwardedRef, setThumb),
323
- value = context.values[index],
324
- percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max),
325
- label = getLabel(index, context.values.length),
326
- sizeIn = sizeProp ?? context.size ?? "$true",
327
- [size, setSize] = React.useState(() => getVariableValue(getThumbSize(sizeIn).width)),
328
- thumbInBoundsOffset = size ? getThumbInBoundsOffset(size, percent, orientation.direction) : 0;
329
- React.useEffect(() => {
330
- if (thumb) return context.thumbs.set(thumb, index), () => {
313
+ },
314
+ defaultVariants: {
315
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
316
+ }
317
+ });
318
+ const SliderThumb = SliderThumbFrame.styleable(function SliderThumb2(props, forwardedRef) {
319
+ const {
320
+ __scopeSlider,
321
+ index = 0,
322
+ circular,
323
+ size: sizeProp,
324
+ ...thumbProps
325
+ } = props;
326
+ const context = useSliderContext(__scopeSlider);
327
+ const orientation = useSliderOrientationContext(__scopeSlider);
328
+ const [thumb, setThumb] = React.useState(null);
329
+ const composedRefs = useComposedRefs(forwardedRef, setThumb);
330
+ const value = context.values[index];
331
+ const percent = value === void 0 ? 0 : convertValueToPercentage(value, context.min, context.max);
332
+ const label = getLabel(index, context.values.length);
333
+ const sizeIn = sizeProp ?? context.size ?? "$true";
334
+ const [size, setSize] = React.useState(() => {
335
+ return getVariableValue(getThumbSize(sizeIn).width);
336
+ });
337
+ const thumbInBoundsOffset = size ? getThumbInBoundsOffset(size, percent, orientation.direction) : 0;
338
+ React.useEffect(() => {
339
+ if (thumb) {
340
+ context.thumbs.set(thumb, index);
341
+ return () => {
331
342
  context.thumbs.delete(thumb);
332
343
  };
333
- }, [thumb, context.thumbs, index]);
334
- const positionalStyles = context.orientation === "horizontal" ? {
335
- x: (thumbInBoundsOffset - size / 2) * orientation.direction,
336
- y: -size / 2,
337
- top: "50%",
338
- ...(size === 0 && {
339
- top: "auto",
340
- bottom: "auto"
341
- })
342
- } : {
343
- x: -size / 2,
344
- y: size / 2,
345
- left: "50%",
346
- ...(size === 0 && {
347
- left: "auto",
348
- right: "auto"
349
- })
350
- };
351
- return /* @__PURE__ */jsx(SliderThumbFrame, {
352
- ref: composedRefs,
353
- role: "slider",
354
- "aria-label": props["aria-label"] || label,
355
- "aria-valuemin": context.min,
356
- "aria-valuenow": value,
357
- "aria-valuemax": context.max,
358
- "aria-orientation": context.orientation,
359
- "data-orientation": context.orientation,
360
- "data-disabled": context.disabled ? "" : void 0,
361
- tabIndex: context.disabled ? void 0 : 0,
362
- animateOnly: ["transform", "left", "top", "right", "bottom"],
363
- ...positionalStyles,
364
- [orientation.startEdge]: `${percent}%`,
365
- size: sizeIn,
366
- circular,
367
- ...thumbProps,
368
- onLayout: e => {
369
- setSize(e.nativeEvent.layout[orientation.sizeProp]);
370
- },
371
- onFocus: composeEventHandlers(props.onFocus, () => {
372
- context.valueIndexToChangeRef.current = index;
373
- })
374
- });
375
- }, {
376
- staticConfig: {
377
- memo: !0
378
344
  }
379
- }),
380
- SliderComponent = React.forwardRef((props, forwardedRef) => {
381
- const {
382
- name,
383
- min = 0,
384
- max = 100,
385
- step = 1,
386
- orientation = "horizontal",
387
- disabled = !1,
388
- minStepsBetweenThumbs = 0,
389
- defaultValue = [min],
390
- value,
391
- onValueChange = () => {},
392
- size: sizeProp,
393
- onSlideEnd,
394
- onSlideMove,
395
- onSlideStart,
396
- ...sliderProps
397
- } = props,
398
- sliderRef = React.useRef(null),
399
- composedRefs = useComposedRefs(sliderRef, forwardedRef),
400
- thumbRefs = React.useRef(/* @__PURE__ */new Map()),
401
- valueIndexToChangeRef = React.useRef(0),
402
- isHorizontal = orientation === "horizontal",
403
- [values = [], setValues] = useControllableState({
404
- prop: value,
405
- defaultProp: defaultValue,
406
- transition: !0,
407
- onChange: value2 => {
408
- updateThumbFocus(valueIndexToChangeRef.current), onValueChange(value2);
409
- }
410
- });
411
- isWeb && React.useEffect(() => {
412
- const node = sliderRef.current;
413
- if (!node) return;
414
- const preventDefault = e => {
415
- e.preventDefault();
416
- };
417
- return node.addEventListener("touchstart", preventDefault), () => {
418
- node.removeEventListener("touchstart", preventDefault);
419
- };
420
- }, []);
421
- function updateThumbFocus(focusIndex) {
422
- if (isWeb) {
423
- for (const [node, index] of thumbRefs.current.entries()) if (index === focusIndex) {
424
- node.focus();
425
- return;
426
- }
427
- }
428
- }
429
- function handleSlideMove(value2, event) {
430
- updateValues(value2, valueIndexToChangeRef.current), onSlideMove?.(event, value2);
345
+ }, [thumb, context.thumbs, index]);
346
+ const positionalStyles = context.orientation === "horizontal" ? {
347
+ x: (thumbInBoundsOffset - size / 2) * orientation.direction,
348
+ y: -size / 2,
349
+ top: "50%",
350
+ ...(size === 0 && {
351
+ top: "auto",
352
+ bottom: "auto"
353
+ })
354
+ } : {
355
+ x: -size / 2,
356
+ y: size / 2,
357
+ left: "50%",
358
+ ...(size === 0 && {
359
+ left: "auto",
360
+ right: "auto"
361
+ })
362
+ };
363
+ return /* @__PURE__ */jsx(SliderThumbFrame, {
364
+ ref: composedRefs,
365
+ role: "slider",
366
+ "aria-label": props["aria-label"] || label,
367
+ "aria-valuemin": context.min,
368
+ "aria-valuenow": value,
369
+ "aria-valuemax": context.max,
370
+ "aria-orientation": context.orientation,
371
+ "data-orientation": context.orientation,
372
+ "data-disabled": context.disabled ? "" : void 0,
373
+ tabIndex: context.disabled ? void 0 : 0,
374
+ animateOnly: ["transform", "left", "top", "right", "bottom"],
375
+ ...positionalStyles,
376
+ [orientation.startEdge]: `${percent}%`,
377
+ size: sizeIn,
378
+ circular,
379
+ ...thumbProps,
380
+ onLayout: e => {
381
+ setSize(e.nativeEvent.layout[orientation.sizeProp]);
382
+ },
383
+ onFocus: composeEventHandlers(props.onFocus, () => {
384
+ context.valueIndexToChangeRef.current = index;
385
+ })
386
+ });
387
+ }, {
388
+ staticConfig: {
389
+ memo: true
390
+ }
391
+ });
392
+ const Slider = withStaticProperties(React.forwardRef((props, forwardedRef) => {
393
+ const {
394
+ name,
395
+ min = 0,
396
+ max = 100,
397
+ step = 1,
398
+ orientation = "horizontal",
399
+ disabled = false,
400
+ minStepsBetweenThumbs = 0,
401
+ defaultValue = [min],
402
+ value,
403
+ onValueChange = () => {},
404
+ size: sizeProp,
405
+ onSlideEnd,
406
+ onSlideMove,
407
+ onSlideStart,
408
+ ...sliderProps
409
+ } = props;
410
+ const sliderRef = React.useRef(null);
411
+ const composedRefs = useComposedRefs(sliderRef, forwardedRef);
412
+ const thumbRefs = React.useRef(/* @__PURE__ */new Map());
413
+ const valueIndexToChangeRef = React.useRef(0);
414
+ const isHorizontal = orientation === "horizontal";
415
+ const [values = [], setValues] = useControllableState({
416
+ prop: value,
417
+ defaultProp: defaultValue,
418
+ transition: true,
419
+ onChange: value2 => {
420
+ updateThumbFocus(valueIndexToChangeRef.current);
421
+ onValueChange(value2);
431
422
  }
432
- function updateValues(value2, atIndex) {
433
- const decimalCount = getDecimalCount(step),
434
- snapToStep = roundValue(Math.round((value2 - min) / step) * step + min, decimalCount),
435
- nextValue = clamp(snapToStep, [min, max]);
436
- setValues((prevValues = []) => {
437
- const nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
438
- return hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step) ? (valueIndexToChangeRef.current = nextValues.indexOf(nextValue), String(nextValues) === String(prevValues) ? prevValues : nextValues) : prevValues;
439
- });
423
+ });
424
+ if (isWeb) React.useEffect(() => {
425
+ const node = sliderRef.current;
426
+ if (!node) return;
427
+ const preventDefault = e => {
428
+ e.preventDefault();
429
+ };
430
+ node.addEventListener("touchstart", preventDefault);
431
+ return () => {
432
+ node.removeEventListener("touchstart", preventDefault);
433
+ };
434
+ }, []);
435
+ function updateThumbFocus(focusIndex) {
436
+ if (!isWeb) return;
437
+ for (const [node, index] of thumbRefs.current.entries()) if (index === focusIndex) {
438
+ node.focus();
439
+ return;
440
440
  }
441
- const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
442
- return /* @__PURE__ */jsx(SliderProvider, {
443
- scope: props.__scopeSlider,
444
- disabled,
441
+ }
442
+ function handleSlideMove(value2, event) {
443
+ updateValues(value2, valueIndexToChangeRef.current);
444
+ onSlideMove?.(event, value2);
445
+ }
446
+ function updateValues(value2, atIndex) {
447
+ const decimalCount = getDecimalCount(step);
448
+ const nextValue = clamp(roundValue(Math.round((value2 - min) / step) * step + min, decimalCount), [min, max]);
449
+ setValues((prevValues = []) => {
450
+ const nextValues = getNextSortedValues(prevValues, nextValue, atIndex);
451
+ if (hasMinStepsBetweenValues(nextValues, minStepsBetweenThumbs * step)) {
452
+ valueIndexToChangeRef.current = nextValues.indexOf(nextValue);
453
+ return String(nextValues) === String(prevValues) ? prevValues : nextValues;
454
+ }
455
+ return prevValues;
456
+ });
457
+ }
458
+ const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
459
+ return /* @__PURE__ */jsx(SliderProvider, {
460
+ scope: props.__scopeSlider,
461
+ disabled,
462
+ min,
463
+ max,
464
+ valueIndexToChangeRef,
465
+ thumbs: thumbRefs.current,
466
+ values,
467
+ orientation,
468
+ size: sizeProp,
469
+ children: /* @__PURE__ */jsx(SliderOriented, {
470
+ "aria-disabled": disabled,
471
+ "data-disabled": disabled ? "" : void 0,
472
+ ...sliderProps,
473
+ ref: composedRefs,
445
474
  min,
446
475
  max,
447
- valueIndexToChangeRef,
448
- thumbs: thumbRefs.current,
449
- values,
450
- orientation,
451
- size: sizeProp,
452
- children: /* @__PURE__ */jsx(SliderOriented, {
453
- "aria-disabled": disabled,
454
- "data-disabled": disabled ? "" : void 0,
455
- ...sliderProps,
456
- ref: composedRefs,
457
- min,
458
- max,
459
- onSlideEnd,
460
- onSlideStart: disabled ? void 0 : (value2, target, event) => {
461
- if (target !== "thumb") {
462
- const closestIndex = getClosestValueIndex(values, value2);
463
- updateValues(value2, closestIndex);
464
- }
465
- onSlideStart?.(event, value2, target);
466
- },
467
- onSlideMove: disabled ? void 0 : handleSlideMove,
468
- onHomeKeyDown: () => !disabled && updateValues(min, 0),
469
- onEndKeyDown: () => !disabled && updateValues(max, values.length - 1),
470
- onStepKeyDown: ({
471
- event,
472
- direction: stepDirection
473
- }) => {
474
- if (!disabled) {
475
- const multiplier = PAGE_KEYS.includes(event.key) || event.shiftKey && ARROW_KEYS.includes(event.key) ? 10 : 1,
476
- atIndex = valueIndexToChangeRef.current,
477
- value2 = values[atIndex],
478
- stepInDirection = step * multiplier * stepDirection;
479
- updateValues(value2 + stepInDirection, atIndex);
480
- }
476
+ onSlideEnd,
477
+ onSlideStart: disabled ? void 0 : (value2, target, event) => {
478
+ if (target !== "thumb") updateValues(value2, getClosestValueIndex(values, value2));
479
+ onSlideStart?.(event, value2, target);
480
+ },
481
+ onSlideMove: disabled ? void 0 : handleSlideMove,
482
+ onHomeKeyDown: () => !disabled && updateValues(min, 0),
483
+ onEndKeyDown: () => !disabled && updateValues(max, values.length - 1),
484
+ onStepKeyDown: ({
485
+ event,
486
+ direction: stepDirection
487
+ }) => {
488
+ if (!disabled) {
489
+ const multiplier = PAGE_KEYS.includes(event.key) || event.shiftKey && ARROW_KEYS.includes(event.key) ? 10 : 1;
490
+ const atIndex = valueIndexToChangeRef.current;
491
+ const value2 = values[atIndex];
492
+ updateValues(value2 + step * multiplier * stepDirection, atIndex);
481
493
  }
482
- })
483
- });
484
- }),
485
- Slider = withStaticProperties(SliderComponent, {
486
- Track: SliderTrack,
487
- TrackActive: SliderActive,
488
- Thumb: SliderThumb
494
+ }
495
+ })
489
496
  });
497
+ }), {
498
+ Track: SliderTrack,
499
+ TrackActive: SliderActive,
500
+ Thumb: SliderThumb
501
+ });
490
502
  Slider.displayName = SLIDER_NAME;
491
- const Track = SliderTrack,
492
- Range = SliderActive,
493
- Thumb = SliderThumb;
503
+ const Track = SliderTrack;
504
+ const Range = SliderActive;
505
+ const Thumb = SliderThumb;
494
506
  export { Range, Slider, SliderActive, SliderActiveFrame, SliderThumb, SliderThumbFrame, SliderTrack, SliderTrackFrame, Thumb, Track };
495
507
  //# sourceMappingURL=Slider.mjs.map