@react-aria/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,19 @@
1
+ import {useSlider as $bcca50147b47f54d$export$56b2c08e277f365} from "./useSlider.mjs";
2
+ import {useSliderThumb as $47b897dc8cdb026b$export$8d15029008292ae} from "./useSliderThumb.mjs";
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
+
17
+
18
+ export {$bcca50147b47f54d$export$56b2c08e277f365 as useSlider, $47b897dc8cdb026b$export$8d15029008292ae as useSliderThumb};
19
+ //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,228 +1,25 @@
1
- var {
2
- useFocusable
3
- } = require("@react-aria/focus");
1
+ var $481f97d830e3ede6$exports = require("./useSlider.main.js");
2
+ var $5eb806b626475377$exports = require("./useSliderThumb.main.js");
4
3
 
5
- var {
6
- useLabel
7
- } = require("@react-aria/label");
8
4
 
9
- var {
10
- mergeProps,
11
- useDrag1D,
12
- focusWithoutScrolling
13
- } = require("@react-aria/utils");
14
-
15
- var {
16
- useRef,
17
- useCallback,
18
- useEffect
19
- } = require("react");
20
-
21
- var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));
22
-
23
- function $parcel$interopDefault(a) {
24
- return a && a.__esModule ? a.default : a;
25
- }
26
-
27
- const $dec1906781d9c7cb69245fc4d5344b$export$sliderIds = new WeakMap();
28
-
29
- /**
30
- * Provides behavior and accessibility for a slider component.
31
- *
32
- * @param props Props for the slider.
33
- * @param state State for the slider, as returned by `useSliderState`.
34
- * @param trackRef Ref for the "track" element. The width of this element provides the "length"
35
- * of the track -- the span of one dimensional space that the slider thumb can be. It also
36
- * accepts click and drag motions, so that the closest thumb will follow clicks and drags on
37
- * the track.
38
- */
39
- function useSlider(props, state, trackRef) {
40
- var _labelProps$id;
41
-
42
- const {
43
- labelProps,
44
- fieldProps
45
- } = useLabel(props);
46
- const isSliderEditable = !(props.isDisabled || props.isReadOnly); // Attach id of the label to the state so it can be accessed by useSliderThumb.
47
-
48
- $dec1906781d9c7cb69245fc4d5344b$export$sliderIds.set(state, (_labelProps$id = labelProps.id) != null ? _labelProps$id : fieldProps.id); // When the user clicks or drags the track, we want the motion to set and drag the
49
- // closest thumb. Hence we also need to install useDrag1D() on the track element.
50
- // Here, we keep track of which index is the "closest" to the drag start point.
51
- // It is set onMouseDown; see trackProps below.
52
-
53
- const realTimeTrackDraggingIndex = useRef(undefined);
54
- const isTrackDragging = useRef(false);
55
- const {
56
- onMouseDown,
57
- onMouseEnter,
58
- onMouseOut
59
- } = useDrag1D({
60
- containerRef: trackRef,
61
- reverse: false,
62
- orientation: 'horizontal',
63
- onDrag: dragging => {
64
- if (realTimeTrackDraggingIndex.current !== undefined) {
65
- state.setThumbDragging(realTimeTrackDraggingIndex.current, dragging);
66
- }
67
-
68
- isTrackDragging.current = dragging;
69
- },
70
- onPositionChange: position => {
71
- if (realTimeTrackDraggingIndex.current !== undefined && trackRef.current) {
72
- const percent = position / trackRef.current.offsetWidth;
73
- state.setThumbPercent(realTimeTrackDraggingIndex.current, percent); // When track-dragging ends, onDrag is called before a final onPositionChange is
74
- // called, so we can't reset realTimeTrackDraggingIndex until onPositionChange,
75
- // as we still needed to update the thumb position one last time. Hence we
76
- // track whether we're dragging, and the actual dragged index, separately.
77
-
78
- if (!isTrackDragging.current) {
79
- realTimeTrackDraggingIndex.current = undefined;
80
- }
81
- }
82
- }
83
- });
84
- return {
85
- labelProps,
86
- // The root element of the Slider will have role="group" to group together
87
- // all the thumb inputs in the Slider. The label of the Slider will
88
- // be used to label the group.
89
- containerProps: _babelRuntimeHelpersExtends({
90
- role: 'group'
91
- }, fieldProps),
92
- trackProps: mergeProps({
93
- onMouseDown: e => {
94
- // We only trigger track-dragging if the user clicks on the track itself.
95
- if (trackRef.current && isSliderEditable) {
96
- // Find the closest thumb
97
- const trackPosition = trackRef.current.getBoundingClientRect().left;
98
- const clickPosition = e.clientX;
99
- const offset = clickPosition - trackPosition;
100
- const percent = offset / trackRef.current.offsetWidth;
101
- const value = state.getPercentValue(percent); // Only compute the diff for thumbs that are editable, as only they can be dragged
102
-
103
- const minDiff = Math.min(...state.values.map((v, index) => state.isThumbEditable(index) ? Math.abs(v - value) : Number.POSITIVE_INFINITY));
104
- const index = state.values.findIndex(v => Math.abs(v - value) === minDiff);
105
-
106
- if (minDiff !== Number.POSITIVE_INFINITY && index >= 0) {
107
- // Don't unfocus anything
108
- e.preventDefault();
109
- realTimeTrackDraggingIndex.current = index;
110
- state.setFocusedThumb(index); // We immediately toggle state to dragging and set the value on mouse down.
111
- // We set the value now, instead of waiting for onDrag, so that the thumb
112
- // is updated while you're still holding the mouse button down. And we
113
- // set dragging on now, so that onChangeEnd() won't fire yet when we set
114
- // the value. Dragging state will be reset to false in onDrag above, even
115
- // if no dragging actually occurs.
116
-
117
- state.setThumbDragging(realTimeTrackDraggingIndex.current, true);
118
- state.setThumbValue(index, value);
119
- } else {
120
- realTimeTrackDraggingIndex.current = undefined;
121
- }
122
- }
123
- }
124
- }, {
125
- onMouseDown,
126
- onMouseEnter,
127
- onMouseOut
128
- })
129
- };
5
+ function $parcel$export(e, n, v, s) {
6
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
130
7
  }
131
8
 
132
- exports.useSlider = useSlider;
133
-
134
- /**
135
- * Provides behavior and accessibility for a thumb of a slider component.
9
+ $parcel$export(module.exports, "useSlider", () => $481f97d830e3ede6$exports.useSlider);
10
+ $parcel$export(module.exports, "useSliderThumb", () => $5eb806b626475377$exports.useSliderThumb);
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
136
16
  *
137
- * @param opts Options for this Slider thumb.
138
- * @param state Slider state, created via `useSliderState`.
139
- */
140
- function useSliderThumb(opts, state) {
141
- var _opts$ariaLabelledby;
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
142
22
 
143
- const {
144
- index,
145
- isRequired,
146
- isDisabled,
147
- isReadOnly,
148
- validationState,
149
- trackRef,
150
- inputRef
151
- } = opts;
152
- let labelId = $dec1906781d9c7cb69245fc4d5344b$export$sliderIds.get(state);
153
- const {
154
- labelProps,
155
- fieldProps
156
- } = useLabel(_babelRuntimeHelpersExtends({}, opts, {
157
- 'aria-labelledby': (labelId + " " + ((_opts$ariaLabelledby = opts['aria-labelledby']) != null ? _opts$ariaLabelledby : '')).trim()
158
- }));
159
- const value = state.values[index];
160
- const isEditable = !(isDisabled || isReadOnly);
161
- const focusInput = useCallback(() => {
162
- if (inputRef.current) {
163
- focusWithoutScrolling(inputRef.current);
164
- }
165
- }, [inputRef]);
166
- const isFocused = state.focusedThumb === index;
167
- useEffect(() => {
168
- if (isFocused) {
169
- focusInput();
170
- }
171
- }, [isFocused, focusInput]);
172
- const draggableProps = useDrag1D({
173
- containerRef: trackRef,
174
- reverse: false,
175
- orientation: 'horizontal',
176
- onDrag: dragging => {
177
- state.setThumbDragging(index, dragging);
178
- focusInput();
179
- },
180
- onPositionChange: position => {
181
- const percent = position / trackRef.current.offsetWidth;
182
- state.setThumbPercent(index, percent);
183
- }
184
- }); // Immediately register editability with the state
185
23
 
186
- state.setThumbEditable(index, isEditable);
187
- const {
188
- focusableProps
189
- } = useFocusable(mergeProps(opts, {
190
- onFocus: () => state.setFocusedThumb(index),
191
- onBlur: () => state.setFocusedThumb(undefined)
192
- }), inputRef); // We install mouse handlers for the drag motion on the thumb div, but
193
- // not the key handler for moving the thumb with the slider. Instead,
194
- // we focus the range input, and let the browser handle the keyboard
195
- // interactions; we then listen to input's onChange to update state.
196
-
197
- return {
198
- inputProps: mergeProps(focusableProps, fieldProps, {
199
- type: 'range',
200
- tabIndex: isEditable ? 0 : undefined,
201
- min: state.getThumbMinValue(index),
202
- max: state.getThumbMaxValue(index),
203
- step: state.step,
204
- value: value,
205
- readOnly: isReadOnly,
206
- disabled: isDisabled,
207
- 'aria-orientation': 'horizontal',
208
- 'aria-valuetext': state.getThumbValueLabel(index),
209
- 'aria-required': isRequired || undefined,
210
- 'aria-invalid': validationState === 'invalid' || undefined,
211
- 'aria-errormessage': opts['aria-errormessage'],
212
- onChange: e => {
213
- state.setThumbValue(index, parseFloat(e.target.value));
214
- }
215
- }),
216
- thumbProps: isEditable ? mergeProps({
217
- onMouseDown: draggableProps.onMouseDown,
218
- onMouseEnter: draggableProps.onMouseEnter,
219
- onMouseOut: draggableProps.onMouseOut
220
- }, {
221
- onMouseDown: focusInput
222
- }) : {},
223
- labelProps
224
- };
225
- }
226
24
 
227
- exports.useSliderThumb = useSliderThumb;
228
25
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;ACAM,MAAMG,gDAAS,GAAG,IAAIC,OAAJ,EAAlB;;AC4BP;;;;;;;;;;AAUO,SAASC,SAA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-hoisting/lib/helpers.js","./packages/@react-aria/slider/src/utils.ts","./packages/@react-aria/slider/src/useSlider.ts","./packages/@react-aria/slider/src/useSliderThumb.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\n : {};\n","import {SliderState} from '@react-stately/slider';\n\nexport const sliderIds = new WeakMap<SliderState, string>();\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {HTMLAttributes, useRef} from 'react';\nimport {mergeProps, useDrag1D} from '@react-aria/utils';\nimport {sliderIds} from './utils';\nimport {SliderProps} from '@react-types/slider';\nimport {SliderState} from '@react-stately/slider';\nimport {useLabel} from '@react-aria/label';\n\ninterface SliderAria {\n /** Props for the label element. */\n labelProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the root element of the slider component; groups slider inputs. */\n containerProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the track element. */\n trackProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides behavior and accessibility for a slider component.\n *\n * @param props Props for the slider.\n * @param state State for the slider, as returned by `useSliderState`.\n * @param trackRef Ref for the \"track\" element. The width of this element provides the \"length\"\n * of the track -- the span of one dimensional space that the slider thumb can be. It also\n * accepts click and drag motions, so that the closest thumb will follow clicks and drags on\n * the track.\n */\nexport function useSlider(\n props: SliderProps,\n state: SliderState,\n trackRef: React.RefObject<HTMLElement>\n): SliderAria {\n const {labelProps, fieldProps} = useLabel(props);\n\n const isSliderEditable = !(props.isDisabled || props.isReadOnly);\n\n // Attach id of the label to the state so it can be accessed by useSliderThumb.\n sliderIds.set(state, labelProps.id ?? fieldProps.id);\n\n // When the user clicks or drags the track, we want the motion to set and drag the\n // closest thumb. Hence we also need to install useDrag1D() on the track element.\n // Here, we keep track of which index is the \"closest\" to the drag start point.\n // It is set onMouseDown; see trackProps below.\n const realTimeTrackDraggingIndex = useRef<number | undefined>(undefined);\n const isTrackDragging = useRef(false);\n const {onMouseDown, onMouseEnter, onMouseOut} = useDrag1D({\n containerRef: trackRef as any,\n reverse: false,\n orientation: 'horizontal',\n onDrag: (dragging) => {\n if (realTimeTrackDraggingIndex.current !== undefined) {\n state.setThumbDragging(realTimeTrackDraggingIndex.current, dragging);\n }\n isTrackDragging.current = dragging;\n },\n onPositionChange: (position) => {\n if (realTimeTrackDraggingIndex.current !== undefined && trackRef.current) {\n const percent = position / trackRef.current.offsetWidth;\n state.setThumbPercent(realTimeTrackDraggingIndex.current, percent);\n\n // When track-dragging ends, onDrag is called before a final onPositionChange is\n // called, so we can't reset realTimeTrackDraggingIndex until onPositionChange,\n // as we still needed to update the thumb position one last time. Hence we\n // track whether we're dragging, and the actual dragged index, separately.\n if (!isTrackDragging.current) {\n realTimeTrackDraggingIndex.current = undefined;\n }\n }\n }\n });\n\n return {\n labelProps,\n\n // The root element of the Slider will have role=\"group\" to group together\n // all the thumb inputs in the Slider. The label of the Slider will\n // be used to label the group.\n containerProps: {\n role: 'group',\n ...fieldProps\n },\n trackProps: mergeProps({\n onMouseDown: (e: React.MouseEvent<HTMLElement>) => {\n // We only trigger track-dragging if the user clicks on the track itself.\n if (trackRef.current && isSliderEditable) {\n // Find the closest thumb\n const trackPosition = trackRef.current.getBoundingClientRect().left;\n const clickPosition = e.clientX;\n const offset = clickPosition - trackPosition;\n const percent = offset / trackRef.current.offsetWidth;\n const value = state.getPercentValue(percent);\n\n // Only compute the diff for thumbs that are editable, as only they can be dragged\n const minDiff = Math.min(...state.values.map((v, index) => state.isThumbEditable(index) ? Math.abs(v - value) : Number.POSITIVE_INFINITY));\n const index = state.values.findIndex(v => Math.abs(v - value) === minDiff);\n if (minDiff !== Number.POSITIVE_INFINITY && index >= 0) {\n // Don't unfocus anything\n e.preventDefault();\n\n realTimeTrackDraggingIndex.current = index;\n state.setFocusedThumb(index);\n\n // We immediately toggle state to dragging and set the value on mouse down.\n // We set the value now, instead of waiting for onDrag, so that the thumb\n // is updated while you're still holding the mouse button down. And we\n // set dragging on now, so that onChangeEnd() won't fire yet when we set\n // the value. Dragging state will be reset to false in onDrag above, even\n // if no dragging actually occurs.\n state.setThumbDragging(realTimeTrackDraggingIndex.current, true);\n state.setThumbValue(index, value);\n } else {\n realTimeTrackDraggingIndex.current = undefined;\n }\n }\n }\n }, {\n onMouseDown, onMouseEnter, onMouseOut\n })\n };\n}\n","import {ChangeEvent, HTMLAttributes, useCallback, useEffect} from 'react';\nimport {focusWithoutScrolling, mergeProps, useDrag1D} from '@react-aria/utils';\nimport {sliderIds} from './utils';\nimport {SliderState} from '@react-stately/slider';\nimport {SliderThumbProps} from '@react-types/slider';\nimport {useFocusable} from '@react-aria/focus';\nimport {useLabel} from '@react-aria/label';\n\ninterface SliderThumbAria {\n /** Props for the range input. */\n inputProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the root thumb element; handles the dragging motion. */\n thumbProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the label element for this thumb. */\n labelProps: HTMLAttributes<HTMLElement>\n}\n\ninterface SliderThumbOptions extends SliderThumbProps {\n trackRef: React.RefObject<HTMLElement>,\n inputRef: React.RefObject<HTMLInputElement>\n}\n\n/**\n * Provides behavior and accessibility for a thumb of a slider component.\n *\n * @param opts Options for this Slider thumb.\n * @param state Slider state, created via `useSliderState`.\n */\nexport function useSliderThumb(\n opts: SliderThumbOptions,\n state: SliderState,\n): SliderThumbAria {\n const {\n index,\n isRequired,\n isDisabled,\n isReadOnly,\n validationState,\n trackRef,\n inputRef\n } = opts;\n\n let labelId = sliderIds.get(state);\n const {labelProps, fieldProps} = useLabel({\n ...opts,\n 'aria-labelledby': `${labelId} ${opts['aria-labelledby'] ?? ''}`.trim()\n });\n\n const value = state.values[index];\n const isEditable = !(isDisabled || isReadOnly);\n\n const focusInput = useCallback(() => {\n if (inputRef.current) {\n focusWithoutScrolling(inputRef.current);\n }\n }, [inputRef]);\n\n const isFocused = state.focusedThumb === index;\n\n useEffect(() => {\n if (isFocused) {\n focusInput();\n }\n }, [isFocused, focusInput]);\n\n const draggableProps = useDrag1D({\n containerRef: trackRef as any,\n reverse: false,\n orientation: 'horizontal',\n onDrag: (dragging) => {\n state.setThumbDragging(index, dragging);\n focusInput();\n },\n onPositionChange: (position) => {\n const percent = position / trackRef.current.offsetWidth;\n state.setThumbPercent(index, percent);\n }\n });\n\n // Immediately register editability with the state\n state.setThumbEditable(index, isEditable);\n\n const {focusableProps} = useFocusable(\n mergeProps(opts, {\n onFocus: () => state.setFocusedThumb(index),\n onBlur: () => state.setFocusedThumb(undefined)\n }),\n inputRef\n );\n\n // We install mouse handlers for the drag motion on the thumb div, but\n // not the key handler for moving the thumb with the slider. Instead,\n // we focus the range input, and let the browser handle the keyboard\n // interactions; we then listen to input's onChange to update state.\n return {\n inputProps: mergeProps(focusableProps, fieldProps, {\n type: 'range',\n tabIndex: isEditable ? 0 : undefined,\n min: state.getThumbMinValue(index),\n max: state.getThumbMaxValue(index),\n step: state.step,\n value: value,\n readOnly: isReadOnly,\n disabled: isDisabled,\n 'aria-orientation': 'horizontal',\n 'aria-valuetext': state.getThumbValueLabel(index),\n 'aria-required': isRequired || undefined,\n 'aria-invalid': validationState === 'invalid' || undefined,\n 'aria-errormessage': opts['aria-errormessage'],\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n state.setThumbValue(index, parseFloat(e.target.value));\n }\n }),\n thumbProps: isEditable ? mergeProps({\n onMouseDown: draggableProps.onMouseDown,\n onMouseEnter: draggableProps.onMouseEnter,\n onMouseOut: draggableProps.onMouseOut\n }, {\n onMouseDown: focusInput\n }) : {},\n labelProps\n };\n}\n"],"names":["$parcel$interopDefault","a","__esModule","default","sliderIds","WeakMap","useSlider","props","state","trackRef","labelProps","fieldProps","useLabel","isSliderEditable","isDisabled","isReadOnly","set","id","realTimeTrackDraggingIndex","useRef","undefined","isTrackDragging","onMouseDown","onMouseEnter","onMouseOut","useDrag1D","containerRef","reverse","orientation","onDrag","dragging","current","setThumbDragging","onPositionChange","position","percent","offsetWidth","setThumbPercent","containerProps","role","trackProps","mergeProps","e","trackPosition","getBoundingClientRect","left","clickPosition","clientX","offset","value","getPercentValue","minDiff","Math","min","values","map","v","index","isThumbEditable","abs","Number","POSITIVE_INFINITY","findIndex","preventDefault","setFocusedThumb","setThumbValue","useSliderThumb","opts","isRequired","validationState","inputRef","labelId","get","trim","isEditable","focusInput","useCallback","focusWithoutScrolling","isFocused","focusedThumb","useEffect","draggableProps","setThumbEditable","focusableProps","useFocusable","onFocus","onBlur","inputProps","type","tabIndex","getThumbMinValue","max","getThumbMaxValue","step","readOnly","disabled","getThumbValueLabel","onChange","parseFloat","target","thumbProps"],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/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 */\nexport {useSlider} from './useSlider';\nexport {useSliderThumb} from './useSliderThumb';\nexport type {AriaSliderProps} from '@react-types/slider';\nexport type {SliderAria} from './useSlider';\nexport type {AriaSliderThumbOptions, SliderThumbAria} from './useSliderThumb';\nexport type {AriaSliderThumbProps} from '@react-types/slider';\nexport type {Orientation} from '@react-types/shared';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,203 +1,19 @@
1
- import { useFocusable } from "@react-aria/focus";
2
- import { useLabel } from "@react-aria/label";
3
- import { mergeProps, useDrag1D, focusWithoutScrolling } from "@react-aria/utils";
4
- import { useRef, useCallback, useEffect } from "react";
5
- import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
6
- const $d20491ae7743da17cfa841ff6d87$export$sliderIds = new WeakMap();
7
-
8
- /**
9
- * Provides behavior and accessibility for a slider component.
10
- *
11
- * @param props Props for the slider.
12
- * @param state State for the slider, as returned by `useSliderState`.
13
- * @param trackRef Ref for the "track" element. The width of this element provides the "length"
14
- * of the track -- the span of one dimensional space that the slider thumb can be. It also
15
- * accepts click and drag motions, so that the closest thumb will follow clicks and drags on
16
- * the track.
17
- */
18
- export function useSlider(props, state, trackRef) {
19
- var _labelProps$id;
20
-
21
- const {
22
- labelProps,
23
- fieldProps
24
- } = useLabel(props);
25
- const isSliderEditable = !(props.isDisabled || props.isReadOnly); // Attach id of the label to the state so it can be accessed by useSliderThumb.
26
-
27
- $d20491ae7743da17cfa841ff6d87$export$sliderIds.set(state, (_labelProps$id = labelProps.id) != null ? _labelProps$id : fieldProps.id); // When the user clicks or drags the track, we want the motion to set and drag the
28
- // closest thumb. Hence we also need to install useDrag1D() on the track element.
29
- // Here, we keep track of which index is the "closest" to the drag start point.
30
- // It is set onMouseDown; see trackProps below.
31
-
32
- const realTimeTrackDraggingIndex = useRef(undefined);
33
- const isTrackDragging = useRef(false);
34
- const {
35
- onMouseDown,
36
- onMouseEnter,
37
- onMouseOut
38
- } = useDrag1D({
39
- containerRef: trackRef,
40
- reverse: false,
41
- orientation: 'horizontal',
42
- onDrag: dragging => {
43
- if (realTimeTrackDraggingIndex.current !== undefined) {
44
- state.setThumbDragging(realTimeTrackDraggingIndex.current, dragging);
45
- }
46
-
47
- isTrackDragging.current = dragging;
48
- },
49
- onPositionChange: position => {
50
- if (realTimeTrackDraggingIndex.current !== undefined && trackRef.current) {
51
- const percent = position / trackRef.current.offsetWidth;
52
- state.setThumbPercent(realTimeTrackDraggingIndex.current, percent); // When track-dragging ends, onDrag is called before a final onPositionChange is
53
- // called, so we can't reset realTimeTrackDraggingIndex until onPositionChange,
54
- // as we still needed to update the thumb position one last time. Hence we
55
- // track whether we're dragging, and the actual dragged index, separately.
56
-
57
- if (!isTrackDragging.current) {
58
- realTimeTrackDraggingIndex.current = undefined;
59
- }
60
- }
61
- }
62
- });
63
- return {
64
- labelProps,
65
- // The root element of the Slider will have role="group" to group together
66
- // all the thumb inputs in the Slider. The label of the Slider will
67
- // be used to label the group.
68
- containerProps: _babelRuntimeHelpersEsmExtends({
69
- role: 'group'
70
- }, fieldProps),
71
- trackProps: mergeProps({
72
- onMouseDown: e => {
73
- // We only trigger track-dragging if the user clicks on the track itself.
74
- if (trackRef.current && isSliderEditable) {
75
- // Find the closest thumb
76
- const trackPosition = trackRef.current.getBoundingClientRect().left;
77
- const clickPosition = e.clientX;
78
- const offset = clickPosition - trackPosition;
79
- const percent = offset / trackRef.current.offsetWidth;
80
- const value = state.getPercentValue(percent); // Only compute the diff for thumbs that are editable, as only they can be dragged
81
-
82
- const minDiff = Math.min(...state.values.map((v, index) => state.isThumbEditable(index) ? Math.abs(v - value) : Number.POSITIVE_INFINITY));
83
- const index = state.values.findIndex(v => Math.abs(v - value) === minDiff);
84
-
85
- if (minDiff !== Number.POSITIVE_INFINITY && index >= 0) {
86
- // Don't unfocus anything
87
- e.preventDefault();
88
- realTimeTrackDraggingIndex.current = index;
89
- state.setFocusedThumb(index); // We immediately toggle state to dragging and set the value on mouse down.
90
- // We set the value now, instead of waiting for onDrag, so that the thumb
91
- // is updated while you're still holding the mouse button down. And we
92
- // set dragging on now, so that onChangeEnd() won't fire yet when we set
93
- // the value. Dragging state will be reset to false in onDrag above, even
94
- // if no dragging actually occurs.
95
-
96
- state.setThumbDragging(realTimeTrackDraggingIndex.current, true);
97
- state.setThumbValue(index, value);
98
- } else {
99
- realTimeTrackDraggingIndex.current = undefined;
100
- }
101
- }
102
- }
103
- }, {
104
- onMouseDown,
105
- onMouseEnter,
106
- onMouseOut
107
- })
108
- };
109
- }
110
-
111
- /**
112
- * Provides behavior and accessibility for a thumb of a slider component.
1
+ import {useSlider as $bcca50147b47f54d$export$56b2c08e277f365} from "./useSlider.module.js";
2
+ import {useSliderThumb as $47b897dc8cdb026b$export$8d15029008292ae} from "./useSliderThumb.module.js";
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
113
9
  *
114
- * @param opts Options for this Slider thumb.
115
- * @param state Slider state, created via `useSliderState`.
116
- */
117
- export function useSliderThumb(opts, state) {
118
- var _opts$ariaLabelledby;
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
+ */
119
15
 
120
- const {
121
- index,
122
- isRequired,
123
- isDisabled,
124
- isReadOnly,
125
- validationState,
126
- trackRef,
127
- inputRef
128
- } = opts;
129
- let labelId = $d20491ae7743da17cfa841ff6d87$export$sliderIds.get(state);
130
- const {
131
- labelProps,
132
- fieldProps
133
- } = useLabel(_babelRuntimeHelpersEsmExtends({}, opts, {
134
- 'aria-labelledby': (labelId + " " + ((_opts$ariaLabelledby = opts['aria-labelledby']) != null ? _opts$ariaLabelledby : '')).trim()
135
- }));
136
- const value = state.values[index];
137
- const isEditable = !(isDisabled || isReadOnly);
138
- const focusInput = useCallback(() => {
139
- if (inputRef.current) {
140
- focusWithoutScrolling(inputRef.current);
141
- }
142
- }, [inputRef]);
143
- const isFocused = state.focusedThumb === index;
144
- useEffect(() => {
145
- if (isFocused) {
146
- focusInput();
147
- }
148
- }, [isFocused, focusInput]);
149
- const draggableProps = useDrag1D({
150
- containerRef: trackRef,
151
- reverse: false,
152
- orientation: 'horizontal',
153
- onDrag: dragging => {
154
- state.setThumbDragging(index, dragging);
155
- focusInput();
156
- },
157
- onPositionChange: position => {
158
- const percent = position / trackRef.current.offsetWidth;
159
- state.setThumbPercent(index, percent);
160
- }
161
- }); // Immediately register editability with the state
162
16
 
163
- state.setThumbEditable(index, isEditable);
164
- const {
165
- focusableProps
166
- } = useFocusable(mergeProps(opts, {
167
- onFocus: () => state.setFocusedThumb(index),
168
- onBlur: () => state.setFocusedThumb(undefined)
169
- }), inputRef); // We install mouse handlers for the drag motion on the thumb div, but
170
- // not the key handler for moving the thumb with the slider. Instead,
171
- // we focus the range input, and let the browser handle the keyboard
172
- // interactions; we then listen to input's onChange to update state.
173
17
 
174
- return {
175
- inputProps: mergeProps(focusableProps, fieldProps, {
176
- type: 'range',
177
- tabIndex: isEditable ? 0 : undefined,
178
- min: state.getThumbMinValue(index),
179
- max: state.getThumbMaxValue(index),
180
- step: state.step,
181
- value: value,
182
- readOnly: isReadOnly,
183
- disabled: isDisabled,
184
- 'aria-orientation': 'horizontal',
185
- 'aria-valuetext': state.getThumbValueLabel(index),
186
- 'aria-required': isRequired || undefined,
187
- 'aria-invalid': validationState === 'invalid' || undefined,
188
- 'aria-errormessage': opts['aria-errormessage'],
189
- onChange: e => {
190
- state.setThumbValue(index, parseFloat(e.target.value));
191
- }
192
- }),
193
- thumbProps: isEditable ? mergeProps({
194
- onMouseDown: draggableProps.onMouseDown,
195
- onMouseEnter: draggableProps.onMouseEnter,
196
- onMouseOut: draggableProps.onMouseOut
197
- }, {
198
- onMouseDown: focusInput
199
- }) : {},
200
- labelProps
201
- };
202
- }
18
+ export {$bcca50147b47f54d$export$56b2c08e277f365 as useSlider, $47b897dc8cdb026b$export$8d15029008292ae as useSliderThumb};
203
19
  //# sourceMappingURL=module.js.map
@@ -1 +1 @@
1
- {"mappings":";;;;;AAEO,MAAMA,8CAAS,GAAG,IAAIC,OAAJ,EAAlB;;AC4BP;;;;;;;;;;OAUO,SAASC,SAAT,CACLC,KADK,EAELC,KAFK,EAGLC,QAHK,EAIO;AAAA;;AACZ,QAAM;AAACC,IAAAA,UAAD;AAAaC,IAAAA;AAAb,MAA2BC,QAAQ,CAACL,KAAD,CAAzC;AAEA,QAAMM,gBAAgB,GAAG,EAAEN,KAAK,CAACO,UAAN,IAAoBP,KAAK,CAACQ,UAA5B,CAAzB,CAHY,CAKZ;;AACA,iDAAUC,GAAV,CAAcR,KAAd,oBAAqBE,UAAU,CAACO,EAAhC,6BAAsCN,UAAU,CAACM,EAAjD,EANY,CAQZ;AACA;AACA;AACA;;AACA,QAAMC,0BAA0B,GAAGC,MAAM,CAAqBC,SAArB,CAAzC;AACA,QAAMC,eAAe,GAAGF,MAAM,CAAC,KAAD,CAA9B;AACA,QAAM;AAACG,IAAAA,WAAD;AAAcC,IAAAA,YAAd;AAA4BC,IAAAA;AAA5B,MAA0CC,SAAS,CAAC;AACxDC,IAAAA,YAAY,EAAEjB,QAD0C;AAExDkB,IAAAA,OAAO,EAAE,KAF+C;AAGxDC,IAAAA,WAAW,EAAE,YAH2C;AAIxDC,IAAAA,MAAM,EAAGC,QAAD,IAAc;AACpB,UAAIZ,0BAA0B,CAACa,OAA3B,KAA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IAAsC;AAC9ClC,QAAAA,KAAK,CAACyD,aAAN,CAAoBR,KAApB,EAA2ByC,UAAU,CAACxD,CAAC,CAACyD,MAAF,CAASlD,KAAV,CAArC;AACD;AAhBgD,KAA7B,CADjB;AAmBLmD,IAAAA,UAAU,EAAE1B,UAAU,GAAGjC,UAAU,CAAC;AAClCnB,MAAAA,WAAW,EAAE2D,cAAc,CAAC3D,WADM;AAElCC,MAAAA,YAAY,EAAE0D,cAAc,CAAC1D,YAFK;AAGlCC,MAAAA,UAAU,EAAEyD,cAAc,CAACzD;AAHO,KAAD,EAIhC;AACDF,MAAAA,WAAW,EAAEqD;AADZ,KAJgC,CAAb,GAMjB,EAzBA;AA0BLjE,IAAAA;AA1BK,GAAP;AA4BD","sources":["./packages/@react-aria/slider/src/utils.ts","./packages/@react-aria/slider/src/useSlider.ts","./packages/@react-aria/slider/src/useSliderThumb.ts"],"sourcesContent":["import {SliderState} from '@react-stately/slider';\n\nexport const sliderIds = new WeakMap<SliderState, string>();\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {HTMLAttributes, useRef} from 'react';\nimport {mergeProps, useDrag1D} from '@react-aria/utils';\nimport {sliderIds} from './utils';\nimport {SliderProps} from '@react-types/slider';\nimport {SliderState} from '@react-stately/slider';\nimport {useLabel} from '@react-aria/label';\n\ninterface SliderAria {\n /** Props for the label element. */\n labelProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the root element of the slider component; groups slider inputs. */\n containerProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the track element. */\n trackProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Provides behavior and accessibility for a slider component.\n *\n * @param props Props for the slider.\n * @param state State for the slider, as returned by `useSliderState`.\n * @param trackRef Ref for the \"track\" element. The width of this element provides the \"length\"\n * of the track -- the span of one dimensional space that the slider thumb can be. It also\n * accepts click and drag motions, so that the closest thumb will follow clicks and drags on\n * the track.\n */\nexport function useSlider(\n props: SliderProps,\n state: SliderState,\n trackRef: React.RefObject<HTMLElement>\n): SliderAria {\n const {labelProps, fieldProps} = useLabel(props);\n\n const isSliderEditable = !(props.isDisabled || props.isReadOnly);\n\n // Attach id of the label to the state so it can be accessed by useSliderThumb.\n sliderIds.set(state, labelProps.id ?? fieldProps.id);\n\n // When the user clicks or drags the track, we want the motion to set and drag the\n // closest thumb. Hence we also need to install useDrag1D() on the track element.\n // Here, we keep track of which index is the \"closest\" to the drag start point.\n // It is set onMouseDown; see trackProps below.\n const realTimeTrackDraggingIndex = useRef<number | undefined>(undefined);\n const isTrackDragging = useRef(false);\n const {onMouseDown, onMouseEnter, onMouseOut} = useDrag1D({\n containerRef: trackRef as any,\n reverse: false,\n orientation: 'horizontal',\n onDrag: (dragging) => {\n if (realTimeTrackDraggingIndex.current !== undefined) {\n state.setThumbDragging(realTimeTrackDraggingIndex.current, dragging);\n }\n isTrackDragging.current = dragging;\n },\n onPositionChange: (position) => {\n if (realTimeTrackDraggingIndex.current !== undefined && trackRef.current) {\n const percent = position / trackRef.current.offsetWidth;\n state.setThumbPercent(realTimeTrackDraggingIndex.current, percent);\n\n // When track-dragging ends, onDrag is called before a final onPositionChange is\n // called, so we can't reset realTimeTrackDraggingIndex until onPositionChange,\n // as we still needed to update the thumb position one last time. Hence we\n // track whether we're dragging, and the actual dragged index, separately.\n if (!isTrackDragging.current) {\n realTimeTrackDraggingIndex.current = undefined;\n }\n }\n }\n });\n\n return {\n labelProps,\n\n // The root element of the Slider will have role=\"group\" to group together\n // all the thumb inputs in the Slider. The label of the Slider will\n // be used to label the group.\n containerProps: {\n role: 'group',\n ...fieldProps\n },\n trackProps: mergeProps({\n onMouseDown: (e: React.MouseEvent<HTMLElement>) => {\n // We only trigger track-dragging if the user clicks on the track itself.\n if (trackRef.current && isSliderEditable) {\n // Find the closest thumb\n const trackPosition = trackRef.current.getBoundingClientRect().left;\n const clickPosition = e.clientX;\n const offset = clickPosition - trackPosition;\n const percent = offset / trackRef.current.offsetWidth;\n const value = state.getPercentValue(percent);\n\n // Only compute the diff for thumbs that are editable, as only they can be dragged\n const minDiff = Math.min(...state.values.map((v, index) => state.isThumbEditable(index) ? Math.abs(v - value) : Number.POSITIVE_INFINITY));\n const index = state.values.findIndex(v => Math.abs(v - value) === minDiff);\n if (minDiff !== Number.POSITIVE_INFINITY && index >= 0) {\n // Don't unfocus anything\n e.preventDefault();\n\n realTimeTrackDraggingIndex.current = index;\n state.setFocusedThumb(index);\n\n // We immediately toggle state to dragging and set the value on mouse down.\n // We set the value now, instead of waiting for onDrag, so that the thumb\n // is updated while you're still holding the mouse button down. And we\n // set dragging on now, so that onChangeEnd() won't fire yet when we set\n // the value. Dragging state will be reset to false in onDrag above, even\n // if no dragging actually occurs.\n state.setThumbDragging(realTimeTrackDraggingIndex.current, true);\n state.setThumbValue(index, value);\n } else {\n realTimeTrackDraggingIndex.current = undefined;\n }\n }\n }\n }, {\n onMouseDown, onMouseEnter, onMouseOut\n })\n };\n}\n","import {ChangeEvent, HTMLAttributes, useCallback, useEffect} from 'react';\nimport {focusWithoutScrolling, mergeProps, useDrag1D} from '@react-aria/utils';\nimport {sliderIds} from './utils';\nimport {SliderState} from '@react-stately/slider';\nimport {SliderThumbProps} from '@react-types/slider';\nimport {useFocusable} from '@react-aria/focus';\nimport {useLabel} from '@react-aria/label';\n\ninterface SliderThumbAria {\n /** Props for the range input. */\n inputProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the root thumb element; handles the dragging motion. */\n thumbProps: HTMLAttributes<HTMLElement>,\n\n /** Props for the label element for this thumb. */\n labelProps: HTMLAttributes<HTMLElement>\n}\n\ninterface SliderThumbOptions extends SliderThumbProps {\n trackRef: React.RefObject<HTMLElement>,\n inputRef: React.RefObject<HTMLInputElement>\n}\n\n/**\n * Provides behavior and accessibility for a thumb of a slider component.\n *\n * @param opts Options for this Slider thumb.\n * @param state Slider state, created via `useSliderState`.\n */\nexport function useSliderThumb(\n opts: SliderThumbOptions,\n state: SliderState,\n): SliderThumbAria {\n const {\n index,\n isRequired,\n isDisabled,\n isReadOnly,\n validationState,\n trackRef,\n inputRef\n } = opts;\n\n let labelId = sliderIds.get(state);\n const {labelProps, fieldProps} = useLabel({\n ...opts,\n 'aria-labelledby': `${labelId} ${opts['aria-labelledby'] ?? ''}`.trim()\n });\n\n const value = state.values[index];\n const isEditable = !(isDisabled || isReadOnly);\n\n const focusInput = useCallback(() => {\n if (inputRef.current) {\n focusWithoutScrolling(inputRef.current);\n }\n }, [inputRef]);\n\n const isFocused = state.focusedThumb === index;\n\n useEffect(() => {\n if (isFocused) {\n focusInput();\n }\n }, [isFocused, focusInput]);\n\n const draggableProps = useDrag1D({\n containerRef: trackRef as any,\n reverse: false,\n orientation: 'horizontal',\n onDrag: (dragging) => {\n state.setThumbDragging(index, dragging);\n focusInput();\n },\n onPositionChange: (position) => {\n const percent = position / trackRef.current.offsetWidth;\n state.setThumbPercent(index, percent);\n }\n });\n\n // Immediately register editability with the state\n state.setThumbEditable(index, isEditable);\n\n const {focusableProps} = useFocusable(\n mergeProps(opts, {\n onFocus: () => state.setFocusedThumb(index),\n onBlur: () => state.setFocusedThumb(undefined)\n }),\n inputRef\n );\n\n // We install mouse handlers for the drag motion on the thumb div, but\n // not the key handler for moving the thumb with the slider. Instead,\n // we focus the range input, and let the browser handle the keyboard\n // interactions; we then listen to input's onChange to update state.\n return {\n inputProps: mergeProps(focusableProps, fieldProps, {\n type: 'range',\n tabIndex: isEditable ? 0 : undefined,\n min: state.getThumbMinValue(index),\n max: state.getThumbMaxValue(index),\n step: state.step,\n value: value,\n readOnly: isReadOnly,\n disabled: isDisabled,\n 'aria-orientation': 'horizontal',\n 'aria-valuetext': state.getThumbValueLabel(index),\n 'aria-required': isRequired || undefined,\n 'aria-invalid': validationState === 'invalid' || undefined,\n 'aria-errormessage': opts['aria-errormessage'],\n onChange: (e: ChangeEvent<HTMLInputElement>) => {\n state.setThumbValue(index, parseFloat(e.target.value));\n }\n }),\n thumbProps: isEditable ? mergeProps({\n onMouseDown: draggableProps.onMouseDown,\n onMouseEnter: draggableProps.onMouseEnter,\n onMouseOut: draggableProps.onMouseOut\n }, {\n onMouseDown: focusInput\n }) : {},\n labelProps\n };\n}\n"],"names":["sliderIds","WeakMap","useSlider","props","state","trackRef","labelProps","fieldProps","useLabel","isSliderEditable","isDisabled","isReadOnly","set","id","realTimeTrackDraggingIndex","useRef","undefined","isTrackDragging","onMouseDown","onMouseEnter","onMouseOut","useDrag1D","containerRef","reverse","orientation","onDrag","dragging","current","setThumbDragging","onPositionChange","position","percent","offsetWidth","setThumbPercent","containerProps","role","trackProps","mergeProps","e","trackPosition","getBoundingClientRect","left","clickPosition","clientX","offset","value","getPercentValue","minDiff","Math","min","values","map","v","index","isThumbEditable","abs","Number","POSITIVE_INFINITY","findIndex","preventDefault","setFocusedThumb","setThumbValue","useSliderThumb","opts","isRequired","validationState","inputRef","labelId","get","trim","isEditable","focusInput","useCallback","focusWithoutScrolling","isFocused","focusedThumb","useEffect","draggableProps","setThumbEditable","focusableProps","useFocusable","onFocus","onBlur","inputProps","type","tabIndex","getThumbMinValue","max","getThumbMaxValue","step","readOnly","disabled","getThumbValueLabel","onChange","parseFloat","target","thumbProps"],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/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 */\nexport {useSlider} from './useSlider';\nexport {useSliderThumb} from './useSliderThumb';\nexport type {AriaSliderProps} from '@react-types/slider';\nexport type {SliderAria} from './useSlider';\nexport type {AriaSliderThumbOptions, SliderThumbAria} from './useSliderThumb';\nexport type {AriaSliderThumbProps} from '@react-types/slider';\nexport type {Orientation} from '@react-types/shared';\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,16 +1,19 @@
1
- import { HTMLAttributes } from "react";
2
- import { SliderProps, SliderThumbProps } from "@react-types/slider";
1
+ import { AriaSliderProps, AriaSliderThumbProps } from "@react-types/slider";
2
+ import { DOMAttributes, RefObject } from "@react-types/shared";
3
+ import { LabelHTMLAttributes, OutputHTMLAttributes, InputHTMLAttributes } from "react";
3
4
  import { SliderState } from "@react-stately/slider";
4
- interface SliderAria {
5
+ export interface SliderAria {
5
6
  /** Props for the label element. */
6
- labelProps: HTMLAttributes<HTMLElement>;
7
+ labelProps: LabelHTMLAttributes<HTMLLabelElement>;
7
8
  /** Props for the root element of the slider component; groups slider inputs. */
8
- containerProps: HTMLAttributes<HTMLElement>;
9
+ groupProps: DOMAttributes;
9
10
  /** Props for the track element. */
10
- trackProps: HTMLAttributes<HTMLElement>;
11
+ trackProps: DOMAttributes;
12
+ /** Props for the output element, displaying the value of the slider thumbs. */
13
+ outputProps: OutputHTMLAttributes<HTMLOutputElement>;
11
14
  }
12
15
  /**
13
- * Provides behavior and accessibility for a slider component.
16
+ * Provides the behavior and accessibility implementation for a slider component representing one or more values.
14
17
  *
15
18
  * @param props Props for the slider.
16
19
  * @param state State for the slider, as returned by `useSliderState`.
@@ -19,18 +22,26 @@ interface SliderAria {
19
22
  * accepts click and drag motions, so that the closest thumb will follow clicks and drags on
20
23
  * the track.
21
24
  */
22
- export function useSlider(props: SliderProps, state: SliderState, trackRef: React.RefObject<HTMLElement>): SliderAria;
23
- interface SliderThumbAria {
24
- /** Props for the range input. */
25
- inputProps: HTMLAttributes<HTMLElement>;
25
+ export function useSlider<T extends number | number[]>(props: AriaSliderProps<T>, state: SliderState, trackRef: RefObject<Element | null>): SliderAria;
26
+ export interface SliderThumbAria {
26
27
  /** Props for the root thumb element; handles the dragging motion. */
27
- thumbProps: HTMLAttributes<HTMLElement>;
28
- /** Props for the label element for this thumb. */
29
- labelProps: HTMLAttributes<HTMLElement>;
28
+ thumbProps: DOMAttributes;
29
+ /** Props for the visually hidden range input element. */
30
+ inputProps: InputHTMLAttributes<HTMLInputElement>;
31
+ /** Props for the label element for this thumb (optional). */
32
+ labelProps: LabelHTMLAttributes<HTMLLabelElement>;
33
+ /** Whether this thumb is currently being dragged. */
34
+ isDragging: boolean;
35
+ /** Whether the thumb is currently focused. */
36
+ isFocused: boolean;
37
+ /** Whether the thumb is disabled. */
38
+ isDisabled: boolean;
30
39
  }
31
- interface SliderThumbOptions extends SliderThumbProps {
32
- trackRef: React.RefObject<HTMLElement>;
33
- inputRef: React.RefObject<HTMLInputElement>;
40
+ export interface AriaSliderThumbOptions extends AriaSliderThumbProps {
41
+ /** A ref to the track element. */
42
+ trackRef: RefObject<Element | null>;
43
+ /** A ref to the thumb input element. */
44
+ inputRef: RefObject<HTMLInputElement | null>;
34
45
  }
35
46
  /**
36
47
  * Provides behavior and accessibility for a thumb of a slider component.
@@ -38,6 +49,9 @@ interface SliderThumbOptions extends SliderThumbProps {
38
49
  * @param opts Options for this Slider thumb.
39
50
  * @param state Slider state, created via `useSliderState`.
40
51
  */
41
- export function useSliderThumb(opts: SliderThumbOptions, state: SliderState): SliderThumbAria;
52
+ export function useSliderThumb(opts: AriaSliderThumbOptions, state: SliderState): SliderThumbAria;
53
+ export type { AriaSliderProps } from '@react-types/slider';
54
+ export type { AriaSliderThumbProps } from '@react-types/slider';
55
+ export type { Orientation } from '@react-types/shared';
42
56
 
43
57
  //# sourceMappingURL=types.d.ts.map