@react-stately/slider 3.0.4 → 3.0.6-nightly.3120
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/main.js +35 -23
- package/dist/main.js.map +1 -1
- package/dist/module.js +35 -23
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +12 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/useSliderState.ts +37 -3
package/dist/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
3
|
-
var $
|
|
1
|
+
var $ltQvC$reactariautils = require("@react-aria/utils");
|
|
2
|
+
var $ltQvC$reactstatelyutils = require("@react-stately/utils");
|
|
3
|
+
var $ltQvC$react = require("react");
|
|
4
4
|
|
|
5
5
|
function $parcel$exportWildcard(dest, source) {
|
|
6
6
|
Object.keys(source).forEach(function(key) {
|
|
@@ -21,26 +21,27 @@ function $parcel$exportWildcard(dest, source) {
|
|
|
21
21
|
function $parcel$export(e, n, v, s) {
|
|
22
22
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
23
23
|
}
|
|
24
|
-
var $
|
|
24
|
+
var $e86753598efd0f02$exports = {};
|
|
25
25
|
|
|
26
|
-
$parcel$export($
|
|
26
|
+
$parcel$export($e86753598efd0f02$exports, "useSliderState", () => $e86753598efd0f02$export$e5fda3247f5d67f9);
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
const $
|
|
31
|
-
const $
|
|
32
|
-
const $
|
|
33
|
-
function $
|
|
34
|
-
const { isDisabled: isDisabled , minValue: minValue = $
|
|
35
|
-
|
|
30
|
+
const $e86753598efd0f02$var$DEFAULT_MIN_VALUE = 0;
|
|
31
|
+
const $e86753598efd0f02$var$DEFAULT_MAX_VALUE = 100;
|
|
32
|
+
const $e86753598efd0f02$var$DEFAULT_STEP_VALUE = 1;
|
|
33
|
+
function $e86753598efd0f02$export$e5fda3247f5d67f9(props) {
|
|
34
|
+
const { isDisabled: isDisabled , minValue: minValue = $e86753598efd0f02$var$DEFAULT_MIN_VALUE , maxValue: maxValue = $e86753598efd0f02$var$DEFAULT_MAX_VALUE , numberFormatter: formatter , step: step = $e86753598efd0f02$var$DEFAULT_STEP_VALUE , pageSize: pageSize = Math.max((maxValue - minValue) / 10, step) } = props;
|
|
35
|
+
var _defaultValue;
|
|
36
|
+
const [values, setValues] = $ltQvC$reactstatelyutils.useControlledState(props.value, (_defaultValue = props.defaultValue) !== null && _defaultValue !== void 0 ? _defaultValue : [
|
|
36
37
|
minValue
|
|
37
38
|
], props.onChange);
|
|
38
|
-
const [isDraggings, setDraggings] = $
|
|
39
|
-
const isEditablesRef = $
|
|
40
|
-
const [focusedIndex, setFocusedIndex] = $
|
|
41
|
-
const valuesRef = $
|
|
39
|
+
const [isDraggings, setDraggings] = $ltQvC$react.useState(new Array(values.length).fill(false));
|
|
40
|
+
const isEditablesRef = $ltQvC$react.useRef(new Array(values.length).fill(true));
|
|
41
|
+
const [focusedIndex, setFocusedIndex] = $ltQvC$react.useState(undefined);
|
|
42
|
+
const valuesRef = $ltQvC$react.useRef(null);
|
|
42
43
|
valuesRef.current = values;
|
|
43
|
-
const isDraggingsRef = $
|
|
44
|
+
const isDraggingsRef = $ltQvC$react.useRef(null);
|
|
44
45
|
isDraggingsRef.current = isDraggings;
|
|
45
46
|
function getValuePercent(value) {
|
|
46
47
|
return (value - minValue) / (maxValue - minValue);
|
|
@@ -62,14 +63,14 @@ function $16a7c389e53c069a$export$e5fda3247f5d67f9(props) {
|
|
|
62
63
|
const thisMin = getThumbMinValue(index);
|
|
63
64
|
const thisMax = getThumbMaxValue(index);
|
|
64
65
|
// Round value to multiple of step, clamp value between min and max
|
|
65
|
-
value = $
|
|
66
|
-
valuesRef.current = $
|
|
66
|
+
value = $ltQvC$reactariautils.snapValueToStep(value, thisMin, thisMax, step);
|
|
67
|
+
valuesRef.current = $e86753598efd0f02$var$replaceIndex(valuesRef.current, index, value);
|
|
67
68
|
setValues(valuesRef.current);
|
|
68
69
|
}
|
|
69
70
|
function updateDragging(index, dragging) {
|
|
70
71
|
if (isDisabled || !isThumbEditable(index)) return;
|
|
71
72
|
const wasDragging = isDraggingsRef.current[index];
|
|
72
|
-
isDraggingsRef.current = $
|
|
73
|
+
isDraggingsRef.current = $e86753598efd0f02$var$replaceIndex(isDraggingsRef.current, index, dragging);
|
|
73
74
|
setDraggings(isDraggingsRef.current);
|
|
74
75
|
// Call onChangeEnd if no handles are dragging.
|
|
75
76
|
if (props.onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) props.onChangeEnd(valuesRef.current);
|
|
@@ -85,7 +86,15 @@ function $16a7c389e53c069a$export$e5fda3247f5d67f9(props) {
|
|
|
85
86
|
}
|
|
86
87
|
function getPercentValue(percent) {
|
|
87
88
|
const val = percent * (maxValue - minValue) + minValue;
|
|
88
|
-
return $
|
|
89
|
+
return $ltQvC$reactariautils.clamp(getRoundedValue(val), minValue, maxValue);
|
|
90
|
+
}
|
|
91
|
+
function incrementThumb(index, stepSize = 1) {
|
|
92
|
+
let s = Math.max(stepSize, step);
|
|
93
|
+
updateValue(index, $ltQvC$reactariautils.snapValueToStep(values[index] + s, minValue, maxValue, step));
|
|
94
|
+
}
|
|
95
|
+
function decrementThumb(index, stepSize = 1) {
|
|
96
|
+
let s = Math.max(stepSize, step);
|
|
97
|
+
updateValue(index, $ltQvC$reactariautils.snapValueToStep(values[index] - s, minValue, maxValue, step));
|
|
89
98
|
}
|
|
90
99
|
return {
|
|
91
100
|
values: values,
|
|
@@ -109,10 +118,13 @@ function $16a7c389e53c069a$export$e5fda3247f5d67f9(props) {
|
|
|
109
118
|
getPercentValue: getPercentValue,
|
|
110
119
|
isThumbEditable: isThumbEditable,
|
|
111
120
|
setThumbEditable: setThumbEditable,
|
|
112
|
-
|
|
121
|
+
incrementThumb: incrementThumb,
|
|
122
|
+
decrementThumb: decrementThumb,
|
|
123
|
+
step: step,
|
|
124
|
+
pageSize: pageSize
|
|
113
125
|
};
|
|
114
126
|
}
|
|
115
|
-
function $
|
|
127
|
+
function $e86753598efd0f02$var$replaceIndex(array, index, value) {
|
|
116
128
|
if (array[index] === value) return array;
|
|
117
129
|
return [
|
|
118
130
|
...array.slice(0, index),
|
|
@@ -122,7 +134,7 @@ function $16a7c389e53c069a$var$replaceIndex(array, index, value) {
|
|
|
122
134
|
}
|
|
123
135
|
|
|
124
136
|
|
|
125
|
-
$parcel$exportWildcard(module.exports, $
|
|
137
|
+
$parcel$exportWildcard(module.exports, $e86753598efd0f02$exports);
|
|
126
138
|
|
|
127
139
|
|
|
128
140
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC+HA,KAAK,CAAC,uCAAiB,GAAG,CAAC;AAC3B,KAAK,CAAC,uCAAiB,GAAG,GAAG;AAC7B,KAAK,CAAC,wCAAkB,GAAG,CAAC;SAYZ,yCAAc,CAAC,KAAyB,EAAe,CAAC;IACtE,KAAK,CAAC,CAAC,aAAA,UAAU,aAAE,QAAQ,GAAG,uCAAiB,aAAE,QAAQ,GAAG,uCAAiB,GAAE,eAAe,EAAE,SAAS,SAAE,IAAI,GAAG,wCAAkB,EAAA,CAAC,GAAG,KAAK;IAE7I,KAAK,EAAE,MAAM,EAAE,SAAS,IAAI,2CAAkB,CAC5C,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,YAAY,IAAI,CAAC;QAAA,QAAQ;IAAA,CAAC,EAChC,KAAK,CAAC,QAAQ;IAEhB,KAAK,EAAE,WAAW,EAAE,YAAY,IAAI,qBAAQ,CAAY,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK;IAC3F,KAAK,CAAC,cAAc,GAAG,mBAAM,CAAY,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI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QAC9C,aAAa,EAAE,WAAW;yBAC1B,eAAe;QACf,eAAe,GAAG,KAAa,GAAK,WAAW,CAAC,KAAK;;QACrD,gBAAgB,EAAE,cAAc;QAChC,YAAY,EAAE,YAAY;QAC1B,eAAe,EAAE,eAAe;QAChC,eAAe,GAAG,KAAa,GAAK,eAAe,CAAC,MAAM,CAAC,KAAK;;yBAChE,eAAe;QACf,kBAAkB,GAAG,KAAa,GAAK,iBAAiB,CAAC,MAAM,CAAC,KAAK;;2BACrE,iBAAiB;0BACjB,gBAAgB;0BAChB,gBAAgB;yBAChB,eAAe;yBACf,eAAe;0BACf,gBAAgB;cAChB,IAAI;IACN,CAAC;AACH,CAAC;SAEQ,kCAAY,CAAI,KAAU,EAAE,KAAa,EAAE,KAAQ,EAAE,CAAC;IAC7D,EAAE,EAAE,KAAK,CAAC,KAAK,MAAM,KAAK,EACxB,MAAM,CAAC,KAAK;IAGd,MAAM,CAAC,CAAC;WAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK;QAAG,KAAK;WAAK,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC;IAAC,CAAC;AACrE,CAAC","sources":["packages/@react-stately/slider/src/index.ts","packages/@react-stately/slider/src/useSliderState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useSliderState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '@react-aria/utils';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useRef, useState} from 'react';\n\nexport interface SliderState {\n /**\n * Values managed by the slider by thumb index.\n */\n readonly values: number[],\n /**\n * Get the value for the specified thumb.\n * @param index\n */\n getThumbValue(index: number): number,\n\n /**\n * Sets the value for the specified thumb.\n * The actual value set will be clamped and rounded according to min/max/step.\n * @param index\n * @param value\n */\n setThumbValue(index: number, value: number): void,\n\n /**\n * Sets value for the specified thumb by percent offset (between 0 and 1).\n * @param index\n * @param percent\n */\n setThumbPercent(index: number, percent: number): void,\n\n /**\n * Whether the specific thumb is being dragged.\n * @param index\n */\n isThumbDragging(index: number): boolean,\n /**\n * Set is dragging on the specified thumb.\n * @param index\n * @param dragging\n */\n setThumbDragging(index: number, dragging: boolean): void,\n\n /**\n * Currently-focused thumb index.\n */\n readonly focusedThumb: number | undefined,\n /**\n * Set focused true on specified thumb. This will remove focus from\n * any thumb that had it before.\n * @param index\n */\n setFocusedThumb(index: number | undefined): void,\n\n /**\n * Returns the specified thumb's value as a percentage from 0 to 1.\n * @param index\n */\n getThumbPercent(index: number): number,\n\n /**\n * Returns the value as a percent between the min and max of the slider.\n * @param index\n */\n getValuePercent(value: number): number,\n\n /**\n * Returns the string label for the specified thumb's value, per props.formatOptions.\n * @param index\n */\n getThumbValueLabel(index: number): string,\n\n /**\n * Returns the string label for the value, per props.formatOptions.\n * @param index\n */\n getFormattedValue(value: number): string,\n\n /**\n * Returns the min allowed value for the specified thumb.\n * @param index\n */\n getThumbMinValue(index: number): number,\n\n /**\n * Returns the max allowed value for the specified thumb.\n * @param index\n */\n getThumbMaxValue(index: number): number,\n\n /**\n * Converts a percent along track (between 0 and 1) to the corresponding value.\n * @param percent\n */\n getPercentValue(percent: number): number,\n\n /**\n * Returns if the specified thumb is editable.\n * @param index\n */\n isThumbEditable(index: number): boolean,\n\n /**\n * Set the specified thumb's editable state.\n * @param index\n * @param editable\n */\n setThumbEditable(index: number, editable: boolean): void,\n\n /**\n * The step amount for the slider.\n */\n readonly step: number\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\ninterface SliderStateOptions extends SliderProps {\n numberFormatter: Intl.NumberFormat\n}\n\n/**\n * Provides state management for a slider component. Stores values for all thumbs,\n * formats values for localization, and provides methods to update the position\n * of any thumbs.\n * @param props\n */\nexport function useSliderState(props: SliderStateOptions): SliderState {\n const {isDisabled, minValue = DEFAULT_MIN_VALUE, maxValue = DEFAULT_MAX_VALUE, numberFormatter: formatter, step = DEFAULT_STEP_VALUE} = props;\n\n const [values, setValues] = useControlledState<number[]>(\n props.value as any,\n props.defaultValue ?? [minValue] as any,\n props.onChange as any\n );\n const [isDraggings, setDraggings] = useState<boolean[]>(new Array(values.length).fill(false));\n const isEditablesRef = useRef<boolean[]>(new Array(values.length).fill(true));\n const [focusedIndex, setFocusedIndex] = useState<number | undefined>(undefined);\n\n const valuesRef = useRef<number[]>(null);\n valuesRef.current = values;\n const isDraggingsRef = useRef<boolean[]>(null);\n isDraggingsRef.current = isDraggings;\n\n function getValuePercent(value: number) {\n return (value - minValue) / (maxValue - minValue);\n }\n\n function getThumbMinValue(index: number) {\n return index === 0 ? minValue : values[index - 1];\n }\n function getThumbMaxValue(index: number) {\n return index === values.length - 1 ? maxValue : values[index + 1];\n }\n\n function isThumbEditable(index: number) {\n return isEditablesRef.current[index];\n }\n\n function setThumbEditable(index: number, editable: boolean) {\n isEditablesRef.current[index] = editable;\n }\n\n function updateValue(index: number, value: number) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n const thisMin = getThumbMinValue(index);\n const thisMax = getThumbMaxValue(index);\n\n // Round value to multiple of step, clamp value between min and max\n value = snapValueToStep(value, thisMin, thisMax, step);\n valuesRef.current = replaceIndex(valuesRef.current, index, value);\n setValues(valuesRef.current);\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n\n const wasDragging = isDraggingsRef.current[index];\n isDraggingsRef.current = replaceIndex(isDraggingsRef.current, index, dragging);\n setDraggings(isDraggingsRef.current);\n\n // Call onChangeEnd if no handles are dragging.\n if (props.onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n props.onChangeEnd(valuesRef.current);\n }\n }\n\n function getFormattedValue(value: number) {\n return formatter.format(value);\n }\n\n function setThumbPercent(index: number, percent: number) {\n updateValue(index, getPercentValue(percent));\n }\n\n function getRoundedValue(value: number) {\n return Math.round((value - minValue) / step) * step + minValue;\n }\n\n function getPercentValue(percent: number) {\n const val = percent * (maxValue - minValue) + minValue;\n return clamp(getRoundedValue(val), minValue, maxValue);\n }\n\n return {\n values: values,\n getThumbValue: (index: number) => values[index],\n setThumbValue: updateValue,\n setThumbPercent,\n isThumbDragging: (index: number) => isDraggings[index],\n setThumbDragging: updateDragging,\n focusedThumb: focusedIndex,\n setFocusedThumb: setFocusedIndex,\n getThumbPercent: (index: number) => getValuePercent(values[index]),\n getValuePercent,\n getThumbValueLabel: (index: number) => getFormattedValue(values[index]),\n getFormattedValue,\n getThumbMinValue,\n getThumbMaxValue,\n getPercentValue,\n isThumbEditable,\n setThumbEditable,\n step\n };\n}\n\nfunction replaceIndex<T>(array: T[], index: number, value: T) {\n if (array[index] === value) {\n return array;\n }\n\n return [...array.slice(0, index), value, ...array.slice(index + 1)];\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC6IA,KAAK,CAAC,uCAAiB,GAAG,CAAC;AAC3B,KAAK,CAAC,uCAAiB,GAAG,GAAG;AAC7B,KAAK,CAAC,wCA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,aAAa,GAAG,KAAa,GAAK,MAAM,CAAC,KAAK;;QAC9C,aAAa,EAAE,WAAW;yBAC1B,eAAe;QACf,eAAe,GAAG,KAAa,GAAK,WAAW,CAAC,KAAK;;QACrD,gBAAgB,EAAE,cAAc;QAChC,YAAY,EAAE,YAAY;QAC1B,eAAe,EAAE,eAAe;QAChC,eAAe,GAAG,KAAa,GAAK,eAAe,CAAC,MAAM,CAAC,KAAK;;yBAChE,eAAe;QACf,kBAAkB,GAAG,KAAa,GAAK,iBAAiB,CAAC,MAAM,CAAC,KAAK;;2BACrE,iBAAiB;0BACjB,gBAAgB;0BAChB,gBAAgB;yBAChB,eAAe;yBACf,eAAe;0BACf,gBAAgB;wBAChB,cAAc;wBACd,cAAc;cACd,IAAI;kBACJ,QAAQ;IACV,CAAC;AACH,CAAC;SAEQ,kCAAY,CAAI,KAAU,EAAE,KAAa,EAAE,KAAQ,EAAE,CAAC;IAC7D,EAAE,EAAE,KAAK,CAAC,KAAK,MAAM,KAAK,EACxB,MAAM,CAAC,KAAK;IAGd,MAAM,CAAC,CAAC;WAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK;QAAG,KAAK;WAAK,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC;IAAC,CAAC;AACrE,CAAC","sources":["packages/@react-stately/slider/src/index.ts","packages/@react-stately/slider/src/useSliderState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useSliderState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '@react-aria/utils';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useRef, useState} from 'react';\n\nexport interface SliderState {\n /**\n * Values managed by the slider by thumb index.\n */\n readonly values: number[],\n /**\n * Get the value for the specified thumb.\n * @param index\n */\n getThumbValue(index: number): number,\n\n /**\n * Sets the value for the specified thumb.\n * The actual value set will be clamped and rounded according to min/max/step.\n * @param index\n * @param value\n */\n setThumbValue(index: number, value: number): void,\n\n /**\n * Sets value for the specified thumb by percent offset (between 0 and 1).\n * @param index\n * @param percent\n */\n setThumbPercent(index: number, percent: number): void,\n\n /**\n * Whether the specific thumb is being dragged.\n * @param index\n */\n isThumbDragging(index: number): boolean,\n /**\n * Set is dragging on the specified thumb.\n * @param index\n * @param dragging\n */\n setThumbDragging(index: number, dragging: boolean): void,\n\n /**\n * Currently-focused thumb index.\n */\n readonly focusedThumb: number | undefined,\n /**\n * Set focused true on specified thumb. This will remove focus from\n * any thumb that had it before.\n * @param index\n */\n setFocusedThumb(index: number | undefined): void,\n\n /**\n * Returns the specified thumb's value as a percentage from 0 to 1.\n * @param index\n */\n getThumbPercent(index: number): number,\n\n /**\n * Returns the value as a percent between the min and max of the slider.\n * @param index\n */\n getValuePercent(value: number): number,\n\n /**\n * Returns the string label for the specified thumb's value, per props.formatOptions.\n * @param index\n */\n getThumbValueLabel(index: number): string,\n\n /**\n * Returns the string label for the value, per props.formatOptions.\n * @param index\n */\n getFormattedValue(value: number): string,\n\n /**\n * Returns the min allowed value for the specified thumb.\n * @param index\n */\n getThumbMinValue(index: number): number,\n\n /**\n * Returns the max allowed value for the specified thumb.\n * @param index\n */\n getThumbMaxValue(index: number): number,\n\n /**\n * Converts a percent along track (between 0 and 1) to the corresponding value.\n * @param percent\n */\n getPercentValue(percent: number): number,\n\n /**\n * Returns if the specified thumb is editable.\n * @param index\n */\n isThumbEditable(index: number): boolean,\n\n /**\n * Set the specified thumb's editable state.\n * @param index\n * @param editable\n */\n setThumbEditable(index: number, editable: boolean): void,\n\n /**\n * Increments the value of the thumb by the step or page amount.\n */\n incrementThumb(index: number, stepSize?: number): void,\n /**\n * Decrements the value of the thumb by the step or page amount.\n */\n decrementThumb(index: number, stepSize?: number): void,\n\n /**\n * The step amount for the slider.\n */\n readonly step: number,\n\n /**\n * The page size for the slider, used to do a bigger step.\n */\n readonly pageSize: number\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\ninterface SliderStateOptions extends SliderProps {\n numberFormatter: Intl.NumberFormat\n}\n\n/**\n * Provides state management for a slider component. Stores values for all thumbs,\n * formats values for localization, and provides methods to update the position\n * of any thumbs.\n * @param props\n */\nexport function useSliderState(props: SliderStateOptions): SliderState {\n const {\n isDisabled,\n minValue = DEFAULT_MIN_VALUE,\n maxValue = DEFAULT_MAX_VALUE,\n numberFormatter: formatter,\n step = DEFAULT_STEP_VALUE,\n pageSize = Math.max((maxValue - minValue) / 10, step)\n } = props;\n\n const [values, setValues] = useControlledState<number[]>(\n props.value as any,\n props.defaultValue ?? [minValue] as any,\n props.onChange as any\n );\n const [isDraggings, setDraggings] = useState<boolean[]>(new Array(values.length).fill(false));\n const isEditablesRef = useRef<boolean[]>(new Array(values.length).fill(true));\n const [focusedIndex, setFocusedIndex] = useState<number | undefined>(undefined);\n\n const valuesRef = useRef<number[]>(null);\n valuesRef.current = values;\n const isDraggingsRef = useRef<boolean[]>(null);\n isDraggingsRef.current = isDraggings;\n\n function getValuePercent(value: number) {\n return (value - minValue) / (maxValue - minValue);\n }\n\n function getThumbMinValue(index: number) {\n return index === 0 ? minValue : values[index - 1];\n }\n function getThumbMaxValue(index: number) {\n return index === values.length - 1 ? maxValue : values[index + 1];\n }\n\n function isThumbEditable(index: number) {\n return isEditablesRef.current[index];\n }\n\n function setThumbEditable(index: number, editable: boolean) {\n isEditablesRef.current[index] = editable;\n }\n\n function updateValue(index: number, value: number) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n const thisMin = getThumbMinValue(index);\n const thisMax = getThumbMaxValue(index);\n\n // Round value to multiple of step, clamp value between min and max\n value = snapValueToStep(value, thisMin, thisMax, step);\n valuesRef.current = replaceIndex(valuesRef.current, index, value);\n setValues(valuesRef.current);\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n\n const wasDragging = isDraggingsRef.current[index];\n isDraggingsRef.current = replaceIndex(isDraggingsRef.current, index, dragging);\n setDraggings(isDraggingsRef.current);\n\n // Call onChangeEnd if no handles are dragging.\n if (props.onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n props.onChangeEnd(valuesRef.current);\n }\n }\n\n function getFormattedValue(value: number) {\n return formatter.format(value);\n }\n\n function setThumbPercent(index: number, percent: number) {\n updateValue(index, getPercentValue(percent));\n }\n\n function getRoundedValue(value: number) {\n return Math.round((value - minValue) / step) * step + minValue;\n }\n\n function getPercentValue(percent: number) {\n const val = percent * (maxValue - minValue) + minValue;\n return clamp(getRoundedValue(val), minValue, maxValue);\n }\n\n function incrementThumb(index: number, stepSize: number = 1) {\n let s = Math.max(stepSize, step);\n updateValue(index, snapValueToStep(values[index] + s, minValue, maxValue, step));\n }\n\n function decrementThumb(index: number, stepSize: number = 1) {\n let s = Math.max(stepSize, step);\n updateValue(index, snapValueToStep(values[index] - s, minValue, maxValue, step));\n }\n\n return {\n values: values,\n getThumbValue: (index: number) => values[index],\n setThumbValue: updateValue,\n setThumbPercent,\n isThumbDragging: (index: number) => isDraggings[index],\n setThumbDragging: updateDragging,\n focusedThumb: focusedIndex,\n setFocusedThumb: setFocusedIndex,\n getThumbPercent: (index: number) => getValuePercent(values[index]),\n getValuePercent,\n getThumbValueLabel: (index: number) => getFormattedValue(values[index]),\n getFormattedValue,\n getThumbMinValue,\n getThumbMaxValue,\n getPercentValue,\n isThumbEditable,\n setThumbEditable,\n incrementThumb,\n decrementThumb,\n step,\n pageSize\n };\n}\n\nfunction replaceIndex<T>(array: T[], index: number, value: T) {\n if (array[index] === value) {\n return array;\n }\n\n return [...array.slice(0, index), value, ...array.slice(index + 1)];\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
|
-
import {snapValueToStep as $
|
|
2
|
-
import {useControlledState as $
|
|
3
|
-
import {useState as $
|
|
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 {useState as $aTwux$useState, useRef as $aTwux$useRef} from "react";
|
|
4
4
|
|
|
5
5
|
function $parcel$export(e, n, v, s) {
|
|
6
6
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
7
|
}
|
|
8
|
-
var $
|
|
8
|
+
var $28f99e3e86e6ec45$exports = {};
|
|
9
9
|
|
|
10
|
-
$parcel$export($
|
|
10
|
+
$parcel$export($28f99e3e86e6ec45$exports, "useSliderState", () => $28f99e3e86e6ec45$export$e5fda3247f5d67f9);
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
const $
|
|
15
|
-
const $
|
|
16
|
-
const $
|
|
17
|
-
function $
|
|
18
|
-
const { isDisabled: isDisabled , minValue: minValue = $
|
|
19
|
-
|
|
14
|
+
const $28f99e3e86e6ec45$var$DEFAULT_MIN_VALUE = 0;
|
|
15
|
+
const $28f99e3e86e6ec45$var$DEFAULT_MAX_VALUE = 100;
|
|
16
|
+
const $28f99e3e86e6ec45$var$DEFAULT_STEP_VALUE = 1;
|
|
17
|
+
function $28f99e3e86e6ec45$export$e5fda3247f5d67f9(props) {
|
|
18
|
+
const { isDisabled: isDisabled , minValue: minValue = $28f99e3e86e6ec45$var$DEFAULT_MIN_VALUE , maxValue: maxValue = $28f99e3e86e6ec45$var$DEFAULT_MAX_VALUE , numberFormatter: formatter , step: step = $28f99e3e86e6ec45$var$DEFAULT_STEP_VALUE , pageSize: pageSize = Math.max((maxValue - minValue) / 10, step) } = props;
|
|
19
|
+
var _defaultValue;
|
|
20
|
+
const [values, setValues] = $aTwux$useControlledState(props.value, (_defaultValue = props.defaultValue) !== null && _defaultValue !== void 0 ? _defaultValue : [
|
|
20
21
|
minValue
|
|
21
22
|
], props.onChange);
|
|
22
|
-
const [isDraggings, setDraggings] = $
|
|
23
|
-
const isEditablesRef = $
|
|
24
|
-
const [focusedIndex, setFocusedIndex] = $
|
|
25
|
-
const valuesRef = $
|
|
23
|
+
const [isDraggings, setDraggings] = $aTwux$useState(new Array(values.length).fill(false));
|
|
24
|
+
const isEditablesRef = $aTwux$useRef(new Array(values.length).fill(true));
|
|
25
|
+
const [focusedIndex, setFocusedIndex] = $aTwux$useState(undefined);
|
|
26
|
+
const valuesRef = $aTwux$useRef(null);
|
|
26
27
|
valuesRef.current = values;
|
|
27
|
-
const isDraggingsRef = $
|
|
28
|
+
const isDraggingsRef = $aTwux$useRef(null);
|
|
28
29
|
isDraggingsRef.current = isDraggings;
|
|
29
30
|
function getValuePercent(value) {
|
|
30
31
|
return (value - minValue) / (maxValue - minValue);
|
|
@@ -46,14 +47,14 @@ function $41e91674a959b70c$export$e5fda3247f5d67f9(props) {
|
|
|
46
47
|
const thisMin = getThumbMinValue(index);
|
|
47
48
|
const thisMax = getThumbMaxValue(index);
|
|
48
49
|
// Round value to multiple of step, clamp value between min and max
|
|
49
|
-
value = $
|
|
50
|
-
valuesRef.current = $
|
|
50
|
+
value = $aTwux$snapValueToStep(value, thisMin, thisMax, step);
|
|
51
|
+
valuesRef.current = $28f99e3e86e6ec45$var$replaceIndex(valuesRef.current, index, value);
|
|
51
52
|
setValues(valuesRef.current);
|
|
52
53
|
}
|
|
53
54
|
function updateDragging(index, dragging) {
|
|
54
55
|
if (isDisabled || !isThumbEditable(index)) return;
|
|
55
56
|
const wasDragging = isDraggingsRef.current[index];
|
|
56
|
-
isDraggingsRef.current = $
|
|
57
|
+
isDraggingsRef.current = $28f99e3e86e6ec45$var$replaceIndex(isDraggingsRef.current, index, dragging);
|
|
57
58
|
setDraggings(isDraggingsRef.current);
|
|
58
59
|
// Call onChangeEnd if no handles are dragging.
|
|
59
60
|
if (props.onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) props.onChangeEnd(valuesRef.current);
|
|
@@ -69,7 +70,15 @@ function $41e91674a959b70c$export$e5fda3247f5d67f9(props) {
|
|
|
69
70
|
}
|
|
70
71
|
function getPercentValue(percent) {
|
|
71
72
|
const val = percent * (maxValue - minValue) + minValue;
|
|
72
|
-
return $
|
|
73
|
+
return $aTwux$clamp(getRoundedValue(val), minValue, maxValue);
|
|
74
|
+
}
|
|
75
|
+
function incrementThumb(index, stepSize = 1) {
|
|
76
|
+
let s = Math.max(stepSize, step);
|
|
77
|
+
updateValue(index, $aTwux$snapValueToStep(values[index] + s, minValue, maxValue, step));
|
|
78
|
+
}
|
|
79
|
+
function decrementThumb(index, stepSize = 1) {
|
|
80
|
+
let s = Math.max(stepSize, step);
|
|
81
|
+
updateValue(index, $aTwux$snapValueToStep(values[index] - s, minValue, maxValue, step));
|
|
73
82
|
}
|
|
74
83
|
return {
|
|
75
84
|
values: values,
|
|
@@ -93,10 +102,13 @@ function $41e91674a959b70c$export$e5fda3247f5d67f9(props) {
|
|
|
93
102
|
getPercentValue: getPercentValue,
|
|
94
103
|
isThumbEditable: isThumbEditable,
|
|
95
104
|
setThumbEditable: setThumbEditable,
|
|
96
|
-
|
|
105
|
+
incrementThumb: incrementThumb,
|
|
106
|
+
decrementThumb: decrementThumb,
|
|
107
|
+
step: step,
|
|
108
|
+
pageSize: pageSize
|
|
97
109
|
};
|
|
98
110
|
}
|
|
99
|
-
function $
|
|
111
|
+
function $28f99e3e86e6ec45$var$replaceIndex(array, index, value) {
|
|
100
112
|
if (array[index] === value) return array;
|
|
101
113
|
return [
|
|
102
114
|
...array.slice(0, index),
|
|
@@ -108,5 +120,5 @@ function $41e91674a959b70c$var$replaceIndex(array, index, value) {
|
|
|
108
120
|
|
|
109
121
|
|
|
110
122
|
|
|
111
|
-
export {$
|
|
123
|
+
export {$28f99e3e86e6ec45$export$e5fda3247f5d67f9 as useSliderState};
|
|
112
124
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;AC+HA,KAAK,CAAC,uCAAiB,GAAG,CAAC;AAC3B,KAAK,CAAC,uCAAiB,GAAG,GAAG;AAC7B,KAAK,CAAC,wCAAkB,GAAG,CAAC;SAYZ,yCAAc,CAAC,KAAyB,EAAe,CAAC;IACtE,KAAK,CAAC,CAAC,aAAA,UAAU,aAAE,QAAQ,GAAG,uCAAiB,aAAE,QAAQ,GAAG,uCAAiB,GAAE,eAAe,EAAE,SAAS,SAAE,IAAI,GAAG,wCAAkB,EAAA,CAAC,GAAG,KAAK;IAE7I,KAAK,EAAE,MAAM,EAAE,SAAS,IAAI,yBAAkB,CAC5C,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,YAAY,IAAI,CAAC;QAAA,QAAQ;IAAA,CAAC,EAChC,KAAK,CAAC,QAAQ;IAEhB,KAAK,EAAE,WAAW,EAAE,YAAY,IAAI,eAAQ,CAAY,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK;IAC3F,KAAK,CAAC,cAAc,GAAG,aAAM,CAAY,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI;IAC3E,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yBAC1B,eAAe;QACf,eAAe,GAAG,KAAa,GAAK,WAAW,CAAC,KAAK;;QACrD,gBAAgB,EAAE,cAAc;QAChC,YAAY,EAAE,YAAY;QAC1B,eAAe,EAAE,eAAe;QAChC,eAAe,GAAG,KAAa,GAAK,eAAe,CAAC,MAAM,CAAC,KAAK;;yBAChE,eAAe;QACf,kBAAkB,GAAG,KAAa,GAAK,iBAAiB,CAAC,MAAM,CAAC,KAAK;;2BACrE,iBAAiB;0BACjB,gBAAgB;0BAChB,gBAAgB;yBAChB,eAAe;yBACf,eAAe;0BACf,gBAAgB;cAChB,IAAI;IACN,CAAC;AACH,CAAC;SAEQ,kCAAY,CAAI,KAAU,EAAE,KAAa,EAAE,KAAQ,EAAE,CAAC;IAC7D,EAAE,EAAE,KAAK,CAAC,KAAK,MAAM,KAAK,EACxB,MAAM,CAAC,KAAK;IAGd,MAAM,CAAC,CAAC;WAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK;QAAG,KAAK;WAAK,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC;IAAC,CAAC;AACrE,CAAC","sources":["packages/@react-stately/slider/src/index.ts","packages/@react-stately/slider/src/useSliderState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useSliderState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '@react-aria/utils';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useRef, useState} from 'react';\n\nexport interface SliderState {\n /**\n * Values managed by the slider by thumb index.\n */\n readonly values: number[],\n /**\n * Get the value for the specified thumb.\n * @param index\n */\n getThumbValue(index: number): number,\n\n /**\n * Sets the value for the specified thumb.\n * The actual value set will be clamped and rounded according to min/max/step.\n * @param index\n * @param value\n */\n setThumbValue(index: number, value: number): void,\n\n /**\n * Sets value for the specified thumb by percent offset (between 0 and 1).\n * @param index\n * @param percent\n */\n setThumbPercent(index: number, percent: number): void,\n\n /**\n * Whether the specific thumb is being dragged.\n * @param index\n */\n isThumbDragging(index: number): boolean,\n /**\n * Set is dragging on the specified thumb.\n * @param index\n * @param dragging\n */\n setThumbDragging(index: number, dragging: boolean): void,\n\n /**\n * Currently-focused thumb index.\n */\n readonly focusedThumb: number | undefined,\n /**\n * Set focused true on specified thumb. This will remove focus from\n * any thumb that had it before.\n * @param index\n */\n setFocusedThumb(index: number | undefined): void,\n\n /**\n * Returns the specified thumb's value as a percentage from 0 to 1.\n * @param index\n */\n getThumbPercent(index: number): number,\n\n /**\n * Returns the value as a percent between the min and max of the slider.\n * @param index\n */\n getValuePercent(value: number): number,\n\n /**\n * Returns the string label for the specified thumb's value, per props.formatOptions.\n * @param index\n */\n getThumbValueLabel(index: number): string,\n\n /**\n * Returns the string label for the value, per props.formatOptions.\n * @param index\n */\n getFormattedValue(value: number): string,\n\n /**\n * Returns the min allowed value for the specified thumb.\n * @param index\n */\n getThumbMinValue(index: number): number,\n\n /**\n * Returns the max allowed value for the specified thumb.\n * @param index\n */\n getThumbMaxValue(index: number): number,\n\n /**\n * Converts a percent along track (between 0 and 1) to the corresponding value.\n * @param percent\n */\n getPercentValue(percent: number): number,\n\n /**\n * Returns if the specified thumb is editable.\n * @param index\n */\n isThumbEditable(index: number): boolean,\n\n /**\n * Set the specified thumb's editable state.\n * @param index\n * @param editable\n */\n setThumbEditable(index: number, editable: boolean): void,\n\n /**\n * The step amount for the slider.\n */\n readonly step: number\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\ninterface SliderStateOptions extends SliderProps {\n numberFormatter: Intl.NumberFormat\n}\n\n/**\n * Provides state management for a slider component. Stores values for all thumbs,\n * formats values for localization, and provides methods to update the position\n * of any thumbs.\n * @param props\n */\nexport function useSliderState(props: SliderStateOptions): SliderState {\n const {isDisabled, minValue = DEFAULT_MIN_VALUE, maxValue = DEFAULT_MAX_VALUE, numberFormatter: formatter, step = DEFAULT_STEP_VALUE} = props;\n\n const [values, setValues] = useControlledState<number[]>(\n props.value as any,\n props.defaultValue ?? [minValue] as any,\n props.onChange as any\n );\n const [isDraggings, setDraggings] = useState<boolean[]>(new Array(values.length).fill(false));\n const isEditablesRef = useRef<boolean[]>(new Array(values.length).fill(true));\n const [focusedIndex, setFocusedIndex] = useState<number | undefined>(undefined);\n\n const valuesRef = useRef<number[]>(null);\n valuesRef.current = values;\n const isDraggingsRef = useRef<boolean[]>(null);\n isDraggingsRef.current = isDraggings;\n\n function getValuePercent(value: number) {\n return (value - minValue) / (maxValue - minValue);\n }\n\n function getThumbMinValue(index: number) {\n return index === 0 ? minValue : values[index - 1];\n }\n function getThumbMaxValue(index: number) {\n return index === values.length - 1 ? maxValue : values[index + 1];\n }\n\n function isThumbEditable(index: number) {\n return isEditablesRef.current[index];\n }\n\n function setThumbEditable(index: number, editable: boolean) {\n isEditablesRef.current[index] = editable;\n }\n\n function updateValue(index: number, value: number) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n const thisMin = getThumbMinValue(index);\n const thisMax = getThumbMaxValue(index);\n\n // Round value to multiple of step, clamp value between min and max\n value = snapValueToStep(value, thisMin, thisMax, step);\n valuesRef.current = replaceIndex(valuesRef.current, index, value);\n setValues(valuesRef.current);\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n\n const wasDragging = isDraggingsRef.current[index];\n isDraggingsRef.current = replaceIndex(isDraggingsRef.current, index, dragging);\n setDraggings(isDraggingsRef.current);\n\n // Call onChangeEnd if no handles are dragging.\n if (props.onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n props.onChangeEnd(valuesRef.current);\n }\n }\n\n function getFormattedValue(value: number) {\n return formatter.format(value);\n }\n\n function setThumbPercent(index: number, percent: number) {\n updateValue(index, getPercentValue(percent));\n }\n\n function getRoundedValue(value: number) {\n return Math.round((value - minValue) / step) * step + minValue;\n }\n\n function getPercentValue(percent: number) {\n const val = percent * (maxValue - minValue) + minValue;\n return clamp(getRoundedValue(val), minValue, maxValue);\n }\n\n return {\n values: values,\n getThumbValue: (index: number) => values[index],\n setThumbValue: updateValue,\n setThumbPercent,\n isThumbDragging: (index: number) => isDraggings[index],\n setThumbDragging: updateDragging,\n focusedThumb: focusedIndex,\n setFocusedThumb: setFocusedIndex,\n getThumbPercent: (index: number) => getValuePercent(values[index]),\n getValuePercent,\n getThumbValueLabel: (index: number) => getFormattedValue(values[index]),\n getFormattedValue,\n getThumbMinValue,\n getThumbMaxValue,\n getPercentValue,\n isThumbEditable,\n setThumbEditable,\n step\n };\n}\n\nfunction replaceIndex<T>(array: T[], index: number, value: T) {\n if (array[index] === value) {\n return array;\n }\n\n return [...array.slice(0, index), value, ...array.slice(index + 1)];\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;AC6IA,KAAK,CAAC,uCAAiB,GAAG,CAAC;AAC3B,KAAK,CAAC,uCAAiB,GAAG,GAAG;AAC7B,KAAK,CAAC,wCAAkB,GAAG,CAAC;SAYZ,yCAAc,CAAC,KAAyB,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aAAa,EAAE,WAAW;yBAC1B,eAAe;QACf,eAAe,GAAG,KAAa,GAAK,WAAW,CAAC,KAAK;;QACrD,gBAAgB,EAAE,cAAc;QAChC,YAAY,EAAE,YAAY;QAC1B,eAAe,EAAE,eAAe;QAChC,eAAe,GAAG,KAAa,GAAK,eAAe,CAAC,MAAM,CAAC,KAAK;;yBAChE,eAAe;QACf,kBAAkB,GAAG,KAAa,GAAK,iBAAiB,CAAC,MAAM,CAAC,KAAK;;2BACrE,iBAAiB;0BACjB,gBAAgB;0BAChB,gBAAgB;yBAChB,eAAe;yBACf,eAAe;0BACf,gBAAgB;wBAChB,cAAc;wBACd,cAAc;cACd,IAAI;kBACJ,QAAQ;IACV,CAAC;AACH,CAAC;SAEQ,kCAAY,CAAI,KAAU,EAAE,KAAa,EAAE,KAAQ,EAAE,CAAC;IAC7D,EAAE,EAAE,KAAK,CAAC,KAAK,MAAM,KAAK,EACxB,MAAM,CAAC,KAAK;IAGd,MAAM,CAAC,CAAC;WAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK;QAAG,KAAK;WAAK,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC;IAAC,CAAC;AACrE,CAAC","sources":["packages/@react-stately/slider/src/index.ts","packages/@react-stately/slider/src/useSliderState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useSliderState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {clamp, snapValueToStep} from '@react-aria/utils';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useRef, useState} from 'react';\n\nexport interface SliderState {\n /**\n * Values managed by the slider by thumb index.\n */\n readonly values: number[],\n /**\n * Get the value for the specified thumb.\n * @param index\n */\n getThumbValue(index: number): number,\n\n /**\n * Sets the value for the specified thumb.\n * The actual value set will be clamped and rounded according to min/max/step.\n * @param index\n * @param value\n */\n setThumbValue(index: number, value: number): void,\n\n /**\n * Sets value for the specified thumb by percent offset (between 0 and 1).\n * @param index\n * @param percent\n */\n setThumbPercent(index: number, percent: number): void,\n\n /**\n * Whether the specific thumb is being dragged.\n * @param index\n */\n isThumbDragging(index: number): boolean,\n /**\n * Set is dragging on the specified thumb.\n * @param index\n * @param dragging\n */\n setThumbDragging(index: number, dragging: boolean): void,\n\n /**\n * Currently-focused thumb index.\n */\n readonly focusedThumb: number | undefined,\n /**\n * Set focused true on specified thumb. This will remove focus from\n * any thumb that had it before.\n * @param index\n */\n setFocusedThumb(index: number | undefined): void,\n\n /**\n * Returns the specified thumb's value as a percentage from 0 to 1.\n * @param index\n */\n getThumbPercent(index: number): number,\n\n /**\n * Returns the value as a percent between the min and max of the slider.\n * @param index\n */\n getValuePercent(value: number): number,\n\n /**\n * Returns the string label for the specified thumb's value, per props.formatOptions.\n * @param index\n */\n getThumbValueLabel(index: number): string,\n\n /**\n * Returns the string label for the value, per props.formatOptions.\n * @param index\n */\n getFormattedValue(value: number): string,\n\n /**\n * Returns the min allowed value for the specified thumb.\n * @param index\n */\n getThumbMinValue(index: number): number,\n\n /**\n * Returns the max allowed value for the specified thumb.\n * @param index\n */\n getThumbMaxValue(index: number): number,\n\n /**\n * Converts a percent along track (between 0 and 1) to the corresponding value.\n * @param percent\n */\n getPercentValue(percent: number): number,\n\n /**\n * Returns if the specified thumb is editable.\n * @param index\n */\n isThumbEditable(index: number): boolean,\n\n /**\n * Set the specified thumb's editable state.\n * @param index\n * @param editable\n */\n setThumbEditable(index: number, editable: boolean): void,\n\n /**\n * Increments the value of the thumb by the step or page amount.\n */\n incrementThumb(index: number, stepSize?: number): void,\n /**\n * Decrements the value of the thumb by the step or page amount.\n */\n decrementThumb(index: number, stepSize?: number): void,\n\n /**\n * The step amount for the slider.\n */\n readonly step: number,\n\n /**\n * The page size for the slider, used to do a bigger step.\n */\n readonly pageSize: number\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\ninterface SliderStateOptions extends SliderProps {\n numberFormatter: Intl.NumberFormat\n}\n\n/**\n * Provides state management for a slider component. Stores values for all thumbs,\n * formats values for localization, and provides methods to update the position\n * of any thumbs.\n * @param props\n */\nexport function useSliderState(props: SliderStateOptions): SliderState {\n const {\n isDisabled,\n minValue = DEFAULT_MIN_VALUE,\n maxValue = DEFAULT_MAX_VALUE,\n numberFormatter: formatter,\n step = DEFAULT_STEP_VALUE,\n pageSize = Math.max((maxValue - minValue) / 10, step)\n } = props;\n\n const [values, setValues] = useControlledState<number[]>(\n props.value as any,\n props.defaultValue ?? [minValue] as any,\n props.onChange as any\n );\n const [isDraggings, setDraggings] = useState<boolean[]>(new Array(values.length).fill(false));\n const isEditablesRef = useRef<boolean[]>(new Array(values.length).fill(true));\n const [focusedIndex, setFocusedIndex] = useState<number | undefined>(undefined);\n\n const valuesRef = useRef<number[]>(null);\n valuesRef.current = values;\n const isDraggingsRef = useRef<boolean[]>(null);\n isDraggingsRef.current = isDraggings;\n\n function getValuePercent(value: number) {\n return (value - minValue) / (maxValue - minValue);\n }\n\n function getThumbMinValue(index: number) {\n return index === 0 ? minValue : values[index - 1];\n }\n function getThumbMaxValue(index: number) {\n return index === values.length - 1 ? maxValue : values[index + 1];\n }\n\n function isThumbEditable(index: number) {\n return isEditablesRef.current[index];\n }\n\n function setThumbEditable(index: number, editable: boolean) {\n isEditablesRef.current[index] = editable;\n }\n\n function updateValue(index: number, value: number) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n const thisMin = getThumbMinValue(index);\n const thisMax = getThumbMaxValue(index);\n\n // Round value to multiple of step, clamp value between min and max\n value = snapValueToStep(value, thisMin, thisMax, step);\n valuesRef.current = replaceIndex(valuesRef.current, index, value);\n setValues(valuesRef.current);\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n\n const wasDragging = isDraggingsRef.current[index];\n isDraggingsRef.current = replaceIndex(isDraggingsRef.current, index, dragging);\n setDraggings(isDraggingsRef.current);\n\n // Call onChangeEnd if no handles are dragging.\n if (props.onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n props.onChangeEnd(valuesRef.current);\n }\n }\n\n function getFormattedValue(value: number) {\n return formatter.format(value);\n }\n\n function setThumbPercent(index: number, percent: number) {\n updateValue(index, getPercentValue(percent));\n }\n\n function getRoundedValue(value: number) {\n return Math.round((value - minValue) / step) * step + minValue;\n }\n\n function getPercentValue(percent: number) {\n const val = percent * (maxValue - minValue) + minValue;\n return clamp(getRoundedValue(val), minValue, maxValue);\n }\n\n function incrementThumb(index: number, stepSize: number = 1) {\n let s = Math.max(stepSize, step);\n updateValue(index, snapValueToStep(values[index] + s, minValue, maxValue, step));\n }\n\n function decrementThumb(index: number, stepSize: number = 1) {\n let s = Math.max(stepSize, step);\n updateValue(index, snapValueToStep(values[index] - s, minValue, maxValue, step));\n }\n\n return {\n values: values,\n getThumbValue: (index: number) => values[index],\n setThumbValue: updateValue,\n setThumbPercent,\n isThumbDragging: (index: number) => isDraggings[index],\n setThumbDragging: updateDragging,\n focusedThumb: focusedIndex,\n setFocusedThumb: setFocusedIndex,\n getThumbPercent: (index: number) => getValuePercent(values[index]),\n getValuePercent,\n getThumbValueLabel: (index: number) => getFormattedValue(values[index]),\n getFormattedValue,\n getThumbMinValue,\n getThumbMaxValue,\n getPercentValue,\n isThumbEditable,\n setThumbEditable,\n incrementThumb,\n decrementThumb,\n step,\n pageSize\n };\n}\n\nfunction replaceIndex<T>(array: T[], index: number, value: T) {\n if (array[index] === value) {\n return array;\n }\n\n return [...array.slice(0, index), value, ...array.slice(index + 1)];\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -89,10 +89,22 @@ export interface SliderState {
|
|
|
89
89
|
* @param editable
|
|
90
90
|
*/
|
|
91
91
|
setThumbEditable(index: number, editable: boolean): void;
|
|
92
|
+
/**
|
|
93
|
+
* Increments the value of the thumb by the step or page amount.
|
|
94
|
+
*/
|
|
95
|
+
incrementThumb(index: number, stepSize?: number): void;
|
|
96
|
+
/**
|
|
97
|
+
* Decrements the value of the thumb by the step or page amount.
|
|
98
|
+
*/
|
|
99
|
+
decrementThumb(index: number, stepSize?: number): void;
|
|
92
100
|
/**
|
|
93
101
|
* The step amount for the slider.
|
|
94
102
|
*/
|
|
95
103
|
readonly step: number;
|
|
104
|
+
/**
|
|
105
|
+
* The page size for the slider, used to do a bigger step.
|
|
106
|
+
*/
|
|
107
|
+
readonly pageSize: number;
|
|
96
108
|
}
|
|
97
109
|
interface SliderStateOptions extends SliderProps {
|
|
98
110
|
numberFormatter: Intl.NumberFormat;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";AAiBA;IACE;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAC1B;;;OAGG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAErC;;;;;OAKG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAElD;;;;O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M,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvD;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAEvD;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAC1B;AAMD,4BAA6B,SAAQ,WAAW;IAC9C,eAAe,EAAE,KAAK,YAAY,CAAA;CACnC;AAED;;;;;GAKG;AACH,+BAA+B,KAAK,EAAE,kBAAkB,GAAG,WAAW,CAyHrE","sources":["packages/@react-stately/slider/src/packages/@react-stately/slider/src/useSliderState.ts","packages/@react-stately/slider/src/packages/@react-stately/slider/src/index.ts","packages/@react-stately/slider/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport * from './useSliderState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/slider",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6-nightly.3120+1aa66e6e7",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-aria/i18n": "
|
|
22
|
-
"@react-aria/utils": "
|
|
23
|
-
"@react-stately/utils": "
|
|
24
|
-
"@react-types/slider": "
|
|
21
|
+
"@react-aria/i18n": "3.0.0-nightly.1424+1aa66e6e7",
|
|
22
|
+
"@react-aria/utils": "3.0.0-nightly.1424+1aa66e6e7",
|
|
23
|
+
"@react-stately/utils": "3.0.0-nightly.1424+1aa66e6e7",
|
|
24
|
+
"@react-types/slider": "3.0.5-nightly.3120+1aa66e6e7"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "1aa66e6e75e2da014f44177686c3332cd625fb9f"
|
|
33
33
|
}
|
package/src/useSliderState.ts
CHANGED
|
@@ -119,10 +119,24 @@ export interface SliderState {
|
|
|
119
119
|
*/
|
|
120
120
|
setThumbEditable(index: number, editable: boolean): void,
|
|
121
121
|
|
|
122
|
+
/**
|
|
123
|
+
* Increments the value of the thumb by the step or page amount.
|
|
124
|
+
*/
|
|
125
|
+
incrementThumb(index: number, stepSize?: number): void,
|
|
126
|
+
/**
|
|
127
|
+
* Decrements the value of the thumb by the step or page amount.
|
|
128
|
+
*/
|
|
129
|
+
decrementThumb(index: number, stepSize?: number): void,
|
|
130
|
+
|
|
122
131
|
/**
|
|
123
132
|
* The step amount for the slider.
|
|
124
133
|
*/
|
|
125
|
-
readonly step: number
|
|
134
|
+
readonly step: number,
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The page size for the slider, used to do a bigger step.
|
|
138
|
+
*/
|
|
139
|
+
readonly pageSize: number
|
|
126
140
|
}
|
|
127
141
|
|
|
128
142
|
const DEFAULT_MIN_VALUE = 0;
|
|
@@ -140,7 +154,14 @@ interface SliderStateOptions extends SliderProps {
|
|
|
140
154
|
* @param props
|
|
141
155
|
*/
|
|
142
156
|
export function useSliderState(props: SliderStateOptions): SliderState {
|
|
143
|
-
const {
|
|
157
|
+
const {
|
|
158
|
+
isDisabled,
|
|
159
|
+
minValue = DEFAULT_MIN_VALUE,
|
|
160
|
+
maxValue = DEFAULT_MAX_VALUE,
|
|
161
|
+
numberFormatter: formatter,
|
|
162
|
+
step = DEFAULT_STEP_VALUE,
|
|
163
|
+
pageSize = Math.max((maxValue - minValue) / 10, step)
|
|
164
|
+
} = props;
|
|
144
165
|
|
|
145
166
|
const [values, setValues] = useControlledState<number[]>(
|
|
146
167
|
props.value as any,
|
|
@@ -220,6 +241,16 @@ export function useSliderState(props: SliderStateOptions): SliderState {
|
|
|
220
241
|
return clamp(getRoundedValue(val), minValue, maxValue);
|
|
221
242
|
}
|
|
222
243
|
|
|
244
|
+
function incrementThumb(index: number, stepSize: number = 1) {
|
|
245
|
+
let s = Math.max(stepSize, step);
|
|
246
|
+
updateValue(index, snapValueToStep(values[index] + s, minValue, maxValue, step));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function decrementThumb(index: number, stepSize: number = 1) {
|
|
250
|
+
let s = Math.max(stepSize, step);
|
|
251
|
+
updateValue(index, snapValueToStep(values[index] - s, minValue, maxValue, step));
|
|
252
|
+
}
|
|
253
|
+
|
|
223
254
|
return {
|
|
224
255
|
values: values,
|
|
225
256
|
getThumbValue: (index: number) => values[index],
|
|
@@ -238,7 +269,10 @@ export function useSliderState(props: SliderStateOptions): SliderState {
|
|
|
238
269
|
getPercentValue,
|
|
239
270
|
isThumbEditable,
|
|
240
271
|
setThumbEditable,
|
|
241
|
-
|
|
272
|
+
incrementThumb,
|
|
273
|
+
decrementThumb,
|
|
274
|
+
step,
|
|
275
|
+
pageSize
|
|
242
276
|
};
|
|
243
277
|
}
|
|
244
278
|
|