@react-stately/slider 3.2.5-nightly.3698 → 3.2.5-nightly.3705
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/import.mjs +167 -0
- package/package.json +12 -7
package/dist/import.mjs
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import {snapValueToStep as $aTwux$snapValueToStep, clamp as $aTwux$clamp} from "@react-aria/utils";
|
|
2
|
+
import {useControlledState as $aTwux$useControlledState} from "@react-stately/utils";
|
|
3
|
+
import {useMemo as $aTwux$useMemo, useState as $aTwux$useState, useRef as $aTwux$useRef} from "react";
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
7
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
+
* governing permissions and limitations under the License.
|
|
15
|
+
*/ /*
|
|
16
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
17
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
18
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
19
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
20
|
+
*
|
|
21
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
22
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
23
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
24
|
+
* governing permissions and limitations under the License.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
const $28f99e3e86e6ec45$var$DEFAULT_MIN_VALUE = 0;
|
|
29
|
+
const $28f99e3e86e6ec45$var$DEFAULT_MAX_VALUE = 100;
|
|
30
|
+
const $28f99e3e86e6ec45$var$DEFAULT_STEP_VALUE = 1;
|
|
31
|
+
function $28f99e3e86e6ec45$export$e5fda3247f5d67f9(props) {
|
|
32
|
+
const { isDisabled: isDisabled = false , minValue: minValue = $28f99e3e86e6ec45$var$DEFAULT_MIN_VALUE , maxValue: maxValue = $28f99e3e86e6ec45$var$DEFAULT_MAX_VALUE , numberFormatter: formatter , step: step = $28f99e3e86e6ec45$var$DEFAULT_STEP_VALUE , orientation: orientation = "horizontal" } = props;
|
|
33
|
+
// Page step should be at least equal to step and always a multiple of the step.
|
|
34
|
+
let pageSize = (0, $aTwux$useMemo)(()=>{
|
|
35
|
+
let calcPageSize = (maxValue - minValue) / 10;
|
|
36
|
+
calcPageSize = (0, $aTwux$snapValueToStep)(calcPageSize, 0, calcPageSize + step, step);
|
|
37
|
+
return Math.max(calcPageSize, step);
|
|
38
|
+
}, [
|
|
39
|
+
step,
|
|
40
|
+
maxValue,
|
|
41
|
+
minValue
|
|
42
|
+
]);
|
|
43
|
+
let value = (0, $aTwux$useMemo)(()=>$28f99e3e86e6ec45$var$convertValue(props.value), [
|
|
44
|
+
props.value
|
|
45
|
+
]);
|
|
46
|
+
var _convertValue;
|
|
47
|
+
let defaultValue = (0, $aTwux$useMemo)(()=>(_convertValue = $28f99e3e86e6ec45$var$convertValue(props.defaultValue)) !== null && _convertValue !== void 0 ? _convertValue : [
|
|
48
|
+
minValue
|
|
49
|
+
], [
|
|
50
|
+
props.defaultValue,
|
|
51
|
+
minValue
|
|
52
|
+
]);
|
|
53
|
+
let onChange = $28f99e3e86e6ec45$var$createOnChange(props.value, props.defaultValue, props.onChange);
|
|
54
|
+
let onChangeEnd = $28f99e3e86e6ec45$var$createOnChange(props.value, props.defaultValue, props.onChangeEnd);
|
|
55
|
+
const [values, setValues] = (0, $aTwux$useControlledState)(value, defaultValue, onChange);
|
|
56
|
+
const [isDraggings, setDraggings] = (0, $aTwux$useState)(new Array(values.length).fill(false));
|
|
57
|
+
const isEditablesRef = (0, $aTwux$useRef)(new Array(values.length).fill(true));
|
|
58
|
+
const [focusedIndex, setFocusedIndex] = (0, $aTwux$useState)(undefined);
|
|
59
|
+
const valuesRef = (0, $aTwux$useRef)(null);
|
|
60
|
+
valuesRef.current = values;
|
|
61
|
+
const isDraggingsRef = (0, $aTwux$useRef)(null);
|
|
62
|
+
isDraggingsRef.current = isDraggings;
|
|
63
|
+
function getValuePercent(value) {
|
|
64
|
+
return (value - minValue) / (maxValue - minValue);
|
|
65
|
+
}
|
|
66
|
+
function getThumbMinValue(index) {
|
|
67
|
+
return index === 0 ? minValue : values[index - 1];
|
|
68
|
+
}
|
|
69
|
+
function getThumbMaxValue(index) {
|
|
70
|
+
return index === values.length - 1 ? maxValue : values[index + 1];
|
|
71
|
+
}
|
|
72
|
+
function isThumbEditable(index) {
|
|
73
|
+
return isEditablesRef.current[index];
|
|
74
|
+
}
|
|
75
|
+
function setThumbEditable(index, editable) {
|
|
76
|
+
isEditablesRef.current[index] = editable;
|
|
77
|
+
}
|
|
78
|
+
function updateValue(index, value) {
|
|
79
|
+
if (isDisabled || !isThumbEditable(index)) return;
|
|
80
|
+
const thisMin = getThumbMinValue(index);
|
|
81
|
+
const thisMax = getThumbMaxValue(index);
|
|
82
|
+
// Round value to multiple of step, clamp value between min and max
|
|
83
|
+
value = (0, $aTwux$snapValueToStep)(value, thisMin, thisMax, step);
|
|
84
|
+
valuesRef.current = $28f99e3e86e6ec45$var$replaceIndex(valuesRef.current, index, value);
|
|
85
|
+
setValues(valuesRef.current);
|
|
86
|
+
}
|
|
87
|
+
function updateDragging(index, dragging) {
|
|
88
|
+
if (isDisabled || !isThumbEditable(index)) return;
|
|
89
|
+
const wasDragging = isDraggingsRef.current[index];
|
|
90
|
+
isDraggingsRef.current = $28f99e3e86e6ec45$var$replaceIndex(isDraggingsRef.current, index, dragging);
|
|
91
|
+
setDraggings(isDraggingsRef.current);
|
|
92
|
+
// Call onChangeEnd if no handles are dragging.
|
|
93
|
+
if (onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) onChangeEnd(valuesRef.current);
|
|
94
|
+
}
|
|
95
|
+
function getFormattedValue(value) {
|
|
96
|
+
return formatter.format(value);
|
|
97
|
+
}
|
|
98
|
+
function setThumbPercent(index, percent) {
|
|
99
|
+
updateValue(index, getPercentValue(percent));
|
|
100
|
+
}
|
|
101
|
+
function getRoundedValue(value) {
|
|
102
|
+
return Math.round((value - minValue) / step) * step + minValue;
|
|
103
|
+
}
|
|
104
|
+
function getPercentValue(percent) {
|
|
105
|
+
const val = percent * (maxValue - minValue) + minValue;
|
|
106
|
+
return (0, $aTwux$clamp)(getRoundedValue(val), minValue, maxValue);
|
|
107
|
+
}
|
|
108
|
+
function incrementThumb(index, stepSize = 1) {
|
|
109
|
+
let s = Math.max(stepSize, step);
|
|
110
|
+
updateValue(index, (0, $aTwux$snapValueToStep)(values[index] + s, minValue, maxValue, step));
|
|
111
|
+
}
|
|
112
|
+
function decrementThumb(index, stepSize = 1) {
|
|
113
|
+
let s = Math.max(stepSize, step);
|
|
114
|
+
updateValue(index, (0, $aTwux$snapValueToStep)(values[index] - s, minValue, maxValue, step));
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
values: values,
|
|
118
|
+
getThumbValue: (index)=>values[index],
|
|
119
|
+
setThumbValue: updateValue,
|
|
120
|
+
setThumbPercent: setThumbPercent,
|
|
121
|
+
isThumbDragging: (index)=>isDraggings[index],
|
|
122
|
+
setThumbDragging: updateDragging,
|
|
123
|
+
focusedThumb: focusedIndex,
|
|
124
|
+
setFocusedThumb: setFocusedIndex,
|
|
125
|
+
getThumbPercent: (index)=>getValuePercent(values[index]),
|
|
126
|
+
getValuePercent: getValuePercent,
|
|
127
|
+
getThumbValueLabel: (index)=>getFormattedValue(values[index]),
|
|
128
|
+
getFormattedValue: getFormattedValue,
|
|
129
|
+
getThumbMinValue: getThumbMinValue,
|
|
130
|
+
getThumbMaxValue: getThumbMaxValue,
|
|
131
|
+
getPercentValue: getPercentValue,
|
|
132
|
+
isThumbEditable: isThumbEditable,
|
|
133
|
+
setThumbEditable: setThumbEditable,
|
|
134
|
+
incrementThumb: incrementThumb,
|
|
135
|
+
decrementThumb: decrementThumb,
|
|
136
|
+
step: step,
|
|
137
|
+
pageSize: pageSize,
|
|
138
|
+
orientation: orientation,
|
|
139
|
+
isDisabled: isDisabled
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function $28f99e3e86e6ec45$var$replaceIndex(array, index, value) {
|
|
143
|
+
if (array[index] === value) return array;
|
|
144
|
+
return [
|
|
145
|
+
...array.slice(0, index),
|
|
146
|
+
value,
|
|
147
|
+
...array.slice(index + 1)
|
|
148
|
+
];
|
|
149
|
+
}
|
|
150
|
+
function $28f99e3e86e6ec45$var$convertValue(value) {
|
|
151
|
+
if (value == null) return undefined;
|
|
152
|
+
return Array.isArray(value) ? value : [
|
|
153
|
+
value
|
|
154
|
+
];
|
|
155
|
+
}
|
|
156
|
+
function $28f99e3e86e6ec45$var$createOnChange(value, defaultValue, onChange) {
|
|
157
|
+
return (newValue)=>{
|
|
158
|
+
if (typeof value === "number" || typeof defaultValue === "number") onChange === null || onChange === void 0 ? void 0 : onChange(newValue[0]);
|
|
159
|
+
else onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
export {$28f99e3e86e6ec45$export$e5fda3247f5d67f9 as useSliderState};
|
|
167
|
+
//# sourceMappingURL=module.js.map
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/slider",
|
|
3
|
-
"version": "3.2.5-nightly.
|
|
3
|
+
"version": "3.2.5-nightly.3705+93b3c951e",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"module": "dist/module.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"types": "./dist/types.d.ts",
|
|
10
|
+
"import": "./dist/import.mjs",
|
|
11
|
+
"require": "./dist/main.js"
|
|
12
|
+
},
|
|
8
13
|
"types": "dist/types.d.ts",
|
|
9
14
|
"source": "src/index.ts",
|
|
10
15
|
"files": [
|
|
@@ -17,11 +22,11 @@
|
|
|
17
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
18
23
|
},
|
|
19
24
|
"dependencies": {
|
|
20
|
-
"@react-aria/i18n": "3.0.0-nightly.
|
|
21
|
-
"@react-aria/utils": "3.0.0-nightly.
|
|
22
|
-
"@react-stately/utils": "3.0.0-nightly.
|
|
23
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
24
|
-
"@react-types/slider": "3.3.2-nightly.
|
|
25
|
+
"@react-aria/i18n": "3.0.0-nightly.2005+93b3c951e",
|
|
26
|
+
"@react-aria/utils": "3.0.0-nightly.2005+93b3c951e",
|
|
27
|
+
"@react-stately/utils": "3.0.0-nightly.2005+93b3c951e",
|
|
28
|
+
"@react-types/shared": "3.0.0-nightly.2005+93b3c951e",
|
|
29
|
+
"@react-types/slider": "3.3.2-nightly.3705+93b3c951e",
|
|
25
30
|
"@swc/helpers": "^0.4.14"
|
|
26
31
|
},
|
|
27
32
|
"peerDependencies": {
|
|
@@ -30,5 +35,5 @@
|
|
|
30
35
|
"publishConfig": {
|
|
31
36
|
"access": "public"
|
|
32
37
|
},
|
|
33
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "93b3c951eb784b14183f9988f2d188b34de8f42d"
|
|
34
39
|
}
|