@tamagui/slider 2.7.7 → 3.0.0-beta.643.1

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