@react-stately/slider 3.0.0-alpha.2 → 3.0.0-nightly-641446f65-240905

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.
@@ -0,0 +1,17 @@
1
+ import {useSliderState as $28f99e3e86e6ec45$export$e5fda3247f5d67f9} from "./useSliderState.mjs";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+
16
+ export {$28f99e3e86e6ec45$export$e5fda3247f5d67f9 as useSliderState};
17
+ //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,135 +1,22 @@
1
- var {
2
- useRef,
3
- useState
4
- } = require("react");
1
+ var $e86753598efd0f02$exports = require("./useSliderState.main.js");
5
2
 
6
- var {
7
- useNumberFormatter
8
- } = require("@react-aria/i18n");
9
3
 
10
- var {
11
- useControlledState
12
- } = require("@react-stately/utils");
13
-
14
- var {
15
- clamp
16
- } = require("@react-aria/utils");
17
-
18
- const DEFAULT_MIN_VALUE = 0;
19
- exports.DEFAULT_MIN_VALUE = DEFAULT_MIN_VALUE;
20
- const DEFAULT_MAX_VALUE = 100;
21
- exports.DEFAULT_MAX_VALUE = DEFAULT_MAX_VALUE;
22
- const DEFAULT_STEP_VALUE = 1;
23
- exports.DEFAULT_STEP_VALUE = DEFAULT_STEP_VALUE;
24
-
25
- function useSliderState(props) {
26
- var _props$defaultValue;
27
-
28
- let {
29
- isReadOnly,
30
- isDisabled,
31
- minValue = DEFAULT_MIN_VALUE,
32
- maxValue = DEFAULT_MAX_VALUE,
33
- formatOptions,
34
- step = DEFAULT_STEP_VALUE
35
- } = props;
36
- const [values, setValues] = useControlledState(props.value, (_props$defaultValue = props.defaultValue) != null ? _props$defaultValue : [minValue], props.onChange);
37
- const [isDraggings, setDraggings] = useState(new Array(values.length).fill(false));
38
- const isEditablesRef = useRef(new Array(values.length).fill(true));
39
- const [focusedIndex, setFocusedIndex] = useState(undefined);
40
- const formatter = useNumberFormatter(formatOptions);
41
-
42
- function getValuePercent(value) {
43
- return (value - minValue) / (maxValue - minValue);
44
- }
45
-
46
- function getThumbMinValue(index) {
47
- return index === 0 ? minValue : values[index - 1];
48
- }
49
-
50
- function getThumbMaxValue(index) {
51
- return index === values.length - 1 ? maxValue : values[index + 1];
52
- }
53
-
54
- function isThumbEditable(index) {
55
- return isEditablesRef.current[index];
56
- }
57
-
58
- function setThumbEditable(index, editable) {
59
- isEditablesRef.current[index] = editable;
60
- }
61
-
62
- function updateValue(index, value) {
63
- if (isReadOnly || isDisabled || !isThumbEditable(index)) {
64
- return;
65
- }
66
-
67
- const thisMin = getThumbMinValue(index);
68
- const thisMax = getThumbMaxValue(index); // Round value to multiple of step, clamp value between min and max
69
-
70
- value = clamp(getRoundedValue(value), thisMin, thisMax);
71
- setValues(values => $bc3294032743285adead374b6f67$var$replaceIndex(values, index, value));
72
- }
73
-
74
- function updateDragging(index, dragging) {
75
- if (isReadOnly || isDisabled || !isThumbEditable(index)) {
76
- return;
77
- }
78
-
79
- const newDraggings = $bc3294032743285adead374b6f67$var$replaceIndex(isDraggings, index, dragging);
80
- setDraggings(newDraggings); // Call onChangeEnd if no handles are dragging.
81
-
82
- if (props.onChangeEnd && isDraggings[index] && !newDraggings.some(Boolean)) {
83
- props.onChangeEnd(values);
84
- }
85
- }
86
-
87
- function getFormattedValue(value) {
88
- return formatter.format(value);
89
- }
90
-
91
- function setThumbPercent(index, percent) {
92
- updateValue(index, getPercentValue(percent));
93
- }
94
-
95
- function getRoundedValue(value) {
96
- return Math.round((value - minValue) / step) * step + minValue;
97
- }
98
-
99
- function getPercentValue(percent) {
100
- const val = percent * (maxValue - minValue) + minValue;
101
- return clamp(getRoundedValue(val), minValue, maxValue);
102
- }
103
-
104
- return {
105
- values: values,
106
- getThumbValue: index => values[index],
107
- setThumbValue: updateValue,
108
- setThumbPercent,
109
- isThumbDragging: index => isDraggings[index],
110
- setThumbDragging: updateDragging,
111
- focusedThumb: focusedIndex,
112
- setFocusedThumb: setFocusedIndex,
113
- getThumbPercent: index => getValuePercent(values[index]),
114
- getValuePercent,
115
- getThumbValueLabel: index => getFormattedValue(values[index]),
116
- getFormattedValue,
117
- getThumbMinValue,
118
- getThumbMaxValue,
119
- getPercentValue,
120
- isThumbEditable,
121
- setThumbEditable,
122
- step
123
- };
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
124
6
  }
125
7
 
126
- exports.useSliderState = useSliderState;
8
+ $parcel$export(module.exports, "useSliderState", () => $e86753598efd0f02$exports.useSliderState);
9
+ /*
10
+ * Copyright 2020 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
127
20
 
128
- function $bc3294032743285adead374b6f67$var$replaceIndex(array, index, value) {
129
- if (array[index] === value) {
130
- return array;
131
- }
132
21
 
133
- return [...array.slice(0, index), value, ...array.slice(index + 1)];
134
- }
135
22
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;AA6DO,MAAMA,iBAAiB,GAAG,CAA1B;;AACA,MAAMC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AAA,iBAZK;AAaLnB,IAAAA,gBAbK;AAcLE,IAAAA,gBAdK;AAeLqB,IAAAA,eAfK;AAgBLpB,IAAAA,eAhBK;AAiBLE,IAAAA,gBAjBK;AAkBL1B,IAAAA;AAlBK,GAAP;AAoBD;;;;AAED,SAASiC,8CAAT,CAAyBuB,KAAzB,EAAqClC,KAArC,EAAoDlB,KAApD,EAA8D;AAC5D,MAAIoD,KAAK,CAAClC,KAAD,CAAL,KAAiBlB,KAArB,EAA4B;AAC1B,WAAOoD,KAAP;AACD;;AAED,SAAO,CAAC,GAAGA,KAAK,CAACC,KAAN,CAAY,CAAZ,EAAenC,KAAf,CAAJ,EAA2BlB,KAA3B,EAAkC,GAAGoD,KAAK,CAACC,KAAN,CAAYnC,KAAK,GAAG,CAApB,CAArC,CAAP;AACD","sources":["./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\nimport {clamp} from '@react-aria/utils';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useNumberFormatter} from '@react-aria/i18n';\nimport {useRef, useState} from 'react';\n\nexport interface SliderState {\n // Values managed by the slider\n readonly values: number[],\n getThumbValue: (index: number) => number,\n\n // Sets value for thumb. The actually value set will be clamped and\n // rounded according to min/max/step\n setThumbValue: (index: number, value: number) => void,\n\n // Sets value for thumb by percent offset (between 0 and 1)\n setThumbPercent: (index: number, percent: number) => void,\n\n // Whether a specific index is being dragged\n isThumbDragging: (index: number) => boolean,\n setThumbDragging: (index: number, dragging: boolean) => void,\n\n // Currently-focused index\n readonly focusedThumb: number | undefined,\n setFocusedThumb: (index: number | undefined) => void,\n\n // Returns the value offset as a percentage from 0 to 1.\n getThumbPercent: (index: number) => number,\n getValuePercent: (value: number) => number,\n\n // Returns the string label for the value, per props.formatOptions\n getThumbValueLabel: (index: number) => string,\n getFormattedValue: (value: number) => string,\n\n // Returns the min and max values for the index\n getThumbMinValue: (index: number) => number,\n getThumbMaxValue: (index: number) => number,\n\n // Converts a percent along track (between 0 and 1) to the corresponding value\n getPercentValue: (percent: number) => number,\n\n // editable\n isThumbEditable: (index: number) => boolean,\n setThumbEditable: (index: number, editable: boolean) => void,\n\n // The step amount for the slider\n readonly step: number\n}\n\nexport const DEFAULT_MIN_VALUE = 0;\nexport const DEFAULT_MAX_VALUE = 100;\nexport const DEFAULT_STEP_VALUE = 1;\n\nexport function useSliderState(props: SliderProps): SliderState {\n let {isReadOnly, isDisabled, minValue = DEFAULT_MIN_VALUE, maxValue = DEFAULT_MAX_VALUE, formatOptions, 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 formatter = useNumberFormatter(formatOptions);\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 (isReadOnly || 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 = clamp(getRoundedValue(value), thisMin, thisMax);\n setValues(values => replaceIndex(values, index, value));\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isReadOnly || isDisabled || !isThumbEditable(index)) {\n return;\n }\n\n const newDraggings = replaceIndex(isDraggings, index, dragging);\n setDraggings(newDraggings);\n\n // Call onChangeEnd if no handles are dragging.\n if (props.onChangeEnd && isDraggings[index] && !newDraggings.some(Boolean)) {\n props.onChangeEnd(values);\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":["DEFAULT_MIN_VALUE","DEFAULT_MAX_VALUE","DEFAULT_STEP_VALUE","useSliderState","props","isReadOnly","isDisabled","minValue","maxValue","formatOptions","step","values","setValues","useControlledState","value","defaultValue","onChange","isDraggings","setDraggings","useState","Array","length","fill","isEditablesRef","useRef","focusedIndex","setFocusedIndex","undefined","formatter","useNumberFormatter","getValuePercent","getThumbMinValue","index","getThumbMaxValue","isThumbEditable","current","setThumbEditable","editable","updateValue","thisMin","thisMax","clamp","getRoundedValue","replaceIndex","updateDragging","dragging","newDraggings","onChangeEnd","some","Boolean","getFormattedValue","format","setThumbPercent","percent","getPercentValue","Math","round","val","getThumbValue","setThumbValue","isThumbDragging","setThumbDragging","focusedThumb","setFocusedThumb","getThumbPercent","getThumbValueLabel","array","slice"],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/slider/src/index.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 {useSliderState} from './useSliderState';\n\nexport type {SliderStateOptions} from './useSliderState';\nexport type {SliderState} from './useSliderState';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,116 +1,17 @@
1
- import { useRef, useState } from "react";
2
- import { useNumberFormatter } from "@react-aria/i18n";
3
- import { useControlledState } from "@react-stately/utils";
4
- import { clamp } from "@react-aria/utils";
5
- export const DEFAULT_MIN_VALUE = 0;
6
- export const DEFAULT_MAX_VALUE = 100;
7
- export const DEFAULT_STEP_VALUE = 1;
8
- export function useSliderState(props) {
9
- var _props$defaultValue;
10
-
11
- let {
12
- isReadOnly,
13
- isDisabled,
14
- minValue = DEFAULT_MIN_VALUE,
15
- maxValue = DEFAULT_MAX_VALUE,
16
- formatOptions,
17
- step = DEFAULT_STEP_VALUE
18
- } = props;
19
- const [values, setValues] = useControlledState(props.value, (_props$defaultValue = props.defaultValue) != null ? _props$defaultValue : [minValue], props.onChange);
20
- const [isDraggings, setDraggings] = useState(new Array(values.length).fill(false));
21
- const isEditablesRef = useRef(new Array(values.length).fill(true));
22
- const [focusedIndex, setFocusedIndex] = useState(undefined);
23
- const formatter = useNumberFormatter(formatOptions);
24
-
25
- function getValuePercent(value) {
26
- return (value - minValue) / (maxValue - minValue);
27
- }
28
-
29
- function getThumbMinValue(index) {
30
- return index === 0 ? minValue : values[index - 1];
31
- }
32
-
33
- function getThumbMaxValue(index) {
34
- return index === values.length - 1 ? maxValue : values[index + 1];
35
- }
36
-
37
- function isThumbEditable(index) {
38
- return isEditablesRef.current[index];
39
- }
40
-
41
- function setThumbEditable(index, editable) {
42
- isEditablesRef.current[index] = editable;
43
- }
44
-
45
- function updateValue(index, value) {
46
- if (isReadOnly || isDisabled || !isThumbEditable(index)) {
47
- return;
48
- }
49
-
50
- const thisMin = getThumbMinValue(index);
51
- const thisMax = getThumbMaxValue(index); // Round value to multiple of step, clamp value between min and max
52
-
53
- value = clamp(getRoundedValue(value), thisMin, thisMax);
54
- setValues(values => $dcc38d2f5fc04b76254f325fa36d$var$replaceIndex(values, index, value));
55
- }
56
-
57
- function updateDragging(index, dragging) {
58
- if (isReadOnly || isDisabled || !isThumbEditable(index)) {
59
- return;
60
- }
61
-
62
- const newDraggings = $dcc38d2f5fc04b76254f325fa36d$var$replaceIndex(isDraggings, index, dragging);
63
- setDraggings(newDraggings); // Call onChangeEnd if no handles are dragging.
64
-
65
- if (props.onChangeEnd && isDraggings[index] && !newDraggings.some(Boolean)) {
66
- props.onChangeEnd(values);
67
- }
68
- }
69
-
70
- function getFormattedValue(value) {
71
- return formatter.format(value);
72
- }
73
-
74
- function setThumbPercent(index, percent) {
75
- updateValue(index, getPercentValue(percent));
76
- }
77
-
78
- function getRoundedValue(value) {
79
- return Math.round((value - minValue) / step) * step + minValue;
80
- }
81
-
82
- function getPercentValue(percent) {
83
- const val = percent * (maxValue - minValue) + minValue;
84
- return clamp(getRoundedValue(val), minValue, maxValue);
85
- }
86
-
87
- return {
88
- values: values,
89
- getThumbValue: index => values[index],
90
- setThumbValue: updateValue,
91
- setThumbPercent,
92
- isThumbDragging: index => isDraggings[index],
93
- setThumbDragging: updateDragging,
94
- focusedThumb: focusedIndex,
95
- setFocusedThumb: setFocusedIndex,
96
- getThumbPercent: index => getValuePercent(values[index]),
97
- getValuePercent,
98
- getThumbValueLabel: index => getFormattedValue(values[index]),
99
- getFormattedValue,
100
- getThumbMinValue,
101
- getThumbMaxValue,
102
- getPercentValue,
103
- isThumbEditable,
104
- setThumbEditable,
105
- step
106
- };
107
- }
108
-
109
- function $dcc38d2f5fc04b76254f325fa36d$var$replaceIndex(array, index, value) {
110
- if (array[index] === value) {
111
- return array;
112
- }
113
-
114
- return [...array.slice(0, index), value, ...array.slice(index + 1)];
115
- }
1
+ import {useSliderState as $28f99e3e86e6ec45$export$e5fda3247f5d67f9} from "./useSliderState.module.js";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+
16
+ export {$28f99e3e86e6ec45$export$e5fda3247f5d67f9 as useSliderState};
116
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;OA6DO,MAAMA,iBAAiB,GAAG,CAA1B;OACA,MAAMC,iBAAiB,GAAG,GAA1B;OACA,MAAMC,kBAAkB,GAAG,CAA3B;OAEA,SAASC,cAAT,CAAwBC,KAAxB,EAAyD;AAAA;;AAC9D,MAAI;AAACC,IAAAA,UAAD;AAAaC,IAAAA,UAAb;AAAyBC,IAAAA,QAAQ,GAAGP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uB,KAAzB,EAAqClC,KAArC,EAAoDlB,KAApD,EAA8D;AAC5D,MAAIoD,KAAK,CAAClC,KAAD,CAAL,KAAiBlB,KAArB,EAA4B;AAC1B,WAAOoD,KAAP;AACD;;AAED,SAAO,CAAC,GAAGA,KAAK,CAACC,KAAN,CAAY,CAAZ,EAAenC,KAAf,CAAJ,EAA2BlB,KAA3B,EAAkC,GAAGoD,KAAK,CAACC,KAAN,CAAYnC,KAAK,GAAG,CAApB,CAArC,CAAP;AACD","sources":["./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\nimport {clamp} from '@react-aria/utils';\nimport {SliderProps} from '@react-types/slider';\nimport {useControlledState} from '@react-stately/utils';\nimport {useNumberFormatter} from '@react-aria/i18n';\nimport {useRef, useState} from 'react';\n\nexport interface SliderState {\n // Values managed by the slider\n readonly values: number[],\n getThumbValue: (index: number) => number,\n\n // Sets value for thumb. The actually value set will be clamped and\n // rounded according to min/max/step\n setThumbValue: (index: number, value: number) => void,\n\n // Sets value for thumb by percent offset (between 0 and 1)\n setThumbPercent: (index: number, percent: number) => void,\n\n // Whether a specific index is being dragged\n isThumbDragging: (index: number) => boolean,\n setThumbDragging: (index: number, dragging: boolean) => void,\n\n // Currently-focused index\n readonly focusedThumb: number | undefined,\n setFocusedThumb: (index: number | undefined) => void,\n\n // Returns the value offset as a percentage from 0 to 1.\n getThumbPercent: (index: number) => number,\n getValuePercent: (value: number) => number,\n\n // Returns the string label for the value, per props.formatOptions\n getThumbValueLabel: (index: number) => string,\n getFormattedValue: (value: number) => string,\n\n // Returns the min and max values for the index\n getThumbMinValue: (index: number) => number,\n getThumbMaxValue: (index: number) => number,\n\n // Converts a percent along track (between 0 and 1) to the corresponding value\n getPercentValue: (percent: number) => number,\n\n // editable\n isThumbEditable: (index: number) => boolean,\n setThumbEditable: (index: number, editable: boolean) => void,\n\n // The step amount for the slider\n readonly step: number\n}\n\nexport const DEFAULT_MIN_VALUE = 0;\nexport const DEFAULT_MAX_VALUE = 100;\nexport const DEFAULT_STEP_VALUE = 1;\n\nexport function useSliderState(props: SliderProps): SliderState {\n let {isReadOnly, isDisabled, minValue = DEFAULT_MIN_VALUE, maxValue = DEFAULT_MAX_VALUE, formatOptions, 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 formatter = useNumberFormatter(formatOptions);\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 (isReadOnly || 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 = clamp(getRoundedValue(value), thisMin, thisMax);\n setValues(values => replaceIndex(values, index, value));\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isReadOnly || isDisabled || !isThumbEditable(index)) {\n return;\n }\n\n const newDraggings = replaceIndex(isDraggings, index, dragging);\n setDraggings(newDraggings);\n\n // Call onChangeEnd if no handles are dragging.\n if (props.onChangeEnd && isDraggings[index] && !newDraggings.some(Boolean)) {\n props.onChangeEnd(values);\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":["DEFAULT_MIN_VALUE","DEFAULT_MAX_VALUE","DEFAULT_STEP_VALUE","useSliderState","props","isReadOnly","isDisabled","minValue","maxValue","formatOptions","step","values","setValues","useControlledState","value","defaultValue","onChange","isDraggings","setDraggings","useState","Array","length","fill","isEditablesRef","useRef","focusedIndex","setFocusedIndex","undefined","formatter","useNumberFormatter","getValuePercent","getThumbMinValue","index","getThumbMaxValue","isThumbEditable","current","setThumbEditable","editable","updateValue","thisMin","thisMax","clamp","getRoundedValue","replaceIndex","updateDragging","dragging","newDraggings","onChangeEnd","some","Boolean","getFormattedValue","format","setThumbPercent","percent","getPercentValue","Math","round","val","getThumbValue","setThumbValue","isThumbDragging","setThumbDragging","focusedThumb","setFocusedThumb","getThumbPercent","getThumbValueLabel","array","slice"],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/slider/src/index.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 {useSliderState} from './useSliderState';\n\nexport type {SliderStateOptions} from './useSliderState';\nexport type {SliderState} from './useSliderState';\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,27 +1,125 @@
1
+ import { Orientation } from "@react-types/shared";
1
2
  import { SliderProps } from "@react-types/slider";
2
3
  export interface SliderState {
4
+ /**
5
+ * Values managed by the slider by thumb index.
6
+ */
3
7
  readonly values: number[];
4
- getThumbValue: (index: number) => number;
5
- setThumbValue: (index: number, value: number) => void;
6
- setThumbPercent: (index: number, percent: number) => void;
7
- isThumbDragging: (index: number) => boolean;
8
- setThumbDragging: (index: number, dragging: boolean) => void;
8
+ /**
9
+ * Get the value for the specified thumb.
10
+ * @param index
11
+ */
12
+ getThumbValue(index: number): number;
13
+ /**
14
+ * Sets the value for the specified thumb.
15
+ * The actual value set will be clamped and rounded according to min/max/step.
16
+ * @param index
17
+ * @param value
18
+ */
19
+ setThumbValue(index: number, value: number): void;
20
+ /**
21
+ * Sets value for the specified thumb by percent offset (between 0 and 1).
22
+ * @param index
23
+ * @param percent
24
+ */
25
+ setThumbPercent(index: number, percent: number): void;
26
+ /**
27
+ * Whether the specific thumb is being dragged.
28
+ * @param index
29
+ */
30
+ isThumbDragging(index: number): boolean;
31
+ /**
32
+ * Set is dragging on the specified thumb.
33
+ * @param index
34
+ * @param dragging
35
+ */
36
+ setThumbDragging(index: number, dragging: boolean): void;
37
+ /**
38
+ * Currently-focused thumb index.
39
+ */
9
40
  readonly focusedThumb: number | undefined;
10
- setFocusedThumb: (index: number | undefined) => void;
11
- getThumbPercent: (index: number) => number;
12
- getValuePercent: (value: number) => number;
13
- getThumbValueLabel: (index: number) => string;
14
- getFormattedValue: (value: number) => string;
15
- getThumbMinValue: (index: number) => number;
16
- getThumbMaxValue: (index: number) => number;
17
- getPercentValue: (percent: number) => number;
18
- isThumbEditable: (index: number) => boolean;
19
- setThumbEditable: (index: number, editable: boolean) => void;
41
+ /**
42
+ * Set focused true on specified thumb. This will remove focus from
43
+ * any thumb that had it before.
44
+ * @param index
45
+ */
46
+ setFocusedThumb(index: number | undefined): void;
47
+ /**
48
+ * Returns the specified thumb's value as a percentage from 0 to 1.
49
+ * @param index
50
+ */
51
+ getThumbPercent(index: number): number;
52
+ /**
53
+ * Returns the value as a percent between the min and max of the slider.
54
+ * @param index
55
+ */
56
+ getValuePercent(value: number): number;
57
+ /**
58
+ * Returns the string label for the specified thumb's value, per props.formatOptions.
59
+ * @param index
60
+ */
61
+ getThumbValueLabel(index: number): string;
62
+ /**
63
+ * Returns the string label for the value, per props.formatOptions.
64
+ * @param index
65
+ */
66
+ getFormattedValue(value: number): string;
67
+ /**
68
+ * Returns the min allowed value for the specified thumb.
69
+ * @param index
70
+ */
71
+ getThumbMinValue(index: number): number;
72
+ /**
73
+ * Returns the max allowed value for the specified thumb.
74
+ * @param index
75
+ */
76
+ getThumbMaxValue(index: number): number;
77
+ /**
78
+ * Converts a percent along track (between 0 and 1) to the corresponding value.
79
+ * @param percent
80
+ */
81
+ getPercentValue(percent: number): number;
82
+ /**
83
+ * Returns if the specified thumb is editable.
84
+ * @param index
85
+ */
86
+ isThumbEditable(index: number): boolean;
87
+ /**
88
+ * Set the specified thumb's editable state.
89
+ * @param index
90
+ * @param editable
91
+ */
92
+ setThumbEditable(index: number, editable: boolean): void;
93
+ /**
94
+ * Increments the value of the thumb by the step or page amount.
95
+ */
96
+ incrementThumb(index: number, stepSize?: number): void;
97
+ /**
98
+ * Decrements the value of the thumb by the step or page amount.
99
+ */
100
+ decrementThumb(index: number, stepSize?: number): void;
101
+ /**
102
+ * The step amount for the slider.
103
+ */
20
104
  readonly step: number;
105
+ /**
106
+ * The page size for the slider, used to do a bigger step.
107
+ */
108
+ readonly pageSize: number;
109
+ /** The orientation of the slider. */
110
+ readonly orientation: Orientation;
111
+ /** Whether the slider is disabled. */
112
+ readonly isDisabled: boolean;
21
113
  }
22
- export const DEFAULT_MIN_VALUE = 0;
23
- export const DEFAULT_MAX_VALUE = 100;
24
- export const DEFAULT_STEP_VALUE = 1;
25
- export function useSliderState(props: SliderProps): SliderState;
114
+ export interface SliderStateOptions<T> extends SliderProps<T> {
115
+ numberFormatter: Intl.NumberFormat;
116
+ }
117
+ /**
118
+ * Provides state management for a slider component. Stores values for all thumbs,
119
+ * formats values for localization, and provides methods to update the position
120
+ * of any thumbs.
121
+ * @param props
122
+ */
123
+ export function useSliderState<T extends number | number[]>(props: SliderStateOptions<T>): SliderState;
26
124
 
27
125
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"mappings":"A;AAkBA;IAEE,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAIzC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAGtD,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAG1D,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5C,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAG7D,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAGrD,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3C,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAG3C,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C,iBAAiB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAG7C,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC5C,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAG5C,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IAG7C,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5C,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAG7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAED,OAAO,MAAM,qBAAqB,CAAC;AACnC,OAAO,MAAM,uBAAuB,CAAC;AACrC,OAAO,MAAM,sBAAsB,CAAC;AAEpC,+BAA+B,KAAK,EAAE,WAAW,GAAG,WAAW,CAgG9D","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"],"sourcesContent":[null,null],"names":[],"version":3,"file":"types.d.ts.map"}
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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AAC;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,CAAC;IAE1B,qCAAqC;IACrC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAElC,sCAAsC;IACtC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;CAC7B;AAMD,oCAAoC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC;IAC3D,eAAe,EAAE,KAAK,YAAY,CAAA;CACnC;AAED;;;;;GAKG;AACH,+BAA+B,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,mBAAmB,CAAC,CAAC,GAAG,WAAW,CAwJrG","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 {useSliderState} from './useSliderState';\n\nexport type {SliderStateOptions} from './useSliderState';\nexport type {SliderState} from './useSliderState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}