@react-stately/slider 3.7.5 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/import.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import {useSliderState as $28f99e3e86e6ec45$export$e5fda3247f5d67f9} from "./useSliderState.mjs";
1
+ import {useSliderState as $100b2794a799746e$re_export$useSliderState} from "react-stately/useSliderState";
2
2
 
3
3
  /*
4
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useSliderState as $28f99e3e86e6ec45$export$e5fda3247f5d67f9} from "./use
13
13
  */
14
14
 
15
15
 
16
- export {$28f99e3e86e6ec45$export$e5fda3247f5d67f9 as useSliderState};
16
+ export {$100b2794a799746e$re_export$useSliderState as useSliderState};
17
17
  //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,11 +1,11 @@
1
- var $e86753598efd0f02$exports = require("./useSliderState.main.js");
1
+ var $d8n7J$reactstatelyuseSliderState = require("react-stately/useSliderState");
2
2
 
3
3
 
4
4
  function $parcel$export(e, n, v, s) {
5
5
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
6
  }
7
7
 
8
- $parcel$export(module.exports, "useSliderState", () => $e86753598efd0f02$exports.useSliderState);
8
+ $parcel$export(module.exports, "useSliderState", function () { return $d8n7J$reactstatelyuseSliderState.useSliderState; });
9
9
  /*
10
10
  * Copyright 2020 Adobe. All rights reserved.
11
11
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
package/dist/main.js.map CHANGED
@@ -1 +1 @@
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"}
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 'react-stately/useSliderState';\n\nexport type {SliderProps, SliderStateOptions, SliderState} from 'react-stately/useSliderState';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import {useSliderState as $28f99e3e86e6ec45$export$e5fda3247f5d67f9} from "./useSliderState.module.js";
1
+ import {useSliderState as $100b2794a799746e$re_export$useSliderState} from "react-stately/useSliderState";
2
2
 
3
3
  /*
4
4
  * Copyright 2020 Adobe. All rights reserved.
@@ -13,5 +13,5 @@ import {useSliderState as $28f99e3e86e6ec45$export$e5fda3247f5d67f9} from "./use
13
13
  */
14
14
 
15
15
 
16
- export {$28f99e3e86e6ec45$export$e5fda3247f5d67f9 as useSliderState};
16
+ export {$100b2794a799746e$re_export$useSliderState as useSliderState};
17
17
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
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"}
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 'react-stately/useSliderState';\n\nexport type {SliderProps, SliderStateOptions, SliderState} from 'react-stately/useSliderState';\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -0,0 +1,2 @@
1
+ export { useSliderState } from 'react-stately/useSliderState';
2
+ export type { SliderProps, SliderStateOptions, SliderState } from 'react-stately/useSliderState';
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "name": "@react-stately/slider",
3
- "version": "3.7.5",
3
+ "version": "3.8.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
8
  "exports": {
9
- "source": "./src/index.ts",
10
- "types": [
11
- "./dist/types.d.ts",
12
- "./src/index.ts"
13
- ],
14
- "import": "./dist/import.mjs",
15
- "require": "./dist/main.js"
9
+ ".": {
10
+ "source": "./src/index.ts",
11
+ "types": "./dist/types/src/index.d.ts",
12
+ "import": "./dist/import.mjs",
13
+ "require": "./dist/main.js"
14
+ },
15
+ "./package.json": "./package.json"
16
16
  },
17
- "types": "dist/types.d.ts",
17
+ "types": "dist/types/src/index.d.ts",
18
18
  "source": "src/index.ts",
19
19
  "files": [
20
20
  "dist",
@@ -26,16 +26,18 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-stately/utils": "^3.11.0",
30
- "@react-types/shared": "^3.33.1",
31
- "@react-types/slider": "^3.8.4",
32
- "@swc/helpers": "^0.5.0"
29
+ "@swc/helpers": "^0.5.0",
30
+ "react-stately": "3.46.0"
33
31
  },
34
32
  "peerDependencies": {
35
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
33
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
34
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
36
35
  },
37
36
  "publishConfig": {
38
37
  "access": "public"
39
38
  },
40
- "gitHead": "8df187370053aa35f553cb388ad670f65e1ab371"
39
+ "targets": {
40
+ "types": false
41
+ },
42
+ "gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
41
43
  }
package/src/index.ts CHANGED
@@ -10,7 +10,6 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- export {useSliderState} from './useSliderState';
13
+ export {useSliderState} from 'react-stately/useSliderState';
14
14
 
15
- export type {SliderStateOptions} from './useSliderState';
16
- export type {SliderState} from './useSliderState';
15
+ export type {SliderProps, SliderStateOptions, SliderState} from 'react-stately/useSliderState';
package/dist/types.d.ts DELETED
@@ -1,129 +0,0 @@
1
- import { Orientation } from "@react-types/shared";
2
- import { SliderProps } from "@react-types/slider";
3
- export interface SliderState {
4
- /**
5
- * Values managed by the slider by thumb index.
6
- */
7
- readonly values: number[];
8
- /**
9
- * The default values for each thumb.
10
- */
11
- readonly defaultValues: number[];
12
- /**
13
- * Get the value for the specified thumb.
14
- * @param index
15
- */
16
- getThumbValue(index: number): number;
17
- /**
18
- * Sets the value for the specified thumb.
19
- * The actual value set will be clamped and rounded according to min/max/step.
20
- * @param index
21
- * @param value
22
- */
23
- setThumbValue(index: number, value: number): void;
24
- /**
25
- * Sets value for the specified thumb by percent offset (between 0 and 1).
26
- * @param index
27
- * @param percent
28
- */
29
- setThumbPercent(index: number, percent: number): void;
30
- /**
31
- * Whether the specific thumb is being dragged.
32
- * @param index
33
- */
34
- isThumbDragging(index: number): boolean;
35
- /**
36
- * Set is dragging on the specified thumb.
37
- * @param index
38
- * @param dragging
39
- */
40
- setThumbDragging(index: number, dragging: boolean): void;
41
- /**
42
- * Currently-focused thumb index.
43
- */
44
- readonly focusedThumb: number | undefined;
45
- /**
46
- * Set focused true on specified thumb. This will remove focus from
47
- * any thumb that had it before.
48
- * @param index
49
- */
50
- setFocusedThumb(index: number | undefined): void;
51
- /**
52
- * Returns the specified thumb's value as a percentage from 0 to 1.
53
- * @param index
54
- */
55
- getThumbPercent(index: number): number;
56
- /**
57
- * Returns the value as a percent between the min and max of the slider.
58
- * @param index
59
- */
60
- getValuePercent(value: number): number;
61
- /**
62
- * Returns the string label for the specified thumb's value, per props.formatOptions.
63
- * @param index
64
- */
65
- getThumbValueLabel(index: number): string;
66
- /**
67
- * Returns the string label for the value, per props.formatOptions.
68
- * @param index
69
- */
70
- getFormattedValue(value: number): string;
71
- /**
72
- * Returns the min allowed value for the specified thumb.
73
- * @param index
74
- */
75
- getThumbMinValue(index: number): number;
76
- /**
77
- * Returns the max allowed value for the specified thumb.
78
- * @param index
79
- */
80
- getThumbMaxValue(index: number): number;
81
- /**
82
- * Converts a percent along track (between 0 and 1) to the corresponding value.
83
- * @param percent
84
- */
85
- getPercentValue(percent: number): number;
86
- /**
87
- * Returns if the specified thumb is editable.
88
- * @param index
89
- */
90
- isThumbEditable(index: number): boolean;
91
- /**
92
- * Set the specified thumb's editable state.
93
- * @param index
94
- * @param editable
95
- */
96
- setThumbEditable(index: number, editable: boolean): void;
97
- /**
98
- * Increments the value of the thumb by the step or page amount.
99
- */
100
- incrementThumb(index: number, stepSize?: number): void;
101
- /**
102
- * Decrements the value of the thumb by the step or page amount.
103
- */
104
- decrementThumb(index: number, stepSize?: number): void;
105
- /**
106
- * The step amount for the slider.
107
- */
108
- readonly step: number;
109
- /**
110
- * The page size for the slider, used to do a bigger step.
111
- */
112
- readonly pageSize: number;
113
- /** The orientation of the slider. */
114
- readonly orientation: Orientation;
115
- /** Whether the slider is disabled. */
116
- readonly isDisabled: boolean;
117
- }
118
- export interface SliderStateOptions<T> extends SliderProps<T> {
119
- numberFormatter: Intl.NumberFormat;
120
- }
121
- /**
122
- * Provides state management for a slider component. Stores values for all thumbs,
123
- * formats values for localization, and provides methods to update the position
124
- * of any thumbs.
125
- * @param props
126
- */
127
- export function useSliderState<T extends number | number[]>(props: SliderStateOptions<T>): SliderState;
128
-
129
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAiBA;IACE;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAC1B;;OAEG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,EAAE,CAAC;IACjC;;;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;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtD;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACxC;;;;OAIG;IACH,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AE,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,CA0JrG","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"}
@@ -1,180 +0,0 @@
1
- var $1NNdE$reactstatelyutils = require("@react-stately/utils");
2
- var $1NNdE$react = require("react");
3
-
4
-
5
- function $parcel$export(e, n, v, s) {
6
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
7
- }
8
-
9
- $parcel$export(module.exports, "useSliderState", () => $e86753598efd0f02$export$e5fda3247f5d67f9);
10
- /*
11
- * Copyright 2020 Adobe. All rights reserved.
12
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License. You may obtain a copy
14
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
15
- *
16
- * Unless required by applicable law or agreed to in writing, software distributed under
17
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
18
- * OF ANY KIND, either express or implied. See the License for the specific language
19
- * governing permissions and limitations under the License.
20
- */
21
-
22
- const $e86753598efd0f02$var$DEFAULT_MIN_VALUE = 0;
23
- const $e86753598efd0f02$var$DEFAULT_MAX_VALUE = 100;
24
- const $e86753598efd0f02$var$DEFAULT_STEP_VALUE = 1;
25
- function $e86753598efd0f02$export$e5fda3247f5d67f9(props) {
26
- const { isDisabled: isDisabled = false, minValue: minValue = $e86753598efd0f02$var$DEFAULT_MIN_VALUE, maxValue: maxValue = $e86753598efd0f02$var$DEFAULT_MAX_VALUE, numberFormatter: formatter, step: step = $e86753598efd0f02$var$DEFAULT_STEP_VALUE, orientation: orientation = 'horizontal' } = props;
27
- // Page step should be at least equal to step and always a multiple of the step.
28
- let pageSize = (0, $1NNdE$react.useMemo)(()=>{
29
- let calcPageSize = (maxValue - minValue) / 10;
30
- calcPageSize = (0, $1NNdE$reactstatelyutils.snapValueToStep)(calcPageSize, 0, calcPageSize + step, step);
31
- return Math.max(calcPageSize, step);
32
- }, [
33
- step,
34
- maxValue,
35
- minValue
36
- ]);
37
- let restrictValues = (0, $1NNdE$react.useCallback)((values)=>values === null || values === void 0 ? void 0 : values.map((val, idx)=>{
38
- let min = idx === 0 ? minValue : values[idx - 1];
39
- let max = idx === values.length - 1 ? maxValue : values[idx + 1];
40
- return (0, $1NNdE$reactstatelyutils.snapValueToStep)(val, min, max, step);
41
- }), [
42
- minValue,
43
- maxValue,
44
- step
45
- ]);
46
- let value = (0, $1NNdE$react.useMemo)(()=>restrictValues($e86753598efd0f02$var$convertValue(props.value)), [
47
- props.value,
48
- restrictValues
49
- ]);
50
- let defaultValue = (0, $1NNdE$react.useMemo)(()=>{
51
- var _convertValue;
52
- return restrictValues((_convertValue = $e86753598efd0f02$var$convertValue(props.defaultValue)) !== null && _convertValue !== void 0 ? _convertValue : [
53
- minValue
54
- ]);
55
- }, [
56
- props.defaultValue,
57
- minValue,
58
- restrictValues
59
- ]);
60
- let onChange = $e86753598efd0f02$var$createOnChange(props.value, props.defaultValue, props.onChange);
61
- let onChangeEnd = $e86753598efd0f02$var$createOnChange(props.value, props.defaultValue, props.onChangeEnd);
62
- const [values, setValuesState] = (0, $1NNdE$reactstatelyutils.useControlledState)(value, defaultValue, onChange);
63
- let [initialValues] = (0, $1NNdE$react.useState)(values);
64
- const [isDraggings, setDraggingsState] = (0, $1NNdE$react.useState)(new Array(values.length).fill(false));
65
- const isEditablesRef = (0, $1NNdE$react.useRef)(new Array(values.length).fill(true));
66
- const [focusedIndex, setFocusedIndex] = (0, $1NNdE$react.useState)(undefined);
67
- const valuesRef = (0, $1NNdE$react.useRef)(values);
68
- const isDraggingsRef = (0, $1NNdE$react.useRef)(isDraggings);
69
- let setValues = (values)=>{
70
- valuesRef.current = values;
71
- setValuesState(values);
72
- };
73
- let setDraggings = (draggings)=>{
74
- isDraggingsRef.current = draggings;
75
- setDraggingsState(draggings);
76
- };
77
- function getValuePercent(value) {
78
- return (value - minValue) / (maxValue - minValue);
79
- }
80
- function getThumbMinValue(index) {
81
- return index === 0 ? minValue : values[index - 1];
82
- }
83
- function getThumbMaxValue(index) {
84
- return index === values.length - 1 ? maxValue : values[index + 1];
85
- }
86
- function isThumbEditable(index) {
87
- return isEditablesRef.current[index];
88
- }
89
- function setThumbEditable(index, editable) {
90
- isEditablesRef.current[index] = editable;
91
- }
92
- function updateValue(index, value) {
93
- if (isDisabled || !isThumbEditable(index)) return;
94
- const thisMin = getThumbMinValue(index);
95
- const thisMax = getThumbMaxValue(index);
96
- // Round value to multiple of step, clamp value between min and max
97
- value = (0, $1NNdE$reactstatelyutils.snapValueToStep)(value, thisMin, thisMax, step);
98
- let newValues = $e86753598efd0f02$var$replaceIndex(valuesRef.current, index, value);
99
- setValues(newValues);
100
- }
101
- function updateDragging(index, dragging) {
102
- if (isDisabled || !isThumbEditable(index)) return;
103
- if (dragging) valuesRef.current = values;
104
- const wasDragging = isDraggingsRef.current[index];
105
- isDraggingsRef.current = $e86753598efd0f02$var$replaceIndex(isDraggingsRef.current, index, dragging);
106
- setDraggings(isDraggingsRef.current);
107
- // Call onChangeEnd if no handles are dragging.
108
- if (onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) onChangeEnd(valuesRef.current);
109
- }
110
- function getFormattedValue(value) {
111
- return formatter.format(value);
112
- }
113
- function setThumbPercent(index, percent) {
114
- updateValue(index, getPercentValue(percent));
115
- }
116
- function getRoundedValue(value) {
117
- return Math.round((value - minValue) / step) * step + minValue;
118
- }
119
- function getPercentValue(percent) {
120
- const val = percent * (maxValue - minValue) + minValue;
121
- return (0, $1NNdE$reactstatelyutils.clamp)(getRoundedValue(val), minValue, maxValue);
122
- }
123
- function incrementThumb(index, stepSize = 1) {
124
- let s = Math.max(stepSize, step);
125
- updateValue(index, (0, $1NNdE$reactstatelyutils.snapValueToStep)(values[index] + s, minValue, maxValue, step));
126
- }
127
- function decrementThumb(index, stepSize = 1) {
128
- let s = Math.max(stepSize, step);
129
- updateValue(index, (0, $1NNdE$reactstatelyutils.snapValueToStep)(values[index] - s, minValue, maxValue, step));
130
- }
131
- return {
132
- values: values,
133
- defaultValues: props.defaultValue !== undefined ? defaultValue : initialValues,
134
- getThumbValue: (index)=>values[index],
135
- setThumbValue: updateValue,
136
- setThumbPercent: setThumbPercent,
137
- isThumbDragging: (index)=>isDraggings[index],
138
- setThumbDragging: updateDragging,
139
- focusedThumb: focusedIndex,
140
- setFocusedThumb: setFocusedIndex,
141
- getThumbPercent: (index)=>getValuePercent(values[index]),
142
- getValuePercent: getValuePercent,
143
- getThumbValueLabel: (index)=>getFormattedValue(values[index]),
144
- getFormattedValue: getFormattedValue,
145
- getThumbMinValue: getThumbMinValue,
146
- getThumbMaxValue: getThumbMaxValue,
147
- getPercentValue: getPercentValue,
148
- isThumbEditable: isThumbEditable,
149
- setThumbEditable: setThumbEditable,
150
- incrementThumb: incrementThumb,
151
- decrementThumb: decrementThumb,
152
- step: step,
153
- pageSize: pageSize,
154
- orientation: orientation,
155
- isDisabled: isDisabled
156
- };
157
- }
158
- function $e86753598efd0f02$var$replaceIndex(array, index, value) {
159
- if (array[index] === value) return array;
160
- return [
161
- ...array.slice(0, index),
162
- value,
163
- ...array.slice(index + 1)
164
- ];
165
- }
166
- function $e86753598efd0f02$var$convertValue(value) {
167
- if (value == null) return undefined;
168
- return Array.isArray(value) ? value : [
169
- value
170
- ];
171
- }
172
- function $e86753598efd0f02$var$createOnChange(value, defaultValue, onChange) {
173
- return (newValue)=>{
174
- if (typeof value === 'number' || typeof defaultValue === 'number') onChange === null || onChange === void 0 ? void 0 : onChange(newValue[0]);
175
- else onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
176
- };
177
- }
178
-
179
-
180
- //# sourceMappingURL=useSliderState.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA6ID,MAAM,0CAAoB;AAC1B,MAAM,0CAAoB;AAC1B,MAAM,2CAAqB;AAYpB,SAAS,0CAA4C,KAA4B;IACtF,MAAM,cACJ,aAAa,iBACb,WAAW,mDACX,WAAW,yCACX,iBAAiB,SAAS,QAC1B,OAAO,uDACP,cAAc,cACf,GAAG;IAEJ,gFAAgF;IAChF,IAAI,WAAW,CAAA,GAAA,oBAAM,EAAE;QACrB,IAAI,eAAe,AAAC,CAAA,WAAW,QAAO,IAAK;QAC3C,eAAe,CAAA,GAAA,wCAAc,EAAE,cAAc,GAAG,eAAe,MAAM;QACrE,OAAO,KAAK,GAAG,CAAC,cAAc;IAChC,GAAG;QAAC;QAAM;QAAU;KAAS;IAE7B,IAAI,iBAAiB,CAAA,GAAA,wBAAU,EAAE,CAAC,SAAiC,mBAAA,6BAAA,OAAQ,GAAG,CAAC,CAAC,KAAK;YACnF,IAAI,MAAM,QAAQ,IAAI,WAAW,MAAM,CAAC,MAAM,EAAE;YAChD,IAAI,MAAM,QAAQ,O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;AAC/C;AAEA,SAAS,qCAAe,KAAK,EAAE,YAAY,EAAE,QAAQ;IACnD,OAAO,CAAC;QACN,IAAI,OAAO,UAAU,YAAY,OAAO,iBAAiB,UACvD,qBAAA,+BAAA,SAAW,QAAQ,CAAC,EAAE;aAEtB,qBAAA,+BAAA,SAAW;IAEf;AACF","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, snapValueToStep, useControlledState} from '@react-stately/utils';\nimport {Orientation} from '@react-types/shared';\nimport {SliderProps} from '@react-types/slider';\nimport {useCallback, useMemo, 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 * The default values for each thumb.\n */\n readonly defaultValues: 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 /** The orientation of the slider. */\n readonly orientation: Orientation,\n\n /** Whether the slider is disabled. */\n readonly isDisabled: boolean\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\nexport interface SliderStateOptions<T> extends SliderProps<T> {\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<T extends number | number[]>(props: SliderStateOptions<T>): SliderState {\n const {\n isDisabled = false,\n minValue = DEFAULT_MIN_VALUE,\n maxValue = DEFAULT_MAX_VALUE,\n numberFormatter: formatter,\n step = DEFAULT_STEP_VALUE,\n orientation = 'horizontal'\n } = props;\n\n // Page step should be at least equal to step and always a multiple of the step.\n let pageSize = useMemo(() => {\n let calcPageSize = (maxValue - minValue) / 10;\n calcPageSize = snapValueToStep(calcPageSize, 0, calcPageSize + step, step);\n return Math.max(calcPageSize, step);\n }, [step, maxValue, minValue]);\n\n let restrictValues = useCallback((values: number[] | undefined) => values?.map((val, idx) => {\n let min = idx === 0 ? minValue : values[idx - 1];\n let max = idx === values.length - 1 ? maxValue : values[idx + 1];\n return snapValueToStep(val, min, max, step);\n }), [minValue, maxValue, step]);\n\n let value = useMemo(() => restrictValues(convertValue(props.value)), [props.value, restrictValues]);\n let defaultValue = useMemo(() => restrictValues(convertValue(props.defaultValue) ?? [minValue])!, [props.defaultValue, minValue, restrictValues]);\n let onChange = createOnChange(props.value, props.defaultValue, props.onChange);\n let onChangeEnd = createOnChange(props.value, props.defaultValue, props.onChangeEnd);\n\n const [values, setValuesState] = useControlledState<number[]>(\n value,\n defaultValue,\n onChange\n );\n let [initialValues] = useState(values);\n const [isDraggings, setDraggingsState] = 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[]>(values);\n const isDraggingsRef = useRef<boolean[]>(isDraggings);\n\n let setValues = (values: number[]) => {\n valuesRef.current = values;\n setValuesState(values);\n };\n\n let setDraggings = (draggings: boolean[]) => {\n isDraggingsRef.current = draggings;\n setDraggingsState(draggings);\n };\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 let newValues = replaceIndex(valuesRef.current, index, value);\n setValues(newValues);\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n if (dragging) {\n valuesRef.current = values;\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 (onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n 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 defaultValues: props.defaultValue !== undefined ? defaultValue : initialValues,\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 orientation,\n isDisabled\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\nfunction convertValue(value?: number | number[]) {\n if (value == null) {\n return undefined;\n }\n\n return Array.isArray(value) ? value : [value];\n}\n\nfunction createOnChange(value, defaultValue, onChange) {\n return (newValue: number[]) => {\n if (typeof value === 'number' || typeof defaultValue === 'number') {\n onChange?.(newValue[0]);\n } else {\n onChange?.(newValue);\n }\n };\n}\n"],"names":[],"version":3,"file":"useSliderState.main.js.map"}
@@ -1,175 +0,0 @@
1
- import {snapValueToStep as $BT4Uh$snapValueToStep, useControlledState as $BT4Uh$useControlledState, clamp as $BT4Uh$clamp} from "@react-stately/utils";
2
- import {useMemo as $BT4Uh$useMemo, useCallback as $BT4Uh$useCallback, useState as $BT4Uh$useState, useRef as $BT4Uh$useRef} from "react";
3
-
4
- /*
5
- * Copyright 2020 Adobe. All rights reserved.
6
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License. You may obtain a copy
8
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software distributed under
11
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- * OF ANY KIND, either express or implied. See the License for the specific language
13
- * governing permissions and limitations under the License.
14
- */
15
-
16
- const $28f99e3e86e6ec45$var$DEFAULT_MIN_VALUE = 0;
17
- const $28f99e3e86e6ec45$var$DEFAULT_MAX_VALUE = 100;
18
- const $28f99e3e86e6ec45$var$DEFAULT_STEP_VALUE = 1;
19
- function $28f99e3e86e6ec45$export$e5fda3247f5d67f9(props) {
20
- const { isDisabled: isDisabled = false, minValue: minValue = $28f99e3e86e6ec45$var$DEFAULT_MIN_VALUE, maxValue: maxValue = $28f99e3e86e6ec45$var$DEFAULT_MAX_VALUE, numberFormatter: formatter, step: step = $28f99e3e86e6ec45$var$DEFAULT_STEP_VALUE, orientation: orientation = 'horizontal' } = props;
21
- // Page step should be at least equal to step and always a multiple of the step.
22
- let pageSize = (0, $BT4Uh$useMemo)(()=>{
23
- let calcPageSize = (maxValue - minValue) / 10;
24
- calcPageSize = (0, $BT4Uh$snapValueToStep)(calcPageSize, 0, calcPageSize + step, step);
25
- return Math.max(calcPageSize, step);
26
- }, [
27
- step,
28
- maxValue,
29
- minValue
30
- ]);
31
- let restrictValues = (0, $BT4Uh$useCallback)((values)=>values === null || values === void 0 ? void 0 : values.map((val, idx)=>{
32
- let min = idx === 0 ? minValue : values[idx - 1];
33
- let max = idx === values.length - 1 ? maxValue : values[idx + 1];
34
- return (0, $BT4Uh$snapValueToStep)(val, min, max, step);
35
- }), [
36
- minValue,
37
- maxValue,
38
- step
39
- ]);
40
- let value = (0, $BT4Uh$useMemo)(()=>restrictValues($28f99e3e86e6ec45$var$convertValue(props.value)), [
41
- props.value,
42
- restrictValues
43
- ]);
44
- let defaultValue = (0, $BT4Uh$useMemo)(()=>{
45
- var _convertValue;
46
- return restrictValues((_convertValue = $28f99e3e86e6ec45$var$convertValue(props.defaultValue)) !== null && _convertValue !== void 0 ? _convertValue : [
47
- minValue
48
- ]);
49
- }, [
50
- props.defaultValue,
51
- minValue,
52
- restrictValues
53
- ]);
54
- let onChange = $28f99e3e86e6ec45$var$createOnChange(props.value, props.defaultValue, props.onChange);
55
- let onChangeEnd = $28f99e3e86e6ec45$var$createOnChange(props.value, props.defaultValue, props.onChangeEnd);
56
- const [values, setValuesState] = (0, $BT4Uh$useControlledState)(value, defaultValue, onChange);
57
- let [initialValues] = (0, $BT4Uh$useState)(values);
58
- const [isDraggings, setDraggingsState] = (0, $BT4Uh$useState)(new Array(values.length).fill(false));
59
- const isEditablesRef = (0, $BT4Uh$useRef)(new Array(values.length).fill(true));
60
- const [focusedIndex, setFocusedIndex] = (0, $BT4Uh$useState)(undefined);
61
- const valuesRef = (0, $BT4Uh$useRef)(values);
62
- const isDraggingsRef = (0, $BT4Uh$useRef)(isDraggings);
63
- let setValues = (values)=>{
64
- valuesRef.current = values;
65
- setValuesState(values);
66
- };
67
- let setDraggings = (draggings)=>{
68
- isDraggingsRef.current = draggings;
69
- setDraggingsState(draggings);
70
- };
71
- function getValuePercent(value) {
72
- return (value - minValue) / (maxValue - minValue);
73
- }
74
- function getThumbMinValue(index) {
75
- return index === 0 ? minValue : values[index - 1];
76
- }
77
- function getThumbMaxValue(index) {
78
- return index === values.length - 1 ? maxValue : values[index + 1];
79
- }
80
- function isThumbEditable(index) {
81
- return isEditablesRef.current[index];
82
- }
83
- function setThumbEditable(index, editable) {
84
- isEditablesRef.current[index] = editable;
85
- }
86
- function updateValue(index, value) {
87
- if (isDisabled || !isThumbEditable(index)) return;
88
- const thisMin = getThumbMinValue(index);
89
- const thisMax = getThumbMaxValue(index);
90
- // Round value to multiple of step, clamp value between min and max
91
- value = (0, $BT4Uh$snapValueToStep)(value, thisMin, thisMax, step);
92
- let newValues = $28f99e3e86e6ec45$var$replaceIndex(valuesRef.current, index, value);
93
- setValues(newValues);
94
- }
95
- function updateDragging(index, dragging) {
96
- if (isDisabled || !isThumbEditable(index)) return;
97
- if (dragging) valuesRef.current = values;
98
- const wasDragging = isDraggingsRef.current[index];
99
- isDraggingsRef.current = $28f99e3e86e6ec45$var$replaceIndex(isDraggingsRef.current, index, dragging);
100
- setDraggings(isDraggingsRef.current);
101
- // Call onChangeEnd if no handles are dragging.
102
- if (onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) onChangeEnd(valuesRef.current);
103
- }
104
- function getFormattedValue(value) {
105
- return formatter.format(value);
106
- }
107
- function setThumbPercent(index, percent) {
108
- updateValue(index, getPercentValue(percent));
109
- }
110
- function getRoundedValue(value) {
111
- return Math.round((value - minValue) / step) * step + minValue;
112
- }
113
- function getPercentValue(percent) {
114
- const val = percent * (maxValue - minValue) + minValue;
115
- return (0, $BT4Uh$clamp)(getRoundedValue(val), minValue, maxValue);
116
- }
117
- function incrementThumb(index, stepSize = 1) {
118
- let s = Math.max(stepSize, step);
119
- updateValue(index, (0, $BT4Uh$snapValueToStep)(values[index] + s, minValue, maxValue, step));
120
- }
121
- function decrementThumb(index, stepSize = 1) {
122
- let s = Math.max(stepSize, step);
123
- updateValue(index, (0, $BT4Uh$snapValueToStep)(values[index] - s, minValue, maxValue, step));
124
- }
125
- return {
126
- values: values,
127
- defaultValues: props.defaultValue !== undefined ? defaultValue : initialValues,
128
- getThumbValue: (index)=>values[index],
129
- setThumbValue: updateValue,
130
- setThumbPercent: setThumbPercent,
131
- isThumbDragging: (index)=>isDraggings[index],
132
- setThumbDragging: updateDragging,
133
- focusedThumb: focusedIndex,
134
- setFocusedThumb: setFocusedIndex,
135
- getThumbPercent: (index)=>getValuePercent(values[index]),
136
- getValuePercent: getValuePercent,
137
- getThumbValueLabel: (index)=>getFormattedValue(values[index]),
138
- getFormattedValue: getFormattedValue,
139
- getThumbMinValue: getThumbMinValue,
140
- getThumbMaxValue: getThumbMaxValue,
141
- getPercentValue: getPercentValue,
142
- isThumbEditable: isThumbEditable,
143
- setThumbEditable: setThumbEditable,
144
- incrementThumb: incrementThumb,
145
- decrementThumb: decrementThumb,
146
- step: step,
147
- pageSize: pageSize,
148
- orientation: orientation,
149
- isDisabled: isDisabled
150
- };
151
- }
152
- function $28f99e3e86e6ec45$var$replaceIndex(array, index, value) {
153
- if (array[index] === value) return array;
154
- return [
155
- ...array.slice(0, index),
156
- value,
157
- ...array.slice(index + 1)
158
- ];
159
- }
160
- function $28f99e3e86e6ec45$var$convertValue(value) {
161
- if (value == null) return undefined;
162
- return Array.isArray(value) ? value : [
163
- value
164
- ];
165
- }
166
- function $28f99e3e86e6ec45$var$createOnChange(value, defaultValue, onChange) {
167
- return (newValue)=>{
168
- if (typeof value === 'number' || typeof defaultValue === 'number') onChange === null || onChange === void 0 ? void 0 : onChange(newValue[0]);
169
- else onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
170
- };
171
- }
172
-
173
-
174
- export {$28f99e3e86e6ec45$export$e5fda3247f5d67f9 as useSliderState};
175
- //# sourceMappingURL=useSliderState.module.js.map
@@ -1,175 +0,0 @@
1
- import {snapValueToStep as $BT4Uh$snapValueToStep, useControlledState as $BT4Uh$useControlledState, clamp as $BT4Uh$clamp} from "@react-stately/utils";
2
- import {useMemo as $BT4Uh$useMemo, useCallback as $BT4Uh$useCallback, useState as $BT4Uh$useState, useRef as $BT4Uh$useRef} from "react";
3
-
4
- /*
5
- * Copyright 2020 Adobe. All rights reserved.
6
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License. You may obtain a copy
8
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software distributed under
11
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- * OF ANY KIND, either express or implied. See the License for the specific language
13
- * governing permissions and limitations under the License.
14
- */
15
-
16
- const $28f99e3e86e6ec45$var$DEFAULT_MIN_VALUE = 0;
17
- const $28f99e3e86e6ec45$var$DEFAULT_MAX_VALUE = 100;
18
- const $28f99e3e86e6ec45$var$DEFAULT_STEP_VALUE = 1;
19
- function $28f99e3e86e6ec45$export$e5fda3247f5d67f9(props) {
20
- const { isDisabled: isDisabled = false, minValue: minValue = $28f99e3e86e6ec45$var$DEFAULT_MIN_VALUE, maxValue: maxValue = $28f99e3e86e6ec45$var$DEFAULT_MAX_VALUE, numberFormatter: formatter, step: step = $28f99e3e86e6ec45$var$DEFAULT_STEP_VALUE, orientation: orientation = 'horizontal' } = props;
21
- // Page step should be at least equal to step and always a multiple of the step.
22
- let pageSize = (0, $BT4Uh$useMemo)(()=>{
23
- let calcPageSize = (maxValue - minValue) / 10;
24
- calcPageSize = (0, $BT4Uh$snapValueToStep)(calcPageSize, 0, calcPageSize + step, step);
25
- return Math.max(calcPageSize, step);
26
- }, [
27
- step,
28
- maxValue,
29
- minValue
30
- ]);
31
- let restrictValues = (0, $BT4Uh$useCallback)((values)=>values === null || values === void 0 ? void 0 : values.map((val, idx)=>{
32
- let min = idx === 0 ? minValue : values[idx - 1];
33
- let max = idx === values.length - 1 ? maxValue : values[idx + 1];
34
- return (0, $BT4Uh$snapValueToStep)(val, min, max, step);
35
- }), [
36
- minValue,
37
- maxValue,
38
- step
39
- ]);
40
- let value = (0, $BT4Uh$useMemo)(()=>restrictValues($28f99e3e86e6ec45$var$convertValue(props.value)), [
41
- props.value,
42
- restrictValues
43
- ]);
44
- let defaultValue = (0, $BT4Uh$useMemo)(()=>{
45
- var _convertValue;
46
- return restrictValues((_convertValue = $28f99e3e86e6ec45$var$convertValue(props.defaultValue)) !== null && _convertValue !== void 0 ? _convertValue : [
47
- minValue
48
- ]);
49
- }, [
50
- props.defaultValue,
51
- minValue,
52
- restrictValues
53
- ]);
54
- let onChange = $28f99e3e86e6ec45$var$createOnChange(props.value, props.defaultValue, props.onChange);
55
- let onChangeEnd = $28f99e3e86e6ec45$var$createOnChange(props.value, props.defaultValue, props.onChangeEnd);
56
- const [values, setValuesState] = (0, $BT4Uh$useControlledState)(value, defaultValue, onChange);
57
- let [initialValues] = (0, $BT4Uh$useState)(values);
58
- const [isDraggings, setDraggingsState] = (0, $BT4Uh$useState)(new Array(values.length).fill(false));
59
- const isEditablesRef = (0, $BT4Uh$useRef)(new Array(values.length).fill(true));
60
- const [focusedIndex, setFocusedIndex] = (0, $BT4Uh$useState)(undefined);
61
- const valuesRef = (0, $BT4Uh$useRef)(values);
62
- const isDraggingsRef = (0, $BT4Uh$useRef)(isDraggings);
63
- let setValues = (values)=>{
64
- valuesRef.current = values;
65
- setValuesState(values);
66
- };
67
- let setDraggings = (draggings)=>{
68
- isDraggingsRef.current = draggings;
69
- setDraggingsState(draggings);
70
- };
71
- function getValuePercent(value) {
72
- return (value - minValue) / (maxValue - minValue);
73
- }
74
- function getThumbMinValue(index) {
75
- return index === 0 ? minValue : values[index - 1];
76
- }
77
- function getThumbMaxValue(index) {
78
- return index === values.length - 1 ? maxValue : values[index + 1];
79
- }
80
- function isThumbEditable(index) {
81
- return isEditablesRef.current[index];
82
- }
83
- function setThumbEditable(index, editable) {
84
- isEditablesRef.current[index] = editable;
85
- }
86
- function updateValue(index, value) {
87
- if (isDisabled || !isThumbEditable(index)) return;
88
- const thisMin = getThumbMinValue(index);
89
- const thisMax = getThumbMaxValue(index);
90
- // Round value to multiple of step, clamp value between min and max
91
- value = (0, $BT4Uh$snapValueToStep)(value, thisMin, thisMax, step);
92
- let newValues = $28f99e3e86e6ec45$var$replaceIndex(valuesRef.current, index, value);
93
- setValues(newValues);
94
- }
95
- function updateDragging(index, dragging) {
96
- if (isDisabled || !isThumbEditable(index)) return;
97
- if (dragging) valuesRef.current = values;
98
- const wasDragging = isDraggingsRef.current[index];
99
- isDraggingsRef.current = $28f99e3e86e6ec45$var$replaceIndex(isDraggingsRef.current, index, dragging);
100
- setDraggings(isDraggingsRef.current);
101
- // Call onChangeEnd if no handles are dragging.
102
- if (onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) onChangeEnd(valuesRef.current);
103
- }
104
- function getFormattedValue(value) {
105
- return formatter.format(value);
106
- }
107
- function setThumbPercent(index, percent) {
108
- updateValue(index, getPercentValue(percent));
109
- }
110
- function getRoundedValue(value) {
111
- return Math.round((value - minValue) / step) * step + minValue;
112
- }
113
- function getPercentValue(percent) {
114
- const val = percent * (maxValue - minValue) + minValue;
115
- return (0, $BT4Uh$clamp)(getRoundedValue(val), minValue, maxValue);
116
- }
117
- function incrementThumb(index, stepSize = 1) {
118
- let s = Math.max(stepSize, step);
119
- updateValue(index, (0, $BT4Uh$snapValueToStep)(values[index] + s, minValue, maxValue, step));
120
- }
121
- function decrementThumb(index, stepSize = 1) {
122
- let s = Math.max(stepSize, step);
123
- updateValue(index, (0, $BT4Uh$snapValueToStep)(values[index] - s, minValue, maxValue, step));
124
- }
125
- return {
126
- values: values,
127
- defaultValues: props.defaultValue !== undefined ? defaultValue : initialValues,
128
- getThumbValue: (index)=>values[index],
129
- setThumbValue: updateValue,
130
- setThumbPercent: setThumbPercent,
131
- isThumbDragging: (index)=>isDraggings[index],
132
- setThumbDragging: updateDragging,
133
- focusedThumb: focusedIndex,
134
- setFocusedThumb: setFocusedIndex,
135
- getThumbPercent: (index)=>getValuePercent(values[index]),
136
- getValuePercent: getValuePercent,
137
- getThumbValueLabel: (index)=>getFormattedValue(values[index]),
138
- getFormattedValue: getFormattedValue,
139
- getThumbMinValue: getThumbMinValue,
140
- getThumbMaxValue: getThumbMaxValue,
141
- getPercentValue: getPercentValue,
142
- isThumbEditable: isThumbEditable,
143
- setThumbEditable: setThumbEditable,
144
- incrementThumb: incrementThumb,
145
- decrementThumb: decrementThumb,
146
- step: step,
147
- pageSize: pageSize,
148
- orientation: orientation,
149
- isDisabled: isDisabled
150
- };
151
- }
152
- function $28f99e3e86e6ec45$var$replaceIndex(array, index, value) {
153
- if (array[index] === value) return array;
154
- return [
155
- ...array.slice(0, index),
156
- value,
157
- ...array.slice(index + 1)
158
- ];
159
- }
160
- function $28f99e3e86e6ec45$var$convertValue(value) {
161
- if (value == null) return undefined;
162
- return Array.isArray(value) ? value : [
163
- value
164
- ];
165
- }
166
- function $28f99e3e86e6ec45$var$createOnChange(value, defaultValue, onChange) {
167
- return (newValue)=>{
168
- if (typeof value === 'number' || typeof defaultValue === 'number') onChange === null || onChange === void 0 ? void 0 : onChange(newValue[0]);
169
- else onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
170
- };
171
- }
172
-
173
-
174
- export {$28f99e3e86e6ec45$export$e5fda3247f5d67f9 as useSliderState};
175
- //# sourceMappingURL=useSliderState.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA6ID,M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AC,MAAM;QAC/C,eAAe;yBACf;QACA,iBAAiB,CAAC,QAAkB,WAAW,CAAC,MAAM;QACtD,kBAAkB;QAClB,cAAc;QACd,iBAAiB;QACjB,iBAAiB,CAAC,QAAkB,gBAAgB,MAAM,CAAC,MAAM;yBACjE;QACA,oBAAoB,CAAC,QAAkB,kBAAkB,MAAM,CAAC,MAAM;2BACtE;0BACA;0BACA;yBACA;yBACA;0BACA;wBACA;wBACA;cACA;kBACA;qBACA;oBACA;IACF;AACF;AAEA,SAAS,mCAAgB,KAAU,EAAE,KAAa,EAAE,KAAQ;IAC1D,IAAI,KAAK,CAAC,MAAM,KAAK,OACnB,OAAO;IAGT,OAAO;WAAI,MAAM,KAAK,CAAC,GAAG;QAAQ;WAAU,MAAM,KAAK,CAAC,QAAQ;KAAG;AACrE;AAEA,SAAS,mCAAa,KAAyB;IAC7C,IAAI,SAAS,MACX,OAAO;IAGT,OAAO,MAAM,OAAO,CAAC,SAAS,QAAQ;QAAC;KAAM;AAC/C;AAEA,SAAS,qCAAe,KAAK,EAAE,YAAY,EAAE,QAAQ;IACnD,OAAO,CAAC;QACN,IAAI,OAAO,UAAU,YAAY,OAAO,iBAAiB,UACvD,qBAAA,+BAAA,SAAW,QAAQ,CAAC,EAAE;aAEtB,qBAAA,+BAAA,SAAW;IAEf;AACF","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, snapValueToStep, useControlledState} from '@react-stately/utils';\nimport {Orientation} from '@react-types/shared';\nimport {SliderProps} from '@react-types/slider';\nimport {useCallback, useMemo, 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 * The default values for each thumb.\n */\n readonly defaultValues: 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 /** The orientation of the slider. */\n readonly orientation: Orientation,\n\n /** Whether the slider is disabled. */\n readonly isDisabled: boolean\n}\n\nconst DEFAULT_MIN_VALUE = 0;\nconst DEFAULT_MAX_VALUE = 100;\nconst DEFAULT_STEP_VALUE = 1;\n\nexport interface SliderStateOptions<T> extends SliderProps<T> {\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<T extends number | number[]>(props: SliderStateOptions<T>): SliderState {\n const {\n isDisabled = false,\n minValue = DEFAULT_MIN_VALUE,\n maxValue = DEFAULT_MAX_VALUE,\n numberFormatter: formatter,\n step = DEFAULT_STEP_VALUE,\n orientation = 'horizontal'\n } = props;\n\n // Page step should be at least equal to step and always a multiple of the step.\n let pageSize = useMemo(() => {\n let calcPageSize = (maxValue - minValue) / 10;\n calcPageSize = snapValueToStep(calcPageSize, 0, calcPageSize + step, step);\n return Math.max(calcPageSize, step);\n }, [step, maxValue, minValue]);\n\n let restrictValues = useCallback((values: number[] | undefined) => values?.map((val, idx) => {\n let min = idx === 0 ? minValue : values[idx - 1];\n let max = idx === values.length - 1 ? maxValue : values[idx + 1];\n return snapValueToStep(val, min, max, step);\n }), [minValue, maxValue, step]);\n\n let value = useMemo(() => restrictValues(convertValue(props.value)), [props.value, restrictValues]);\n let defaultValue = useMemo(() => restrictValues(convertValue(props.defaultValue) ?? [minValue])!, [props.defaultValue, minValue, restrictValues]);\n let onChange = createOnChange(props.value, props.defaultValue, props.onChange);\n let onChangeEnd = createOnChange(props.value, props.defaultValue, props.onChangeEnd);\n\n const [values, setValuesState] = useControlledState<number[]>(\n value,\n defaultValue,\n onChange\n );\n let [initialValues] = useState(values);\n const [isDraggings, setDraggingsState] = 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[]>(values);\n const isDraggingsRef = useRef<boolean[]>(isDraggings);\n\n let setValues = (values: number[]) => {\n valuesRef.current = values;\n setValuesState(values);\n };\n\n let setDraggings = (draggings: boolean[]) => {\n isDraggingsRef.current = draggings;\n setDraggingsState(draggings);\n };\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 let newValues = replaceIndex(valuesRef.current, index, value);\n setValues(newValues);\n }\n\n function updateDragging(index: number, dragging: boolean) {\n if (isDisabled || !isThumbEditable(index)) {\n return;\n }\n if (dragging) {\n valuesRef.current = values;\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 (onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {\n 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 defaultValues: props.defaultValue !== undefined ? defaultValue : initialValues,\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 orientation,\n isDisabled\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\nfunction convertValue(value?: number | number[]) {\n if (value == null) {\n return undefined;\n }\n\n return Array.isArray(value) ? value : [value];\n}\n\nfunction createOnChange(value, defaultValue, onChange) {\n return (newValue: number[]) => {\n if (typeof value === 'number' || typeof defaultValue === 'number') {\n onChange?.(newValue[0]);\n } else {\n onChange?.(newValue);\n }\n };\n}\n"],"names":[],"version":3,"file":"useSliderState.module.js.map"}
@@ -1,346 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {clamp, snapValueToStep, useControlledState} from '@react-stately/utils';
14
- import {Orientation} from '@react-types/shared';
15
- import {SliderProps} from '@react-types/slider';
16
- import {useCallback, useMemo, useRef, useState} from 'react';
17
-
18
- export interface SliderState {
19
- /**
20
- * Values managed by the slider by thumb index.
21
- */
22
- readonly values: number[],
23
- /**
24
- * The default values for each thumb.
25
- */
26
- readonly defaultValues: number[],
27
- /**
28
- * Get the value for the specified thumb.
29
- * @param index
30
- */
31
- getThumbValue(index: number): number,
32
-
33
- /**
34
- * Sets the value for the specified thumb.
35
- * The actual value set will be clamped and rounded according to min/max/step.
36
- * @param index
37
- * @param value
38
- */
39
- setThumbValue(index: number, value: number): void,
40
-
41
- /**
42
- * Sets value for the specified thumb by percent offset (between 0 and 1).
43
- * @param index
44
- * @param percent
45
- */
46
- setThumbPercent(index: number, percent: number): void,
47
-
48
- /**
49
- * Whether the specific thumb is being dragged.
50
- * @param index
51
- */
52
- isThumbDragging(index: number): boolean,
53
- /**
54
- * Set is dragging on the specified thumb.
55
- * @param index
56
- * @param dragging
57
- */
58
- setThumbDragging(index: number, dragging: boolean): void,
59
-
60
- /**
61
- * Currently-focused thumb index.
62
- */
63
- readonly focusedThumb: number | undefined,
64
- /**
65
- * Set focused true on specified thumb. This will remove focus from
66
- * any thumb that had it before.
67
- * @param index
68
- */
69
- setFocusedThumb(index: number | undefined): void,
70
-
71
- /**
72
- * Returns the specified thumb's value as a percentage from 0 to 1.
73
- * @param index
74
- */
75
- getThumbPercent(index: number): number,
76
-
77
- /**
78
- * Returns the value as a percent between the min and max of the slider.
79
- * @param index
80
- */
81
- getValuePercent(value: number): number,
82
-
83
- /**
84
- * Returns the string label for the specified thumb's value, per props.formatOptions.
85
- * @param index
86
- */
87
- getThumbValueLabel(index: number): string,
88
-
89
- /**
90
- * Returns the string label for the value, per props.formatOptions.
91
- * @param index
92
- */
93
- getFormattedValue(value: number): string,
94
-
95
- /**
96
- * Returns the min allowed value for the specified thumb.
97
- * @param index
98
- */
99
- getThumbMinValue(index: number): number,
100
-
101
- /**
102
- * Returns the max allowed value for the specified thumb.
103
- * @param index
104
- */
105
- getThumbMaxValue(index: number): number,
106
-
107
- /**
108
- * Converts a percent along track (between 0 and 1) to the corresponding value.
109
- * @param percent
110
- */
111
- getPercentValue(percent: number): number,
112
-
113
- /**
114
- * Returns if the specified thumb is editable.
115
- * @param index
116
- */
117
- isThumbEditable(index: number): boolean,
118
-
119
- /**
120
- * Set the specified thumb's editable state.
121
- * @param index
122
- * @param editable
123
- */
124
- setThumbEditable(index: number, editable: boolean): void,
125
-
126
- /**
127
- * Increments the value of the thumb by the step or page amount.
128
- */
129
- incrementThumb(index: number, stepSize?: number): void,
130
- /**
131
- * Decrements the value of the thumb by the step or page amount.
132
- */
133
- decrementThumb(index: number, stepSize?: number): void,
134
-
135
- /**
136
- * The step amount for the slider.
137
- */
138
- readonly step: number,
139
-
140
- /**
141
- * The page size for the slider, used to do a bigger step.
142
- */
143
- readonly pageSize: number,
144
-
145
- /** The orientation of the slider. */
146
- readonly orientation: Orientation,
147
-
148
- /** Whether the slider is disabled. */
149
- readonly isDisabled: boolean
150
- }
151
-
152
- const DEFAULT_MIN_VALUE = 0;
153
- const DEFAULT_MAX_VALUE = 100;
154
- const DEFAULT_STEP_VALUE = 1;
155
-
156
- export interface SliderStateOptions<T> extends SliderProps<T> {
157
- numberFormatter: Intl.NumberFormat
158
- }
159
-
160
- /**
161
- * Provides state management for a slider component. Stores values for all thumbs,
162
- * formats values for localization, and provides methods to update the position
163
- * of any thumbs.
164
- * @param props
165
- */
166
- export function useSliderState<T extends number | number[]>(props: SliderStateOptions<T>): SliderState {
167
- const {
168
- isDisabled = false,
169
- minValue = DEFAULT_MIN_VALUE,
170
- maxValue = DEFAULT_MAX_VALUE,
171
- numberFormatter: formatter,
172
- step = DEFAULT_STEP_VALUE,
173
- orientation = 'horizontal'
174
- } = props;
175
-
176
- // Page step should be at least equal to step and always a multiple of the step.
177
- let pageSize = useMemo(() => {
178
- let calcPageSize = (maxValue - minValue) / 10;
179
- calcPageSize = snapValueToStep(calcPageSize, 0, calcPageSize + step, step);
180
- return Math.max(calcPageSize, step);
181
- }, [step, maxValue, minValue]);
182
-
183
- let restrictValues = useCallback((values: number[] | undefined) => values?.map((val, idx) => {
184
- let min = idx === 0 ? minValue : values[idx - 1];
185
- let max = idx === values.length - 1 ? maxValue : values[idx + 1];
186
- return snapValueToStep(val, min, max, step);
187
- }), [minValue, maxValue, step]);
188
-
189
- let value = useMemo(() => restrictValues(convertValue(props.value)), [props.value, restrictValues]);
190
- let defaultValue = useMemo(() => restrictValues(convertValue(props.defaultValue) ?? [minValue])!, [props.defaultValue, minValue, restrictValues]);
191
- let onChange = createOnChange(props.value, props.defaultValue, props.onChange);
192
- let onChangeEnd = createOnChange(props.value, props.defaultValue, props.onChangeEnd);
193
-
194
- const [values, setValuesState] = useControlledState<number[]>(
195
- value,
196
- defaultValue,
197
- onChange
198
- );
199
- let [initialValues] = useState(values);
200
- const [isDraggings, setDraggingsState] = useState<boolean[]>(new Array(values.length).fill(false));
201
- const isEditablesRef = useRef<boolean[]>(new Array(values.length).fill(true));
202
- const [focusedIndex, setFocusedIndex] = useState<number | undefined>(undefined);
203
-
204
- const valuesRef = useRef<number[]>(values);
205
- const isDraggingsRef = useRef<boolean[]>(isDraggings);
206
-
207
- let setValues = (values: number[]) => {
208
- valuesRef.current = values;
209
- setValuesState(values);
210
- };
211
-
212
- let setDraggings = (draggings: boolean[]) => {
213
- isDraggingsRef.current = draggings;
214
- setDraggingsState(draggings);
215
- };
216
-
217
- function getValuePercent(value: number) {
218
- return (value - minValue) / (maxValue - minValue);
219
- }
220
-
221
- function getThumbMinValue(index: number) {
222
- return index === 0 ? minValue : values[index - 1];
223
- }
224
- function getThumbMaxValue(index: number) {
225
- return index === values.length - 1 ? maxValue : values[index + 1];
226
- }
227
-
228
- function isThumbEditable(index: number) {
229
- return isEditablesRef.current[index];
230
- }
231
-
232
- function setThumbEditable(index: number, editable: boolean) {
233
- isEditablesRef.current[index] = editable;
234
- }
235
-
236
- function updateValue(index: number, value: number) {
237
- if (isDisabled || !isThumbEditable(index)) {
238
- return;
239
- }
240
- const thisMin = getThumbMinValue(index);
241
- const thisMax = getThumbMaxValue(index);
242
-
243
- // Round value to multiple of step, clamp value between min and max
244
- value = snapValueToStep(value, thisMin, thisMax, step);
245
- let newValues = replaceIndex(valuesRef.current, index, value);
246
- setValues(newValues);
247
- }
248
-
249
- function updateDragging(index: number, dragging: boolean) {
250
- if (isDisabled || !isThumbEditable(index)) {
251
- return;
252
- }
253
- if (dragging) {
254
- valuesRef.current = values;
255
- }
256
-
257
- const wasDragging = isDraggingsRef.current[index];
258
- isDraggingsRef.current = replaceIndex(isDraggingsRef.current, index, dragging);
259
- setDraggings(isDraggingsRef.current);
260
-
261
- // Call onChangeEnd if no handles are dragging.
262
- if (onChangeEnd && wasDragging && !isDraggingsRef.current.some(Boolean)) {
263
- onChangeEnd(valuesRef.current);
264
- }
265
- }
266
-
267
- function getFormattedValue(value: number) {
268
- return formatter.format(value);
269
- }
270
-
271
- function setThumbPercent(index: number, percent: number) {
272
- updateValue(index, getPercentValue(percent));
273
- }
274
-
275
- function getRoundedValue(value: number) {
276
- return Math.round((value - minValue) / step) * step + minValue;
277
- }
278
-
279
- function getPercentValue(percent: number) {
280
- const val = percent * (maxValue - minValue) + minValue;
281
- return clamp(getRoundedValue(val), minValue, maxValue);
282
- }
283
-
284
- function incrementThumb(index: number, stepSize: number = 1) {
285
- let s = Math.max(stepSize, step);
286
- updateValue(index, snapValueToStep(values[index] + s, minValue, maxValue, step));
287
- }
288
-
289
- function decrementThumb(index: number, stepSize: number = 1) {
290
- let s = Math.max(stepSize, step);
291
- updateValue(index, snapValueToStep(values[index] - s, minValue, maxValue, step));
292
- }
293
-
294
- return {
295
- values: values,
296
- defaultValues: props.defaultValue !== undefined ? defaultValue : initialValues,
297
- getThumbValue: (index: number) => values[index],
298
- setThumbValue: updateValue,
299
- setThumbPercent,
300
- isThumbDragging: (index: number) => isDraggings[index],
301
- setThumbDragging: updateDragging,
302
- focusedThumb: focusedIndex,
303
- setFocusedThumb: setFocusedIndex,
304
- getThumbPercent: (index: number) => getValuePercent(values[index]),
305
- getValuePercent,
306
- getThumbValueLabel: (index: number) => getFormattedValue(values[index]),
307
- getFormattedValue,
308
- getThumbMinValue,
309
- getThumbMaxValue,
310
- getPercentValue,
311
- isThumbEditable,
312
- setThumbEditable,
313
- incrementThumb,
314
- decrementThumb,
315
- step,
316
- pageSize,
317
- orientation,
318
- isDisabled
319
- };
320
- }
321
-
322
- function replaceIndex<T>(array: T[], index: number, value: T) {
323
- if (array[index] === value) {
324
- return array;
325
- }
326
-
327
- return [...array.slice(0, index), value, ...array.slice(index + 1)];
328
- }
329
-
330
- function convertValue(value?: number | number[]) {
331
- if (value == null) {
332
- return undefined;
333
- }
334
-
335
- return Array.isArray(value) ? value : [value];
336
- }
337
-
338
- function createOnChange(value, defaultValue, onChange) {
339
- return (newValue: number[]) => {
340
- if (typeof value === 'number' || typeof defaultValue === 'number') {
341
- onChange?.(newValue[0]);
342
- } else {
343
- onChange?.(newValue);
344
- }
345
- };
346
- }