@tamagui/slider 1.114.3 → 1.115.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Slider.cjs +509 -0
- package/dist/cjs/SliderImpl.cjs +110 -0
- package/dist/cjs/constants.cjs +51 -0
- package/dist/cjs/{helpers.js → helpers.cjs} +23 -18
- package/dist/cjs/index.cjs +28 -0
- package/dist/cjs/types.cjs +16 -0
- package/package.json +14 -13
- package/dist/cjs/Slider.js +0 -462
- package/dist/cjs/SliderImpl.js +0 -96
- package/dist/cjs/constants.js +0 -40
- package/dist/cjs/index.js +0 -22
- package/dist/cjs/types.js +0 -14
- /package/dist/cjs/{Slider.js.map → Slider.cjs.map} +0 -0
- /package/dist/cjs/{SliderImpl.js.map → SliderImpl.cjs.map} +0 -0
- /package/dist/cjs/{constants.js.map → constants.cjs.map} +0 -0
- /package/dist/cjs/{helpers.js.map → helpers.cjs.map} +0 -0
- /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
- /package/dist/cjs/{types.js.map → types.cjs.map} +0 -0
|
@@ -3,15 +3,21 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
15
21
|
var helpers_exports = {};
|
|
16
22
|
__export(helpers_exports, {
|
|
17
23
|
convertValueToPercentage: () => convertValueToPercentage,
|
|
@@ -33,18 +39,18 @@ function convertValueToPercentage(value, min, max) {
|
|
|
33
39
|
return 100 / (max - min) * (value - min);
|
|
34
40
|
}
|
|
35
41
|
function getLabel(index, totalValues) {
|
|
36
|
-
if (totalValues > 2)
|
|
37
|
-
|
|
38
|
-
if (totalValues === 2)
|
|
39
|
-
return ["Minimum", "Maximum"][index];
|
|
42
|
+
if (totalValues > 2) return `Value ${index + 1} of ${totalValues}`;
|
|
43
|
+
if (totalValues === 2) return ["Minimum", "Maximum"][index];
|
|
40
44
|
}
|
|
41
45
|
function getClosestValueIndex(values, nextValue) {
|
|
42
46
|
if (values.length === 1) return 0;
|
|
43
|
-
const distances = values.map(
|
|
47
|
+
const distances = values.map(value => Math.abs(value - nextValue)),
|
|
48
|
+
closestDistance = Math.min(...distances);
|
|
44
49
|
return distances.indexOf(closestDistance);
|
|
45
50
|
}
|
|
46
51
|
function getThumbInBoundsOffset(width, left, direction) {
|
|
47
|
-
const quarterWidth = width / 4,
|
|
52
|
+
const quarterWidth = width / 4,
|
|
53
|
+
offset = linearScale([0, 50], [0, quarterWidth]);
|
|
48
54
|
return (quarterWidth - offset(left) * direction) * direction;
|
|
49
55
|
}
|
|
50
56
|
function getStepsBetweenValues(values) {
|
|
@@ -58,7 +64,7 @@ function hasMinStepsBetweenValues(values, minStepsBetweenValues) {
|
|
|
58
64
|
return !0;
|
|
59
65
|
}
|
|
60
66
|
function linearScale(input, output) {
|
|
61
|
-
return
|
|
67
|
+
return value => {
|
|
62
68
|
if (input[0] === input[1] || output[0] === output[1]) return output[0];
|
|
63
69
|
const ratio = (output[1] - output[0]) / (input[1] - input[0]);
|
|
64
70
|
return output[0] + ratio * (value - input[0]);
|
|
@@ -70,5 +76,4 @@ function getDecimalCount(value) {
|
|
|
70
76
|
function roundValue(value, decimalCount) {
|
|
71
77
|
const rounder = 10 ** decimalCount;
|
|
72
78
|
return Math.round(value * rounder) / rounder;
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=helpers.js.map
|
|
79
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
},
|
|
18
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
20
|
+
value: !0
|
|
21
|
+
}), mod);
|
|
22
|
+
var src_exports = {};
|
|
23
|
+
__export(src_exports, {
|
|
24
|
+
SliderFrame: () => import_SliderImpl.SliderFrame
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(src_exports);
|
|
27
|
+
__reExport(src_exports, require("./Slider.cjs"), module.exports);
|
|
28
|
+
var import_SliderImpl = require("./SliderImpl.cjs");
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
};
|
|
12
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
13
|
+
value: !0
|
|
14
|
+
}), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/slider",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.115.0",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -29,26 +29,27 @@
|
|
|
29
29
|
"react-native": "./dist/cjs/index.native.js",
|
|
30
30
|
"types": "./types/index.d.ts",
|
|
31
31
|
"import": "./dist/esm/index.mjs",
|
|
32
|
-
"require": "./dist/cjs/index.
|
|
32
|
+
"require": "./dist/cjs/index.cjs",
|
|
33
|
+
"default": "./dist/cjs/index.native.js"
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@tamagui/compose-refs": "1.
|
|
37
|
-
"@tamagui/constants": "1.
|
|
38
|
-
"@tamagui/core": "1.
|
|
39
|
-
"@tamagui/create-context": "1.
|
|
40
|
-
"@tamagui/get-token": "1.
|
|
41
|
-
"@tamagui/helpers": "1.
|
|
42
|
-
"@tamagui/stacks": "1.
|
|
43
|
-
"@tamagui/use-controllable-state": "1.
|
|
44
|
-
"@tamagui/use-debounce": "1.
|
|
45
|
-
"@tamagui/use-direction": "1.
|
|
37
|
+
"@tamagui/compose-refs": "1.115.0",
|
|
38
|
+
"@tamagui/constants": "1.115.0",
|
|
39
|
+
"@tamagui/core": "1.115.0",
|
|
40
|
+
"@tamagui/create-context": "1.115.0",
|
|
41
|
+
"@tamagui/get-token": "1.115.0",
|
|
42
|
+
"@tamagui/helpers": "1.115.0",
|
|
43
|
+
"@tamagui/stacks": "1.115.0",
|
|
44
|
+
"@tamagui/use-controllable-state": "1.115.0",
|
|
45
|
+
"@tamagui/use-debounce": "1.115.0",
|
|
46
|
+
"@tamagui/use-direction": "1.115.0"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
48
49
|
"react": "*"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@tamagui/build": "1.
|
|
52
|
+
"@tamagui/build": "1.115.0",
|
|
52
53
|
"react": "^18.2.0 || ^19.0.0",
|
|
53
54
|
"react-native": "0.74.1"
|
|
54
55
|
},
|
package/dist/cjs/Slider.js
DELETED
|
@@ -1,462 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
-
mod
|
|
22
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
-
var Slider_exports = {};
|
|
24
|
-
__export(Slider_exports, {
|
|
25
|
-
Range: () => Range,
|
|
26
|
-
Slider: () => Slider,
|
|
27
|
-
SliderThumb: () => SliderThumb,
|
|
28
|
-
SliderThumbFrame: () => SliderThumbFrame,
|
|
29
|
-
SliderTrack: () => SliderTrack,
|
|
30
|
-
SliderTrackActive: () => SliderTrackActive,
|
|
31
|
-
SliderTrackActiveFrame: () => SliderTrackActiveFrame,
|
|
32
|
-
SliderTrackFrame: () => SliderTrackFrame,
|
|
33
|
-
Thumb: () => Thumb,
|
|
34
|
-
Track: () => Track
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(Slider_exports);
|
|
37
|
-
var import_compose_refs = require("@tamagui/compose-refs"), import_constants = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_get_token = require("@tamagui/get-token"), import_helpers = require("@tamagui/helpers"), import_helpers2 = require("@tamagui/helpers"), import_stacks = require("@tamagui/stacks"), import_use_controllable_state = require("@tamagui/use-controllable-state"), import_use_direction = require("@tamagui/use-direction"), React = __toESM(require("react")), import_constants2 = require("./constants"), import_helpers3 = require("./helpers"), import_SliderImpl = require("./SliderImpl"), import_jsx_runtime = require("react/jsx-runtime");
|
|
38
|
-
const activeSliderMeasureListeners = /* @__PURE__ */ new Set();
|
|
39
|
-
import_constants.isWeb && import_constants.isClient && (process.env.TAMAGUI_DISABLE_SLIDER_INTERVAL || setInterval?.(
|
|
40
|
-
() => {
|
|
41
|
-
activeSliderMeasureListeners.forEach((cb) => cb());
|
|
42
|
-
},
|
|
43
|
-
// really doesn't need to be super often
|
|
44
|
-
1e3
|
|
45
|
-
));
|
|
46
|
-
const SliderHorizontal = React.forwardRef(
|
|
47
|
-
(props, forwardedRef) => {
|
|
48
|
-
const {
|
|
49
|
-
min,
|
|
50
|
-
max,
|
|
51
|
-
dir,
|
|
52
|
-
onSlideStart,
|
|
53
|
-
onSlideMove,
|
|
54
|
-
onStepKeyDown,
|
|
55
|
-
onSlideEnd,
|
|
56
|
-
...sliderProps
|
|
57
|
-
} = props, direction = (0, import_use_direction.useDirection)(dir), isDirectionLTR = direction === "ltr", sliderRef = React.useRef(null), [state, setState_] = React.useState(() => ({ size: 0, offset: 0 })), setState = (0, import_core.createShallowSetState)(setState_);
|
|
58
|
-
function getValueFromPointer(pointerPosition) {
|
|
59
|
-
const input = [0, state.size];
|
|
60
|
-
return (0, import_helpers3.linearScale)(input, isDirectionLTR ? [min, max] : [max, min])(pointerPosition);
|
|
61
|
-
}
|
|
62
|
-
const measure = () => {
|
|
63
|
-
sliderRef.current?.measure((_x, _y, width, _height, pageX, _pageY) => {
|
|
64
|
-
setState({
|
|
65
|
-
size: width,
|
|
66
|
-
offset: pageX
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
return import_constants.isClient && (useOnDebouncedWindowResize(measure), React.useEffect(() => {
|
|
71
|
-
const node = sliderRef.current;
|
|
72
|
-
if (!node) return;
|
|
73
|
-
let measureTm;
|
|
74
|
-
const debouncedMeasure = () => {
|
|
75
|
-
clearTimeout(measureTm), measureTm = setTimeout(() => {
|
|
76
|
-
measure();
|
|
77
|
-
}, 200);
|
|
78
|
-
}, io = new IntersectionObserver(
|
|
79
|
-
(entries) => {
|
|
80
|
-
debouncedMeasure(), entries?.[0].isIntersecting ? activeSliderMeasureListeners.add(debouncedMeasure) : activeSliderMeasureListeners.delete(debouncedMeasure);
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
root: null,
|
|
84
|
-
// Use the viewport as the container.
|
|
85
|
-
rootMargin: "0px",
|
|
86
|
-
threshold: [0, 0.5, 1]
|
|
87
|
-
}
|
|
88
|
-
);
|
|
89
|
-
return io.observe(node), () => {
|
|
90
|
-
activeSliderMeasureListeners.delete(debouncedMeasure), io.disconnect();
|
|
91
|
-
};
|
|
92
|
-
}, [])), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
93
|
-
import_constants2.SliderOrientationProvider,
|
|
94
|
-
{
|
|
95
|
-
scope: props.__scopeSlider,
|
|
96
|
-
startEdge: isDirectionLTR ? "left" : "right",
|
|
97
|
-
endEdge: isDirectionLTR ? "right" : "left",
|
|
98
|
-
direction: isDirectionLTR ? 1 : -1,
|
|
99
|
-
sizeProp: "width",
|
|
100
|
-
size: state.size,
|
|
101
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
102
|
-
import_SliderImpl.SliderImpl,
|
|
103
|
-
{
|
|
104
|
-
ref: (0, import_compose_refs.composeRefs)(forwardedRef, sliderRef),
|
|
105
|
-
dir: direction,
|
|
106
|
-
...sliderProps,
|
|
107
|
-
orientation: "horizontal",
|
|
108
|
-
onLayout: measure,
|
|
109
|
-
onSlideStart: (event, target) => {
|
|
110
|
-
const value = getValueFromPointer(event.nativeEvent.locationX);
|
|
111
|
-
value && onSlideStart?.(value, target, event);
|
|
112
|
-
},
|
|
113
|
-
onSlideMove: (event) => {
|
|
114
|
-
const value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
|
|
115
|
-
value && onSlideMove?.(value, event);
|
|
116
|
-
},
|
|
117
|
-
onSlideEnd: (event) => {
|
|
118
|
-
const value = getValueFromPointer(event.nativeEvent.pageX - state.offset);
|
|
119
|
-
value && onSlideEnd?.(event, value);
|
|
120
|
-
},
|
|
121
|
-
onStepKeyDown: (event) => {
|
|
122
|
-
const isBackKey = import_constants2.BACK_KEYS[direction].includes(event.key);
|
|
123
|
-
onStepKeyDown?.({ event, direction: isBackKey ? -1 : 1 });
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
)
|
|
127
|
-
}
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
function useOnDebouncedWindowResize(callback, amt = 200) {
|
|
132
|
-
React.useEffect(() => {
|
|
133
|
-
let last;
|
|
134
|
-
const onResize = () => {
|
|
135
|
-
clearTimeout(last), last = setTimeout(callback, amt);
|
|
136
|
-
};
|
|
137
|
-
return window.addEventListener("resize", onResize), () => {
|
|
138
|
-
clearTimeout(last), window.removeEventListener("resize", onResize);
|
|
139
|
-
};
|
|
140
|
-
}, []);
|
|
141
|
-
}
|
|
142
|
-
const SliderVertical = React.forwardRef(
|
|
143
|
-
(props, forwardedRef) => {
|
|
144
|
-
const {
|
|
145
|
-
min,
|
|
146
|
-
max,
|
|
147
|
-
onSlideStart,
|
|
148
|
-
onSlideMove,
|
|
149
|
-
onStepKeyDown,
|
|
150
|
-
onSlideEnd,
|
|
151
|
-
...sliderProps
|
|
152
|
-
} = props, [state, setState_] = React.useState(() => ({ size: 0, offset: 0 })), setState = (0, import_core.createShallowSetState)(setState_), sliderRef = React.useRef(null);
|
|
153
|
-
function getValueFromPointer(pointerPosition) {
|
|
154
|
-
const input = [0, state.size];
|
|
155
|
-
return (0, import_helpers3.linearScale)(input, [max, min])(pointerPosition);
|
|
156
|
-
}
|
|
157
|
-
const measure = () => {
|
|
158
|
-
sliderRef.current?.measure((_x, _y, _width, height, _pageX, pageY) => {
|
|
159
|
-
setState({
|
|
160
|
-
size: height,
|
|
161
|
-
offset: pageY
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
};
|
|
165
|
-
return import_constants.isClient && useOnDebouncedWindowResize(measure), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
166
|
-
import_constants2.SliderOrientationProvider,
|
|
167
|
-
{
|
|
168
|
-
scope: props.__scopeSlider,
|
|
169
|
-
startEdge: "bottom",
|
|
170
|
-
endEdge: "top",
|
|
171
|
-
sizeProp: "height",
|
|
172
|
-
size: state.size,
|
|
173
|
-
direction: 1,
|
|
174
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
175
|
-
import_SliderImpl.SliderImpl,
|
|
176
|
-
{
|
|
177
|
-
ref: (0, import_compose_refs.composeRefs)(forwardedRef, sliderRef),
|
|
178
|
-
...sliderProps,
|
|
179
|
-
orientation: "vertical",
|
|
180
|
-
onLayout: measure,
|
|
181
|
-
onSlideStart: (event, target) => {
|
|
182
|
-
const value = getValueFromPointer(event.nativeEvent.locationY);
|
|
183
|
-
value && onSlideStart?.(value, target, event);
|
|
184
|
-
},
|
|
185
|
-
onSlideMove: (event) => {
|
|
186
|
-
const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
|
|
187
|
-
value && onSlideMove?.(value, event);
|
|
188
|
-
},
|
|
189
|
-
onSlideEnd: (event) => {
|
|
190
|
-
const value = getValueFromPointer(event.nativeEvent.pageY - state.offset);
|
|
191
|
-
onSlideEnd?.(event, value);
|
|
192
|
-
},
|
|
193
|
-
onStepKeyDown: (event) => {
|
|
194
|
-
const isBackKey = import_constants2.BACK_KEYS.ltr.includes(event.key);
|
|
195
|
-
onStepKeyDown?.({ event, direction: isBackKey ? -1 : 1 });
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
)
|
|
199
|
-
}
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
), TRACK_NAME = "SliderTrack", SliderTrackFrame = (0, import_core.styled)(import_SliderImpl.SliderFrame, {
|
|
203
|
-
name: "SliderTrack",
|
|
204
|
-
variants: {
|
|
205
|
-
unstyled: {
|
|
206
|
-
false: {
|
|
207
|
-
height: "100%",
|
|
208
|
-
width: "100%",
|
|
209
|
-
backgroundColor: "$background",
|
|
210
|
-
position: "relative",
|
|
211
|
-
borderRadius: 1e5,
|
|
212
|
-
overflow: "hidden"
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
defaultVariants: {
|
|
217
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
218
|
-
}
|
|
219
|
-
}), SliderTrack = React.forwardRef(
|
|
220
|
-
(props, forwardedRef) => {
|
|
221
|
-
const { __scopeSlider, ...trackProps } = props, context = (0, import_constants2.useSliderContext)(TRACK_NAME, __scopeSlider);
|
|
222
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
223
|
-
SliderTrackFrame,
|
|
224
|
-
{
|
|
225
|
-
"data-disabled": context.disabled ? "" : void 0,
|
|
226
|
-
"data-orientation": context.orientation,
|
|
227
|
-
orientation: context.orientation,
|
|
228
|
-
size: context.size,
|
|
229
|
-
...trackProps,
|
|
230
|
-
ref: forwardedRef
|
|
231
|
-
}
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
);
|
|
235
|
-
SliderTrack.displayName = TRACK_NAME;
|
|
236
|
-
const RANGE_NAME = "SliderTrackActive", SliderTrackActiveFrame = (0, import_core.styled)(import_SliderImpl.SliderFrame, {
|
|
237
|
-
name: "SliderTrackActive",
|
|
238
|
-
backgroundColor: "$background",
|
|
239
|
-
position: "absolute"
|
|
240
|
-
}), SliderTrackActive = React.forwardRef(
|
|
241
|
-
(props, forwardedRef) => {
|
|
242
|
-
const { __scopeSlider, ...rangeProps } = props, context = (0, import_constants2.useSliderContext)(RANGE_NAME, __scopeSlider), orientation = (0, import_constants2.useSliderOrientationContext)(RANGE_NAME, __scopeSlider), ref = React.useRef(null), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref), valuesCount = context.values.length, percentages = context.values.map(
|
|
243
|
-
(value) => (0, import_helpers3.convertValueToPercentage)(value, context.min, context.max)
|
|
244
|
-
), offsetStart = valuesCount > 1 ? Math.min(...percentages) : 0, offsetEnd = 100 - Math.max(...percentages);
|
|
245
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
246
|
-
SliderTrackActiveFrame,
|
|
247
|
-
{
|
|
248
|
-
orientation: context.orientation,
|
|
249
|
-
"data-orientation": context.orientation,
|
|
250
|
-
"data-disabled": context.disabled ? "" : void 0,
|
|
251
|
-
size: context.size,
|
|
252
|
-
animateOnly: ["left", "top", "right", "bottom"],
|
|
253
|
-
...rangeProps,
|
|
254
|
-
ref: composedRefs,
|
|
255
|
-
[orientation.startEdge]: `${offsetStart}%`,
|
|
256
|
-
[orientation.endEdge]: `${offsetEnd}%`,
|
|
257
|
-
...orientation.sizeProp === "width" ? {
|
|
258
|
-
height: "100%"
|
|
259
|
-
} : {
|
|
260
|
-
left: 0,
|
|
261
|
-
right: 0
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
);
|
|
267
|
-
SliderTrackActive.displayName = RANGE_NAME;
|
|
268
|
-
const THUMB_NAME = "SliderThumb", getThumbSize = (val) => {
|
|
269
|
-
const tokens = (0, import_core.getTokens)(), size = typeof val == "number" ? val : (0, import_get_token.getSize)(tokens.size[val], {
|
|
270
|
-
shift: -1
|
|
271
|
-
});
|
|
272
|
-
return {
|
|
273
|
-
width: size,
|
|
274
|
-
height: size,
|
|
275
|
-
minWidth: size,
|
|
276
|
-
minHeight: size
|
|
277
|
-
};
|
|
278
|
-
}, SliderThumbFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
|
|
279
|
-
name: "SliderThumb",
|
|
280
|
-
variants: {
|
|
281
|
-
size: {
|
|
282
|
-
"...size": getThumbSize
|
|
283
|
-
},
|
|
284
|
-
unstyled: {
|
|
285
|
-
false: {
|
|
286
|
-
position: "absolute",
|
|
287
|
-
bordered: 2,
|
|
288
|
-
borderWidth: 2,
|
|
289
|
-
backgrounded: !0,
|
|
290
|
-
pressTheme: import_constants.isWeb,
|
|
291
|
-
focusTheme: import_constants.isWeb,
|
|
292
|
-
hoverTheme: import_constants.isWeb
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
defaultVariants: {
|
|
297
|
-
unstyled: process.env.TAMAGUI_HEADLESS === "1"
|
|
298
|
-
}
|
|
299
|
-
}), SliderThumb = React.memo(
|
|
300
|
-
SliderThumbFrame.styleable(function(props, forwardedRef) {
|
|
301
|
-
const { __scopeSlider, index, size: sizeProp, ...thumbProps } = props, context = (0, import_constants2.useSliderContext)(THUMB_NAME, __scopeSlider), orientation = (0, import_constants2.useSliderOrientationContext)(THUMB_NAME, __scopeSlider), [thumb, setThumb] = React.useState(null), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, setThumb), value = context.values[index], percent = value === void 0 ? 0 : (0, import_helpers3.convertValueToPercentage)(value, context.min, context.max), label = (0, import_helpers3.getLabel)(index, context.values.length), sizeIn = sizeProp ?? context.size ?? "$true", [size, setSize] = React.useState(() => (0, import_core.getVariableValue)(getThumbSize(sizeIn).width)), thumbInBoundsOffset = size ? (0, import_helpers3.getThumbInBoundsOffset)(size, percent, orientation.direction) : 0;
|
|
302
|
-
React.useEffect(() => {
|
|
303
|
-
if (thumb)
|
|
304
|
-
return context.thumbs.set(thumb, index), () => {
|
|
305
|
-
context.thumbs.delete(thumb);
|
|
306
|
-
};
|
|
307
|
-
}, [thumb, context.thumbs, index]);
|
|
308
|
-
const positionalStyles = context.orientation === "horizontal" ? {
|
|
309
|
-
x: thumbInBoundsOffset - size / 2,
|
|
310
|
-
y: -size / 2,
|
|
311
|
-
top: "50%",
|
|
312
|
-
...size === 0 && {
|
|
313
|
-
top: "auto",
|
|
314
|
-
bottom: "auto"
|
|
315
|
-
}
|
|
316
|
-
} : {
|
|
317
|
-
x: -size / 2,
|
|
318
|
-
y: size / 2,
|
|
319
|
-
left: "50%",
|
|
320
|
-
...size === 0 && {
|
|
321
|
-
left: "auto",
|
|
322
|
-
right: "auto"
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
326
|
-
SliderThumbFrame,
|
|
327
|
-
{
|
|
328
|
-
ref: composedRefs,
|
|
329
|
-
role: "slider",
|
|
330
|
-
"aria-label": props["aria-label"] || label,
|
|
331
|
-
"aria-valuemin": context.min,
|
|
332
|
-
"aria-valuenow": value,
|
|
333
|
-
"aria-valuemax": context.max,
|
|
334
|
-
"aria-orientation": context.orientation,
|
|
335
|
-
"data-orientation": context.orientation,
|
|
336
|
-
"data-disabled": context.disabled ? "" : void 0,
|
|
337
|
-
tabIndex: context.disabled ? void 0 : 0,
|
|
338
|
-
animateOnly: ["transform", "left", "top", "right", "bottom"],
|
|
339
|
-
...positionalStyles,
|
|
340
|
-
[orientation.startEdge]: `${percent}%`,
|
|
341
|
-
size: sizeIn,
|
|
342
|
-
...thumbProps,
|
|
343
|
-
onLayout: (e) => {
|
|
344
|
-
setSize(e.nativeEvent.layout[orientation.sizeProp]);
|
|
345
|
-
},
|
|
346
|
-
onFocus: (0, import_helpers2.composeEventHandlers)(props.onFocus, () => {
|
|
347
|
-
context.valueIndexToChangeRef.current = index;
|
|
348
|
-
})
|
|
349
|
-
}
|
|
350
|
-
);
|
|
351
|
-
})
|
|
352
|
-
), SliderComponent = React.forwardRef(
|
|
353
|
-
(props, forwardedRef) => {
|
|
354
|
-
const {
|
|
355
|
-
name,
|
|
356
|
-
min = 0,
|
|
357
|
-
max = 100,
|
|
358
|
-
step = 1,
|
|
359
|
-
orientation = "horizontal",
|
|
360
|
-
disabled = !1,
|
|
361
|
-
minStepsBetweenThumbs = 0,
|
|
362
|
-
defaultValue = [min],
|
|
363
|
-
value,
|
|
364
|
-
onValueChange = () => {
|
|
365
|
-
},
|
|
366
|
-
size: sizeProp,
|
|
367
|
-
onSlideEnd,
|
|
368
|
-
onSlideMove,
|
|
369
|
-
onSlideStart,
|
|
370
|
-
...sliderProps
|
|
371
|
-
} = props, sliderRef = React.useRef(null), composedRefs = (0, import_compose_refs.useComposedRefs)(sliderRef, forwardedRef), thumbRefs = React.useRef(/* @__PURE__ */ new Map()), valueIndexToChangeRef = React.useRef(0), isHorizontal = orientation === "horizontal", [values = [], setValues] = (0, import_use_controllable_state.useControllableState)({
|
|
372
|
-
prop: value,
|
|
373
|
-
defaultProp: defaultValue,
|
|
374
|
-
transition: !0,
|
|
375
|
-
onChange: (value2) => {
|
|
376
|
-
updateThumbFocus(valueIndexToChangeRef.current), onValueChange(value2);
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
import_constants.isWeb && React.useEffect(() => {
|
|
380
|
-
const node = sliderRef.current;
|
|
381
|
-
if (!node) return;
|
|
382
|
-
const preventDefault = (e) => {
|
|
383
|
-
e.preventDefault();
|
|
384
|
-
};
|
|
385
|
-
return node.addEventListener("touchstart", preventDefault), () => {
|
|
386
|
-
node.removeEventListener("touchstart", preventDefault);
|
|
387
|
-
};
|
|
388
|
-
}, []);
|
|
389
|
-
function updateThumbFocus(focusIndex) {
|
|
390
|
-
if (import_constants.isWeb) {
|
|
391
|
-
for (const [node, index] of thumbRefs.current.entries())
|
|
392
|
-
if (index === focusIndex) {
|
|
393
|
-
node.focus();
|
|
394
|
-
return;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
function handleSlideMove(value2, event) {
|
|
399
|
-
updateValues(value2, valueIndexToChangeRef.current), onSlideMove?.(event, value2);
|
|
400
|
-
}
|
|
401
|
-
function updateValues(value2, atIndex) {
|
|
402
|
-
const decimalCount = (0, import_helpers3.getDecimalCount)(step), snapToStep = (0, import_helpers3.roundValue)(
|
|
403
|
-
Math.round((value2 - min) / step) * step + min,
|
|
404
|
-
decimalCount
|
|
405
|
-
), nextValue = (0, import_helpers2.clamp)(snapToStep, [min, max]);
|
|
406
|
-
setValues((prevValues = []) => {
|
|
407
|
-
const nextValues = (0, import_helpers3.getNextSortedValues)(prevValues, nextValue, atIndex);
|
|
408
|
-
return (0, import_helpers3.hasMinStepsBetweenValues)(nextValues, minStepsBetweenThumbs * step) ? (valueIndexToChangeRef.current = nextValues.indexOf(nextValue), String(nextValues) === String(prevValues) ? prevValues : nextValues) : prevValues;
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
const SliderOriented = isHorizontal ? SliderHorizontal : SliderVertical;
|
|
412
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
413
|
-
import_constants2.SliderProvider,
|
|
414
|
-
{
|
|
415
|
-
scope: props.__scopeSlider,
|
|
416
|
-
disabled,
|
|
417
|
-
min,
|
|
418
|
-
max,
|
|
419
|
-
valueIndexToChangeRef,
|
|
420
|
-
thumbs: thumbRefs.current,
|
|
421
|
-
values,
|
|
422
|
-
orientation,
|
|
423
|
-
size: sizeProp,
|
|
424
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
425
|
-
SliderOriented,
|
|
426
|
-
{
|
|
427
|
-
"aria-disabled": disabled,
|
|
428
|
-
"data-disabled": disabled ? "" : void 0,
|
|
429
|
-
...sliderProps,
|
|
430
|
-
ref: composedRefs,
|
|
431
|
-
min,
|
|
432
|
-
max,
|
|
433
|
-
onSlideEnd,
|
|
434
|
-
onSlideStart: disabled ? void 0 : (value2, target, event) => {
|
|
435
|
-
if (target !== "thumb") {
|
|
436
|
-
const closestIndex = (0, import_helpers3.getClosestValueIndex)(values, value2);
|
|
437
|
-
updateValues(value2, closestIndex);
|
|
438
|
-
}
|
|
439
|
-
onSlideStart?.(event, value2, target);
|
|
440
|
-
},
|
|
441
|
-
onSlideMove: disabled ? void 0 : handleSlideMove,
|
|
442
|
-
onHomeKeyDown: () => !disabled && updateValues(min, 0),
|
|
443
|
-
onEndKeyDown: () => !disabled && updateValues(max, values.length - 1),
|
|
444
|
-
onStepKeyDown: ({ event, direction: stepDirection }) => {
|
|
445
|
-
if (!disabled) {
|
|
446
|
-
const multiplier = import_constants2.PAGE_KEYS.includes(event.key) || event.shiftKey && import_constants2.ARROW_KEYS.includes(event.key) ? 10 : 1, atIndex = valueIndexToChangeRef.current, value2 = values[atIndex], stepInDirection = step * multiplier * stepDirection;
|
|
447
|
-
updateValues(value2 + stepInDirection, atIndex);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
)
|
|
452
|
-
}
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
|
-
), Slider = (0, import_helpers.withStaticProperties)(SliderComponent, {
|
|
456
|
-
Track: SliderTrack,
|
|
457
|
-
TrackActive: SliderTrackActive,
|
|
458
|
-
Thumb: SliderThumb
|
|
459
|
-
});
|
|
460
|
-
Slider.displayName = import_constants2.SLIDER_NAME;
|
|
461
|
-
const Track = SliderTrack, Range = SliderTrackActive, Thumb = SliderThumb;
|
|
462
|
-
//# sourceMappingURL=Slider.js.map
|