@mui/material 5.16.1 → 5.16.3

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.
Files changed (252) hide show
  1. package/Autocomplete/Autocomplete.d.ts +6 -7
  2. package/Autocomplete/Autocomplete.js +1 -1
  3. package/Badge/Badge.d.ts +1 -1
  4. package/Badge/Badge.js +2 -2
  5. package/Badge/useBadge.d.ts +13 -0
  6. package/Badge/useBadge.js +41 -0
  7. package/Badge/useBadge.types.d.ts +40 -0
  8. package/Badge/useBadge.types.js +1 -0
  9. package/Breadcrumbs/Breadcrumbs.d.ts +1 -1
  10. package/Breadcrumbs/Breadcrumbs.js +1 -1
  11. package/CHANGELOG.md +35 -0
  12. package/ClickAwayListener/ClickAwayListener.d.ts +47 -0
  13. package/ClickAwayListener/ClickAwayListener.js +178 -0
  14. package/ClickAwayListener/index.d.ts +2 -2
  15. package/ClickAwayListener/index.js +1 -1
  16. package/InputBase/InputBase.js +2 -2
  17. package/ListItem/ListItem.js +1 -1
  18. package/Menu/Menu.js +1 -1
  19. package/Modal/Modal.d.ts +1 -1
  20. package/Modal/Modal.js +2 -2
  21. package/Modal/ModalManager.d.ts +25 -0
  22. package/Modal/ModalManager.js +213 -0
  23. package/Modal/index.d.ts +1 -1
  24. package/Modal/index.js +1 -1
  25. package/Modal/useModal.d.ts +13 -0
  26. package/Modal/useModal.js +195 -0
  27. package/Modal/useModal.types.d.ts +115 -0
  28. package/Modal/useModal.types.js +1 -0
  29. package/NoSsr/NoSsr.d.ts +25 -0
  30. package/NoSsr/NoSsr.js +73 -0
  31. package/NoSsr/NoSsr.types.d.ts +18 -0
  32. package/NoSsr/NoSsr.types.js +1 -0
  33. package/NoSsr/index.d.ts +3 -2
  34. package/NoSsr/index.js +1 -1
  35. package/Popover/Popover.js +2 -1
  36. package/Popper/BasePopper.d.ts +7 -0
  37. package/Popper/BasePopper.js +372 -0
  38. package/Popper/BasePopper.types.d.ts +130 -0
  39. package/Popper/BasePopper.types.js +1 -0
  40. package/Popper/Popper.d.ts +1 -1
  41. package/Popper/Popper.js +1 -1
  42. package/Popper/index.d.ts +2 -1
  43. package/Popper/index.js +2 -1
  44. package/Popper/popperClasses.d.ts +8 -0
  45. package/Popper/popperClasses.js +7 -0
  46. package/Portal/Portal.d.ts +16 -0
  47. package/Portal/Portal.js +92 -0
  48. package/Portal/Portal.types.d.ts +23 -0
  49. package/Portal/Portal.types.js +1 -0
  50. package/Portal/index.d.ts +3 -2
  51. package/Portal/index.js +1 -1
  52. package/Slider/Slider.d.ts +2 -2
  53. package/Slider/Slider.js +3 -2
  54. package/Slider/useSlider.d.ts +14 -0
  55. package/Slider/useSlider.js +655 -0
  56. package/Slider/useSlider.types.d.ts +228 -0
  57. package/Slider/useSlider.types.js +1 -0
  58. package/Snackbar/Snackbar.d.ts +1 -1
  59. package/Snackbar/Snackbar.js +4 -5
  60. package/Snackbar/useSnackbar.d.ts +14 -0
  61. package/Snackbar/useSnackbar.js +131 -0
  62. package/Snackbar/useSnackbar.types.d.ts +60 -0
  63. package/Snackbar/useSnackbar.types.js +1 -0
  64. package/SwipeableDrawer/SwipeableDrawer.js +1 -1
  65. package/TabScrollButton/TabScrollButton.d.ts +1 -1
  66. package/TabScrollButton/TabScrollButton.js +1 -1
  67. package/TablePagination/TablePagination.js +1 -1
  68. package/Tabs/Tabs.d.ts +1 -1
  69. package/Tabs/Tabs.js +1 -1
  70. package/TextareaAutosize/TextareaAutosize.d.ts +14 -0
  71. package/TextareaAutosize/TextareaAutosize.js +223 -0
  72. package/TextareaAutosize/TextareaAutosize.types.d.ts +13 -0
  73. package/TextareaAutosize/TextareaAutosize.types.js +1 -0
  74. package/TextareaAutosize/index.d.ts +3 -2
  75. package/TextareaAutosize/index.js +1 -1
  76. package/Tooltip/Tooltip.js +2 -3
  77. package/Unstable_TrapFocus/FocusTrap.d.ts +10 -0
  78. package/Unstable_TrapFocus/FocusTrap.js +332 -0
  79. package/Unstable_TrapFocus/FocusTrap.types.d.ts +51 -0
  80. package/Unstable_TrapFocus/FocusTrap.types.js +1 -0
  81. package/Unstable_TrapFocus/index.d.ts +2 -2
  82. package/Unstable_TrapFocus/index.js +1 -1
  83. package/index.d.ts +1 -1
  84. package/index.js +2 -2
  85. package/legacy/Autocomplete/Autocomplete.js +1 -1
  86. package/legacy/Badge/Badge.js +2 -2
  87. package/legacy/Badge/useBadge.js +42 -0
  88. package/legacy/Badge/useBadge.types.js +1 -0
  89. package/legacy/Breadcrumbs/Breadcrumbs.js +1 -1
  90. package/legacy/ClickAwayListener/ClickAwayListener.js +181 -0
  91. package/legacy/ClickAwayListener/index.js +1 -1
  92. package/legacy/InputBase/InputBase.js +2 -2
  93. package/legacy/ListItem/ListItem.js +1 -1
  94. package/legacy/Menu/Menu.js +1 -1
  95. package/legacy/Modal/Modal.js +2 -2
  96. package/legacy/Modal/ModalManager.js +233 -0
  97. package/legacy/Modal/index.js +1 -1
  98. package/legacy/Modal/useModal.js +206 -0
  99. package/legacy/Modal/useModal.types.js +1 -0
  100. package/legacy/NoSsr/NoSsr.js +75 -0
  101. package/legacy/NoSsr/NoSsr.types.js +1 -0
  102. package/legacy/NoSsr/index.js +1 -1
  103. package/legacy/Popover/Popover.js +2 -1
  104. package/legacy/Popper/BasePopper.js +380 -0
  105. package/legacy/Popper/BasePopper.types.js +1 -0
  106. package/legacy/Popper/Popper.js +1 -1
  107. package/legacy/Popper/index.js +2 -1
  108. package/legacy/Popper/popperClasses.js +7 -0
  109. package/legacy/Portal/Portal.js +92 -0
  110. package/legacy/Portal/Portal.types.js +1 -0
  111. package/legacy/Portal/index.js +1 -1
  112. package/legacy/Slider/Slider.js +3 -2
  113. package/legacy/Slider/useSlider.js +701 -0
  114. package/legacy/Slider/useSlider.types.js +1 -0
  115. package/legacy/Snackbar/Snackbar.js +4 -5
  116. package/legacy/Snackbar/useSnackbar.js +141 -0
  117. package/legacy/Snackbar/useSnackbar.types.js +1 -0
  118. package/legacy/SwipeableDrawer/SwipeableDrawer.js +1 -1
  119. package/legacy/TabScrollButton/TabScrollButton.js +1 -1
  120. package/legacy/TablePagination/TablePagination.js +1 -1
  121. package/legacy/Tabs/Tabs.js +1 -1
  122. package/legacy/TextareaAutosize/TextareaAutosize.js +220 -0
  123. package/legacy/TextareaAutosize/TextareaAutosize.types.js +1 -0
  124. package/legacy/TextareaAutosize/index.js +1 -1
  125. package/legacy/Tooltip/Tooltip.js +2 -3
  126. package/legacy/Unstable_TrapFocus/FocusTrap.js +341 -0
  127. package/legacy/Unstable_TrapFocus/FocusTrap.types.js +1 -0
  128. package/legacy/Unstable_TrapFocus/index.js +1 -1
  129. package/legacy/index.js +2 -2
  130. package/legacy/useAutocomplete/useAutocomplete.js +1078 -2
  131. package/legacy/utils/PolymorphicComponent.js +1 -0
  132. package/legacy/utils/areArraysEqual.js +9 -0
  133. package/legacy/utils/index.js +1 -1
  134. package/legacy/utils/shouldSpreadAdditionalProps.js +1 -1
  135. package/legacy/utils/useSlot.js +3 -1
  136. package/modern/Autocomplete/Autocomplete.js +1 -1
  137. package/modern/Badge/Badge.js +2 -2
  138. package/modern/Badge/useBadge.js +41 -0
  139. package/modern/Badge/useBadge.types.js +1 -0
  140. package/modern/Breadcrumbs/Breadcrumbs.js +1 -1
  141. package/modern/ClickAwayListener/ClickAwayListener.js +178 -0
  142. package/modern/ClickAwayListener/index.js +1 -1
  143. package/modern/InputBase/InputBase.js +2 -2
  144. package/modern/ListItem/ListItem.js +1 -1
  145. package/modern/Menu/Menu.js +1 -1
  146. package/modern/Modal/Modal.js +2 -2
  147. package/modern/Modal/ModalManager.js +213 -0
  148. package/modern/Modal/index.js +1 -1
  149. package/modern/Modal/useModal.js +193 -0
  150. package/modern/Modal/useModal.types.js +1 -0
  151. package/modern/NoSsr/NoSsr.js +73 -0
  152. package/modern/NoSsr/NoSsr.types.js +1 -0
  153. package/modern/NoSsr/index.js +1 -1
  154. package/modern/Popover/Popover.js +2 -1
  155. package/modern/Popper/BasePopper.js +371 -0
  156. package/modern/Popper/BasePopper.types.js +1 -0
  157. package/modern/Popper/Popper.js +1 -1
  158. package/modern/Popper/index.js +2 -1
  159. package/modern/Popper/popperClasses.js +7 -0
  160. package/modern/Portal/Portal.js +92 -0
  161. package/modern/Portal/Portal.types.js +1 -0
  162. package/modern/Portal/index.js +1 -1
  163. package/modern/Slider/Slider.js +3 -2
  164. package/modern/Slider/useSlider.js +643 -0
  165. package/modern/Slider/useSlider.types.js +1 -0
  166. package/modern/Snackbar/Snackbar.js +4 -5
  167. package/modern/Snackbar/useSnackbar.js +131 -0
  168. package/modern/Snackbar/useSnackbar.types.js +1 -0
  169. package/modern/SwipeableDrawer/SwipeableDrawer.js +1 -1
  170. package/modern/TabScrollButton/TabScrollButton.js +1 -1
  171. package/modern/TablePagination/TablePagination.js +1 -1
  172. package/modern/Tabs/Tabs.js +1 -1
  173. package/modern/TextareaAutosize/TextareaAutosize.js +223 -0
  174. package/modern/TextareaAutosize/TextareaAutosize.types.js +1 -0
  175. package/modern/TextareaAutosize/index.js +1 -1
  176. package/modern/Tooltip/Tooltip.js +2 -3
  177. package/modern/Unstable_TrapFocus/FocusTrap.js +331 -0
  178. package/modern/Unstable_TrapFocus/FocusTrap.types.js +1 -0
  179. package/modern/Unstable_TrapFocus/index.js +1 -1
  180. package/modern/index.js +2 -2
  181. package/modern/useAutocomplete/useAutocomplete.js +987 -2
  182. package/modern/utils/PolymorphicComponent.js +1 -0
  183. package/modern/utils/areArraysEqual.js +4 -0
  184. package/modern/utils/index.js +1 -1
  185. package/modern/utils/shouldSpreadAdditionalProps.js +1 -1
  186. package/modern/utils/useSlot.js +3 -1
  187. package/node/Autocomplete/Autocomplete.js +3 -3
  188. package/node/Badge/Badge.js +5 -5
  189. package/node/Badge/useBadge.js +46 -0
  190. package/node/Badge/useBadge.types.js +5 -0
  191. package/node/Breadcrumbs/Breadcrumbs.js +2 -2
  192. package/node/ClickAwayListener/ClickAwayListener.js +184 -0
  193. package/node/ClickAwayListener/index.js +1 -1
  194. package/node/InputBase/InputBase.js +7 -7
  195. package/node/ListItem/ListItem.js +3 -3
  196. package/node/Menu/Menu.js +3 -3
  197. package/node/Modal/Modal.js +5 -5
  198. package/node/Modal/ModalManager.js +221 -0
  199. package/node/Modal/index.js +2 -2
  200. package/node/Modal/useModal.js +203 -0
  201. package/node/Modal/useModal.types.js +5 -0
  202. package/node/NoSsr/NoSsr.js +81 -0
  203. package/node/NoSsr/NoSsr.types.js +5 -0
  204. package/node/NoSsr/index.js +3 -2
  205. package/node/Popover/Popover.js +5 -4
  206. package/node/Popper/BasePopper.js +380 -0
  207. package/node/Popper/BasePopper.types.js +5 -0
  208. package/node/Popper/Popper.js +2 -2
  209. package/node/Popper/index.js +14 -1
  210. package/node/Popper/popperClasses.js +15 -0
  211. package/node/Portal/Portal.js +100 -0
  212. package/node/Portal/Portal.types.js +5 -0
  213. package/node/Portal/index.js +3 -2
  214. package/node/Slider/Slider.js +14 -13
  215. package/node/Slider/useSlider.js +666 -0
  216. package/node/Slider/useSlider.types.js +5 -0
  217. package/node/Snackbar/Snackbar.js +9 -10
  218. package/node/Snackbar/useSnackbar.js +139 -0
  219. package/node/Snackbar/useSnackbar.types.js +5 -0
  220. package/node/SwipeableDrawer/SwipeableDrawer.js +2 -2
  221. package/node/TabScrollButton/TabScrollButton.js +3 -3
  222. package/node/TablePagination/TablePagination.js +2 -2
  223. package/node/Tabs/Tabs.js +3 -3
  224. package/node/TextareaAutosize/TextareaAutosize.js +230 -0
  225. package/node/TextareaAutosize/TextareaAutosize.types.js +5 -0
  226. package/node/TextareaAutosize/index.js +3 -2
  227. package/node/Tooltip/Tooltip.js +10 -11
  228. package/node/Unstable_TrapFocus/FocusTrap.js +339 -0
  229. package/node/Unstable_TrapFocus/FocusTrap.types.js +5 -0
  230. package/node/Unstable_TrapFocus/index.js +3 -2
  231. package/node/index.js +3 -3
  232. package/node/useAutocomplete/useAutocomplete.js +997 -18
  233. package/node/utils/PolymorphicComponent.js +5 -0
  234. package/node/utils/areArraysEqual.js +10 -0
  235. package/node/utils/index.js +2 -2
  236. package/node/utils/shouldSpreadAdditionalProps.js +3 -2
  237. package/node/utils/useSlot.js +6 -4
  238. package/package.json +5 -5
  239. package/styles/overrides.d.ts +1 -1
  240. package/umd/material-ui.development.js +9190 -9248
  241. package/umd/material-ui.production.min.js +3 -3
  242. package/useAutocomplete/useAutocomplete.d.ts +460 -2
  243. package/useAutocomplete/useAutocomplete.js +994 -2
  244. package/utils/PolymorphicComponent.d.ts +17 -0
  245. package/utils/PolymorphicComponent.js +1 -0
  246. package/utils/areArraysEqual.d.ts +3 -0
  247. package/utils/areArraysEqual.js +4 -0
  248. package/utils/index.d.ts +2 -1
  249. package/utils/index.js +1 -1
  250. package/utils/shouldSpreadAdditionalProps.js +1 -1
  251. package/utils/types.d.ts +2 -1
  252. package/utils/useSlot.js +3 -1
@@ -0,0 +1,655 @@
1
+ 'use client';
2
+
3
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
+ import * as React from 'react';
5
+ import { unstable_ownerDocument as ownerDocument, unstable_useControlled as useControlled, unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback, unstable_useForkRef as useForkRef, unstable_useIsFocusVisible as useIsFocusVisible, visuallyHidden, clamp } from '@mui/utils';
6
+ import extractEventHandlers from '@mui/utils/extractEventHandlers';
7
+ import areArraysEqual from '../utils/areArraysEqual';
8
+ const INTENTIONAL_DRAG_COUNT_THRESHOLD = 2;
9
+ function asc(a, b) {
10
+ return a - b;
11
+ }
12
+ function findClosest(values, currentValue) {
13
+ var _values$reduce;
14
+ const {
15
+ index: closestIndex
16
+ } = (_values$reduce = values.reduce((acc, value, index) => {
17
+ const distance = Math.abs(currentValue - value);
18
+ if (acc === null || distance < acc.distance || distance === acc.distance) {
19
+ return {
20
+ distance,
21
+ index
22
+ };
23
+ }
24
+ return acc;
25
+ }, null)) != null ? _values$reduce : {};
26
+ return closestIndex;
27
+ }
28
+ function trackFinger(event, touchId) {
29
+ // The event is TouchEvent
30
+ if (touchId.current !== undefined && event.changedTouches) {
31
+ const touchEvent = event;
32
+ for (let i = 0; i < touchEvent.changedTouches.length; i += 1) {
33
+ const touch = touchEvent.changedTouches[i];
34
+ if (touch.identifier === touchId.current) {
35
+ return {
36
+ x: touch.clientX,
37
+ y: touch.clientY
38
+ };
39
+ }
40
+ }
41
+ return false;
42
+ }
43
+
44
+ // The event is MouseEvent
45
+ return {
46
+ x: event.clientX,
47
+ y: event.clientY
48
+ };
49
+ }
50
+ export function valueToPercent(value, min, max) {
51
+ return (value - min) * 100 / (max - min);
52
+ }
53
+ function percentToValue(percent, min, max) {
54
+ return (max - min) * percent + min;
55
+ }
56
+ function getDecimalPrecision(num) {
57
+ // This handles the case when num is very small (0.00000001), js will turn this into 1e-8.
58
+ // When num is bigger than 1 or less than -1 it won't get converted to this notation so it's fine.
59
+ if (Math.abs(num) < 1) {
60
+ const parts = num.toExponential().split('e-');
61
+ const matissaDecimalPart = parts[0].split('.')[1];
62
+ return (matissaDecimalPart ? matissaDecimalPart.length : 0) + parseInt(parts[1], 10);
63
+ }
64
+ const decimalPart = num.toString().split('.')[1];
65
+ return decimalPart ? decimalPart.length : 0;
66
+ }
67
+ function roundValueToStep(value, step, min) {
68
+ const nearest = Math.round((value - min) / step) * step + min;
69
+ return Number(nearest.toFixed(getDecimalPrecision(step)));
70
+ }
71
+ function setValueIndex({
72
+ values,
73
+ newValue,
74
+ index
75
+ }) {
76
+ const output = values.slice();
77
+ output[index] = newValue;
78
+ return output.sort(asc);
79
+ }
80
+ function focusThumb({
81
+ sliderRef,
82
+ activeIndex,
83
+ setActive
84
+ }) {
85
+ var _sliderRef$current, _doc$activeElement;
86
+ const doc = ownerDocument(sliderRef.current);
87
+ if (!((_sliderRef$current = sliderRef.current) != null && _sliderRef$current.contains(doc.activeElement)) || Number(doc == null || (_doc$activeElement = doc.activeElement) == null ? void 0 : _doc$activeElement.getAttribute('data-index')) !== activeIndex) {
88
+ var _sliderRef$current2;
89
+ (_sliderRef$current2 = sliderRef.current) == null || _sliderRef$current2.querySelector(`[type="range"][data-index="${activeIndex}"]`).focus();
90
+ }
91
+ if (setActive) {
92
+ setActive(activeIndex);
93
+ }
94
+ }
95
+ function areValuesEqual(newValue, oldValue) {
96
+ if (typeof newValue === 'number' && typeof oldValue === 'number') {
97
+ return newValue === oldValue;
98
+ }
99
+ if (typeof newValue === 'object' && typeof oldValue === 'object') {
100
+ return areArraysEqual(newValue, oldValue);
101
+ }
102
+ return false;
103
+ }
104
+ const axisProps = {
105
+ horizontal: {
106
+ offset: percent => ({
107
+ left: `${percent}%`
108
+ }),
109
+ leap: percent => ({
110
+ width: `${percent}%`
111
+ })
112
+ },
113
+ 'horizontal-reverse': {
114
+ offset: percent => ({
115
+ right: `${percent}%`
116
+ }),
117
+ leap: percent => ({
118
+ width: `${percent}%`
119
+ })
120
+ },
121
+ vertical: {
122
+ offset: percent => ({
123
+ bottom: `${percent}%`
124
+ }),
125
+ leap: percent => ({
126
+ height: `${percent}%`
127
+ })
128
+ }
129
+ };
130
+ export const Identity = x => x;
131
+
132
+ // TODO: remove support for Safari < 13.
133
+ // https://caniuse.com/#search=touch-action
134
+ //
135
+ // Safari, on iOS, supports touch action since v13.
136
+ // Over 80% of the iOS phones are compatible
137
+ // in August 2020.
138
+ // Utilizing the CSS.supports method to check if touch-action is supported.
139
+ // Since CSS.supports is supported on all but Edge@12 and IE and touch-action
140
+ // is supported on both Edge@12 and IE if CSS.supports is not available that means that
141
+ // touch-action will be supported
142
+ let cachedSupportsTouchActionNone;
143
+ function doesSupportTouchActionNone() {
144
+ if (cachedSupportsTouchActionNone === undefined) {
145
+ if (typeof CSS !== 'undefined' && typeof CSS.supports === 'function') {
146
+ cachedSupportsTouchActionNone = CSS.supports('touch-action', 'none');
147
+ } else {
148
+ cachedSupportsTouchActionNone = true;
149
+ }
150
+ }
151
+ return cachedSupportsTouchActionNone;
152
+ }
153
+ /**
154
+ *
155
+ * Demos:
156
+ *
157
+ * - [Slider](https://mui.com/base-ui/react-slider/#hook)
158
+ *
159
+ * API:
160
+ *
161
+ * - [useSlider API](https://mui.com/base-ui/react-slider/hooks-api/#use-slider)
162
+ */
163
+ export function useSlider(parameters) {
164
+ const {
165
+ 'aria-labelledby': ariaLabelledby,
166
+ defaultValue,
167
+ disabled = false,
168
+ disableSwap = false,
169
+ isRtl = false,
170
+ marks: marksProp = false,
171
+ max = 100,
172
+ min = 0,
173
+ name,
174
+ onChange,
175
+ onChangeCommitted,
176
+ orientation = 'horizontal',
177
+ rootRef: ref,
178
+ scale = Identity,
179
+ step = 1,
180
+ shiftStep = 10,
181
+ tabIndex,
182
+ value: valueProp
183
+ } = parameters;
184
+ const touchId = React.useRef();
185
+ // We can't use the :active browser pseudo-classes.
186
+ // - The active state isn't triggered when clicking on the rail.
187
+ // - The active state isn't transferred when inversing a range slider.
188
+ const [active, setActive] = React.useState(-1);
189
+ const [open, setOpen] = React.useState(-1);
190
+ const [dragging, setDragging] = React.useState(false);
191
+ const moveCount = React.useRef(0);
192
+ const [valueDerived, setValueState] = useControlled({
193
+ controlled: valueProp,
194
+ default: defaultValue != null ? defaultValue : min,
195
+ name: 'Slider'
196
+ });
197
+ const handleChange = onChange && ((event, value, thumbIndex) => {
198
+ // Redefine target to allow name and value to be read.
199
+ // This allows seamless integration with the most popular form libraries.
200
+ // https://github.com/mui/material-ui/issues/13485#issuecomment-676048492
201
+ // Clone the event to not override `target` of the original event.
202
+ const nativeEvent = event.nativeEvent || event;
203
+ // @ts-ignore The nativeEvent is function, not object
204
+ const clonedEvent = new nativeEvent.constructor(nativeEvent.type, nativeEvent);
205
+ Object.defineProperty(clonedEvent, 'target', {
206
+ writable: true,
207
+ value: {
208
+ value,
209
+ name
210
+ }
211
+ });
212
+ onChange(clonedEvent, value, thumbIndex);
213
+ });
214
+ const range = Array.isArray(valueDerived);
215
+ let values = range ? valueDerived.slice().sort(asc) : [valueDerived];
216
+ values = values.map(value => value == null ? min : clamp(value, min, max));
217
+ const marks = marksProp === true && step !== null ? [...Array(Math.floor((max - min) / step) + 1)].map((_, index) => ({
218
+ value: min + step * index
219
+ })) : marksProp || [];
220
+ const marksValues = marks.map(mark => mark.value);
221
+ const {
222
+ isFocusVisibleRef,
223
+ onBlur: handleBlurVisible,
224
+ onFocus: handleFocusVisible,
225
+ ref: focusVisibleRef
226
+ } = useIsFocusVisible();
227
+ const [focusedThumbIndex, setFocusedThumbIndex] = React.useState(-1);
228
+ const sliderRef = React.useRef();
229
+ const handleFocusRef = useForkRef(focusVisibleRef, sliderRef);
230
+ const handleRef = useForkRef(ref, handleFocusRef);
231
+ const createHandleHiddenInputFocus = otherHandlers => event => {
232
+ var _otherHandlers$onFocu;
233
+ const index = Number(event.currentTarget.getAttribute('data-index'));
234
+ handleFocusVisible(event);
235
+ if (isFocusVisibleRef.current === true) {
236
+ setFocusedThumbIndex(index);
237
+ }
238
+ setOpen(index);
239
+ otherHandlers == null || (_otherHandlers$onFocu = otherHandlers.onFocus) == null || _otherHandlers$onFocu.call(otherHandlers, event);
240
+ };
241
+ const createHandleHiddenInputBlur = otherHandlers => event => {
242
+ var _otherHandlers$onBlur;
243
+ handleBlurVisible(event);
244
+ if (isFocusVisibleRef.current === false) {
245
+ setFocusedThumbIndex(-1);
246
+ }
247
+ setOpen(-1);
248
+ otherHandlers == null || (_otherHandlers$onBlur = otherHandlers.onBlur) == null || _otherHandlers$onBlur.call(otherHandlers, event);
249
+ };
250
+ const changeValue = (event, valueInput) => {
251
+ const index = Number(event.currentTarget.getAttribute('data-index'));
252
+ const value = values[index];
253
+ const marksIndex = marksValues.indexOf(value);
254
+ let newValue = valueInput;
255
+ if (marks && step == null) {
256
+ const maxMarksValue = marksValues[marksValues.length - 1];
257
+ if (newValue > maxMarksValue) {
258
+ newValue = maxMarksValue;
259
+ } else if (newValue < marksValues[0]) {
260
+ newValue = marksValues[0];
261
+ } else {
262
+ newValue = newValue < value ? marksValues[marksIndex - 1] : marksValues[marksIndex + 1];
263
+ }
264
+ }
265
+ newValue = clamp(newValue, min, max);
266
+ if (range) {
267
+ // Bound the new value to the thumb's neighbours.
268
+ if (disableSwap) {
269
+ newValue = clamp(newValue, values[index - 1] || -Infinity, values[index + 1] || Infinity);
270
+ }
271
+ const previousValue = newValue;
272
+ newValue = setValueIndex({
273
+ values,
274
+ newValue,
275
+ index
276
+ });
277
+ let activeIndex = index;
278
+
279
+ // Potentially swap the index if needed.
280
+ if (!disableSwap) {
281
+ activeIndex = newValue.indexOf(previousValue);
282
+ }
283
+ focusThumb({
284
+ sliderRef,
285
+ activeIndex
286
+ });
287
+ }
288
+ setValueState(newValue);
289
+ setFocusedThumbIndex(index);
290
+ if (handleChange && !areValuesEqual(newValue, valueDerived)) {
291
+ handleChange(event, newValue, index);
292
+ }
293
+ if (onChangeCommitted) {
294
+ onChangeCommitted(event, newValue);
295
+ }
296
+ };
297
+ const createHandleHiddenInputKeyDown = otherHandlers => event => {
298
+ var _otherHandlers$onKeyD;
299
+ // The Shift + Up/Down keyboard shortcuts for moving the slider makes sense to be supported
300
+ // only if the step is defined. If the step is null, this means tha the marks are used for specifying the valid values.
301
+ if (step !== null) {
302
+ const index = Number(event.currentTarget.getAttribute('data-index'));
303
+ const value = values[index];
304
+ let newValue = null;
305
+ if ((event.key === 'ArrowLeft' || event.key === 'ArrowDown') && event.shiftKey || event.key === 'PageDown') {
306
+ newValue = Math.max(value - shiftStep, min);
307
+ } else if ((event.key === 'ArrowRight' || event.key === 'ArrowUp') && event.shiftKey || event.key === 'PageUp') {
308
+ newValue = Math.min(value + shiftStep, max);
309
+ }
310
+ if (newValue !== null) {
311
+ changeValue(event, newValue);
312
+ event.preventDefault();
313
+ }
314
+ }
315
+ otherHandlers == null || (_otherHandlers$onKeyD = otherHandlers.onKeyDown) == null || _otherHandlers$onKeyD.call(otherHandlers, event);
316
+ };
317
+ useEnhancedEffect(() => {
318
+ if (disabled && sliderRef.current.contains(document.activeElement)) {
319
+ var _document$activeEleme;
320
+ // This is necessary because Firefox and Safari will keep focus
321
+ // on a disabled element:
322
+ // https://codesandbox.io/p/sandbox/mui-pr-22247-forked-h151h?file=/src/App.js
323
+ // @ts-ignore
324
+ (_document$activeEleme = document.activeElement) == null || _document$activeEleme.blur();
325
+ }
326
+ }, [disabled]);
327
+ if (disabled && active !== -1) {
328
+ setActive(-1);
329
+ }
330
+ if (disabled && focusedThumbIndex !== -1) {
331
+ setFocusedThumbIndex(-1);
332
+ }
333
+ const createHandleHiddenInputChange = otherHandlers => event => {
334
+ var _otherHandlers$onChan;
335
+ (_otherHandlers$onChan = otherHandlers.onChange) == null || _otherHandlers$onChan.call(otherHandlers, event);
336
+ // @ts-ignore
337
+ changeValue(event, event.target.valueAsNumber);
338
+ };
339
+ const previousIndex = React.useRef();
340
+ let axis = orientation;
341
+ if (isRtl && orientation === 'horizontal') {
342
+ axis += '-reverse';
343
+ }
344
+ const getFingerNewValue = ({
345
+ finger,
346
+ move = false
347
+ }) => {
348
+ const {
349
+ current: slider
350
+ } = sliderRef;
351
+ const {
352
+ width,
353
+ height,
354
+ bottom,
355
+ left
356
+ } = slider.getBoundingClientRect();
357
+ let percent;
358
+ if (axis.indexOf('vertical') === 0) {
359
+ percent = (bottom - finger.y) / height;
360
+ } else {
361
+ percent = (finger.x - left) / width;
362
+ }
363
+ if (axis.indexOf('-reverse') !== -1) {
364
+ percent = 1 - percent;
365
+ }
366
+ let newValue;
367
+ newValue = percentToValue(percent, min, max);
368
+ if (step) {
369
+ newValue = roundValueToStep(newValue, step, min);
370
+ } else {
371
+ const closestIndex = findClosest(marksValues, newValue);
372
+ newValue = marksValues[closestIndex];
373
+ }
374
+ newValue = clamp(newValue, min, max);
375
+ let activeIndex = 0;
376
+ if (range) {
377
+ if (!move) {
378
+ activeIndex = findClosest(values, newValue);
379
+ } else {
380
+ activeIndex = previousIndex.current;
381
+ }
382
+
383
+ // Bound the new value to the thumb's neighbours.
384
+ if (disableSwap) {
385
+ newValue = clamp(newValue, values[activeIndex - 1] || -Infinity, values[activeIndex + 1] || Infinity);
386
+ }
387
+ const previousValue = newValue;
388
+ newValue = setValueIndex({
389
+ values,
390
+ newValue,
391
+ index: activeIndex
392
+ });
393
+
394
+ // Potentially swap the index if needed.
395
+ if (!(disableSwap && move)) {
396
+ activeIndex = newValue.indexOf(previousValue);
397
+ previousIndex.current = activeIndex;
398
+ }
399
+ }
400
+ return {
401
+ newValue,
402
+ activeIndex
403
+ };
404
+ };
405
+ const handleTouchMove = useEventCallback(nativeEvent => {
406
+ const finger = trackFinger(nativeEvent, touchId);
407
+ if (!finger) {
408
+ return;
409
+ }
410
+ moveCount.current += 1;
411
+
412
+ // Cancel move in case some other element consumed a mouseup event and it was not fired.
413
+ // @ts-ignore buttons doesn't not exists on touch event
414
+ if (nativeEvent.type === 'mousemove' && nativeEvent.buttons === 0) {
415
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
416
+ handleTouchEnd(nativeEvent);
417
+ return;
418
+ }
419
+ const {
420
+ newValue,
421
+ activeIndex
422
+ } = getFingerNewValue({
423
+ finger,
424
+ move: true
425
+ });
426
+ focusThumb({
427
+ sliderRef,
428
+ activeIndex,
429
+ setActive
430
+ });
431
+ setValueState(newValue);
432
+ if (!dragging && moveCount.current > INTENTIONAL_DRAG_COUNT_THRESHOLD) {
433
+ setDragging(true);
434
+ }
435
+ if (handleChange && !areValuesEqual(newValue, valueDerived)) {
436
+ handleChange(nativeEvent, newValue, activeIndex);
437
+ }
438
+ });
439
+ const handleTouchEnd = useEventCallback(nativeEvent => {
440
+ const finger = trackFinger(nativeEvent, touchId);
441
+ setDragging(false);
442
+ if (!finger) {
443
+ return;
444
+ }
445
+ const {
446
+ newValue
447
+ } = getFingerNewValue({
448
+ finger,
449
+ move: true
450
+ });
451
+ setActive(-1);
452
+ if (nativeEvent.type === 'touchend') {
453
+ setOpen(-1);
454
+ }
455
+ if (onChangeCommitted) {
456
+ onChangeCommitted(nativeEvent, newValue);
457
+ }
458
+ touchId.current = undefined;
459
+
460
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
461
+ stopListening();
462
+ });
463
+ const handleTouchStart = useEventCallback(nativeEvent => {
464
+ if (disabled) {
465
+ return;
466
+ }
467
+ // If touch-action: none; is not supported we need to prevent the scroll manually.
468
+ if (!doesSupportTouchActionNone()) {
469
+ nativeEvent.preventDefault();
470
+ }
471
+ const touch = nativeEvent.changedTouches[0];
472
+ if (touch != null) {
473
+ // A number that uniquely identifies the current finger in the touch session.
474
+ touchId.current = touch.identifier;
475
+ }
476
+ const finger = trackFinger(nativeEvent, touchId);
477
+ if (finger !== false) {
478
+ const {
479
+ newValue,
480
+ activeIndex
481
+ } = getFingerNewValue({
482
+ finger
483
+ });
484
+ focusThumb({
485
+ sliderRef,
486
+ activeIndex,
487
+ setActive
488
+ });
489
+ setValueState(newValue);
490
+ if (handleChange && !areValuesEqual(newValue, valueDerived)) {
491
+ handleChange(nativeEvent, newValue, activeIndex);
492
+ }
493
+ }
494
+ moveCount.current = 0;
495
+ const doc = ownerDocument(sliderRef.current);
496
+ doc.addEventListener('touchmove', handleTouchMove, {
497
+ passive: true
498
+ });
499
+ doc.addEventListener('touchend', handleTouchEnd, {
500
+ passive: true
501
+ });
502
+ });
503
+ const stopListening = React.useCallback(() => {
504
+ const doc = ownerDocument(sliderRef.current);
505
+ doc.removeEventListener('mousemove', handleTouchMove);
506
+ doc.removeEventListener('mouseup', handleTouchEnd);
507
+ doc.removeEventListener('touchmove', handleTouchMove);
508
+ doc.removeEventListener('touchend', handleTouchEnd);
509
+ }, [handleTouchEnd, handleTouchMove]);
510
+ React.useEffect(() => {
511
+ const {
512
+ current: slider
513
+ } = sliderRef;
514
+ slider.addEventListener('touchstart', handleTouchStart, {
515
+ passive: doesSupportTouchActionNone()
516
+ });
517
+ return () => {
518
+ slider.removeEventListener('touchstart', handleTouchStart);
519
+ stopListening();
520
+ };
521
+ }, [stopListening, handleTouchStart]);
522
+ React.useEffect(() => {
523
+ if (disabled) {
524
+ stopListening();
525
+ }
526
+ }, [disabled, stopListening]);
527
+ const createHandleMouseDown = otherHandlers => event => {
528
+ var _otherHandlers$onMous;
529
+ (_otherHandlers$onMous = otherHandlers.onMouseDown) == null || _otherHandlers$onMous.call(otherHandlers, event);
530
+ if (disabled) {
531
+ return;
532
+ }
533
+ if (event.defaultPrevented) {
534
+ return;
535
+ }
536
+
537
+ // Only handle left clicks
538
+ if (event.button !== 0) {
539
+ return;
540
+ }
541
+
542
+ // Avoid text selection
543
+ event.preventDefault();
544
+ const finger = trackFinger(event, touchId);
545
+ if (finger !== false) {
546
+ const {
547
+ newValue,
548
+ activeIndex
549
+ } = getFingerNewValue({
550
+ finger
551
+ });
552
+ focusThumb({
553
+ sliderRef,
554
+ activeIndex,
555
+ setActive
556
+ });
557
+ setValueState(newValue);
558
+ if (handleChange && !areValuesEqual(newValue, valueDerived)) {
559
+ handleChange(event, newValue, activeIndex);
560
+ }
561
+ }
562
+ moveCount.current = 0;
563
+ const doc = ownerDocument(sliderRef.current);
564
+ doc.addEventListener('mousemove', handleTouchMove, {
565
+ passive: true
566
+ });
567
+ doc.addEventListener('mouseup', handleTouchEnd);
568
+ };
569
+ const trackOffset = valueToPercent(range ? values[0] : min, min, max);
570
+ const trackLeap = valueToPercent(values[values.length - 1], min, max) - trackOffset;
571
+ const getRootProps = (externalProps = {}) => {
572
+ const externalHandlers = extractEventHandlers(externalProps);
573
+ const ownEventHandlers = {
574
+ onMouseDown: createHandleMouseDown(externalHandlers || {})
575
+ };
576
+ const mergedEventHandlers = _extends({}, externalHandlers, ownEventHandlers);
577
+ return _extends({}, externalProps, {
578
+ ref: handleRef
579
+ }, mergedEventHandlers);
580
+ };
581
+ const createHandleMouseOver = otherHandlers => event => {
582
+ var _otherHandlers$onMous2;
583
+ (_otherHandlers$onMous2 = otherHandlers.onMouseOver) == null || _otherHandlers$onMous2.call(otherHandlers, event);
584
+ const index = Number(event.currentTarget.getAttribute('data-index'));
585
+ setOpen(index);
586
+ };
587
+ const createHandleMouseLeave = otherHandlers => event => {
588
+ var _otherHandlers$onMous3;
589
+ (_otherHandlers$onMous3 = otherHandlers.onMouseLeave) == null || _otherHandlers$onMous3.call(otherHandlers, event);
590
+ setOpen(-1);
591
+ };
592
+ const getThumbProps = (externalProps = {}) => {
593
+ const externalHandlers = extractEventHandlers(externalProps);
594
+ const ownEventHandlers = {
595
+ onMouseOver: createHandleMouseOver(externalHandlers || {}),
596
+ onMouseLeave: createHandleMouseLeave(externalHandlers || {})
597
+ };
598
+ return _extends({}, externalProps, externalHandlers, ownEventHandlers);
599
+ };
600
+ const getThumbStyle = index => {
601
+ return {
602
+ // So the non active thumb doesn't show its label on hover.
603
+ pointerEvents: active !== -1 && active !== index ? 'none' : undefined
604
+ };
605
+ };
606
+ const getHiddenInputProps = (externalProps = {}) => {
607
+ var _parameters$step;
608
+ const externalHandlers = extractEventHandlers(externalProps);
609
+ const ownEventHandlers = {
610
+ onChange: createHandleHiddenInputChange(externalHandlers || {}),
611
+ onFocus: createHandleHiddenInputFocus(externalHandlers || {}),
612
+ onBlur: createHandleHiddenInputBlur(externalHandlers || {}),
613
+ onKeyDown: createHandleHiddenInputKeyDown(externalHandlers || {})
614
+ };
615
+ const mergedEventHandlers = _extends({}, externalHandlers, ownEventHandlers);
616
+ return _extends({
617
+ tabIndex,
618
+ 'aria-labelledby': ariaLabelledby,
619
+ 'aria-orientation': orientation,
620
+ 'aria-valuemax': scale(max),
621
+ 'aria-valuemin': scale(min),
622
+ name,
623
+ type: 'range',
624
+ min: parameters.min,
625
+ max: parameters.max,
626
+ step: parameters.step === null && parameters.marks ? 'any' : (_parameters$step = parameters.step) != null ? _parameters$step : undefined,
627
+ disabled
628
+ }, externalProps, mergedEventHandlers, {
629
+ style: _extends({}, visuallyHidden, {
630
+ direction: isRtl ? 'rtl' : 'ltr',
631
+ // So that VoiceOver's focus indicator matches the thumb's dimensions
632
+ width: '100%',
633
+ height: '100%'
634
+ })
635
+ });
636
+ };
637
+ return {
638
+ active,
639
+ axis: axis,
640
+ axisProps,
641
+ dragging,
642
+ focusedThumbIndex,
643
+ getHiddenInputProps,
644
+ getRootProps,
645
+ getThumbProps,
646
+ marks: marks,
647
+ open,
648
+ range,
649
+ rootRef: handleRef,
650
+ trackLeap,
651
+ trackOffset,
652
+ values,
653
+ getThumbStyle
654
+ };
655
+ }