1 | 'use client';
|
2 |
|
3 | import _extends from "@babel/runtime/helpers/esm/extends";
|
4 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
5 | const _excluded = ["aria-label", "aria-valuetext", "aria-labelledby", "className", "disableSwap", "disabled", "getAriaLabel", "getAriaValueText", "marks", "max", "min", "name", "onChange", "onChangeCommitted", "orientation", "shiftStep", "scale", "step", "tabIndex", "track", "value", "valueLabelFormat", "isRtl", "defaultValue", "slotProps", "slots"];
|
6 | import * as React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import clsx from 'clsx';
|
9 | import { chainPropTypes } from '@mui/utils';
|
10 | import { isHostComponent } from '../utils/isHostComponent';
|
11 | import { unstable_composeClasses as composeClasses } from '../composeClasses';
|
12 | import { getSliderUtilityClass } from './sliderClasses';
|
13 | import { useSlider, valueToPercent } from '../useSlider';
|
14 | import { useSlotProps } from '../utils/useSlotProps';
|
15 | import { resolveComponentProps } from '../utils/resolveComponentProps';
|
16 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
17 |
|
18 |
|
19 | import { jsx as _jsx } from "react/jsx-runtime";
|
20 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
21 | function Identity(x) {
|
22 | return x;
|
23 | }
|
24 | const useUtilityClasses = ownerState => {
|
25 | const {
|
26 | disabled,
|
27 | dragging,
|
28 | marked,
|
29 | orientation,
|
30 | track
|
31 | } = ownerState;
|
32 | const slots = {
|
33 | root: ['root', disabled && 'disabled', dragging && 'dragging', marked && 'marked', orientation === 'vertical' && 'vertical', track === 'inverted' && 'trackInverted', track === false && 'trackFalse'],
|
34 | rail: ['rail'],
|
35 | track: ['track'],
|
36 | mark: ['mark'],
|
37 | markActive: ['markActive'],
|
38 | markLabel: ['markLabel'],
|
39 | markLabelActive: ['markLabelActive'],
|
40 | valueLabel: ['valueLabel'],
|
41 | thumb: ['thumb', disabled && 'disabled'],
|
42 | active: ['active'],
|
43 | disabled: ['disabled'],
|
44 | focusVisible: ['focusVisible']
|
45 | };
|
46 | return composeClasses(slots, useClassNamesOverride(getSliderUtilityClass));
|
47 | };
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | const Slider = React.forwardRef(function Slider(props, forwardedRef) {
|
60 | var _slots$root, _slots$rail, _slots$track, _slots$thumb, _slots$mark, _slots$markLabel;
|
61 | const {
|
62 | 'aria-label': ariaLabel,
|
63 | 'aria-valuetext': ariaValuetext,
|
64 | 'aria-labelledby': ariaLabelledby,
|
65 | className,
|
66 | disableSwap = false,
|
67 | disabled = false,
|
68 | getAriaLabel,
|
69 | getAriaValueText,
|
70 | marks: marksProp = false,
|
71 | max = 100,
|
72 | min = 0,
|
73 | orientation = 'horizontal',
|
74 | shiftStep = 10,
|
75 | scale = Identity,
|
76 | step = 1,
|
77 | track = 'normal',
|
78 | valueLabelFormat = Identity,
|
79 | isRtl = false,
|
80 | defaultValue,
|
81 | slotProps = {},
|
82 | slots = {}
|
83 | } = props,
|
84 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
85 |
|
86 |
|
87 |
|
88 | const partialOwnerState = _extends({}, props, {
|
89 | marks: marksProp,
|
90 | disabled,
|
91 | disableSwap,
|
92 | isRtl,
|
93 | defaultValue,
|
94 | max,
|
95 | min,
|
96 | orientation,
|
97 | scale,
|
98 | step,
|
99 | shiftStep,
|
100 | track,
|
101 | valueLabelFormat
|
102 | });
|
103 | const {
|
104 | axisProps,
|
105 | getRootProps,
|
106 | getHiddenInputProps,
|
107 | getThumbProps,
|
108 | active,
|
109 | axis,
|
110 | range,
|
111 | focusedThumbIndex,
|
112 | dragging,
|
113 | marks,
|
114 | values,
|
115 | trackOffset,
|
116 | trackLeap,
|
117 | getThumbStyle
|
118 | } = useSlider(_extends({}, partialOwnerState, {
|
119 | rootRef: forwardedRef
|
120 | }));
|
121 | const ownerState = _extends({}, partialOwnerState, {
|
122 | marked: marks.length > 0 && marks.some(mark => mark.label),
|
123 | dragging,
|
124 | focusedThumbIndex,
|
125 | activeThumbIndex: active
|
126 | });
|
127 | const classes = useUtilityClasses(ownerState);
|
128 | const Root = (_slots$root = slots.root) != null ? _slots$root : 'span';
|
129 | const rootProps = useSlotProps({
|
130 | elementType: Root,
|
131 | getSlotProps: getRootProps,
|
132 | externalSlotProps: slotProps.root,
|
133 | externalForwardedProps: other,
|
134 | ownerState,
|
135 | className: [classes.root, className]
|
136 | });
|
137 | const Rail = (_slots$rail = slots.rail) != null ? _slots$rail : 'span';
|
138 | const railProps = useSlotProps({
|
139 | elementType: Rail,
|
140 | externalSlotProps: slotProps.rail,
|
141 | ownerState,
|
142 | className: classes.rail
|
143 | });
|
144 | const Track = (_slots$track = slots.track) != null ? _slots$track : 'span';
|
145 | const trackProps = useSlotProps({
|
146 | elementType: Track,
|
147 | externalSlotProps: slotProps.track,
|
148 | additionalProps: {
|
149 | style: _extends({}, axisProps[axis].offset(trackOffset), axisProps[axis].leap(trackLeap))
|
150 | },
|
151 | ownerState,
|
152 | className: classes.track
|
153 | });
|
154 | const Thumb = (_slots$thumb = slots.thumb) != null ? _slots$thumb : 'span';
|
155 | const thumbProps = useSlotProps({
|
156 | elementType: Thumb,
|
157 | getSlotProps: getThumbProps,
|
158 | externalSlotProps: slotProps.thumb,
|
159 | ownerState,
|
160 | skipResolvingSlotProps: true
|
161 | });
|
162 | const ValueLabel = slots.valueLabel;
|
163 | const valueLabelProps = useSlotProps({
|
164 | elementType: ValueLabel,
|
165 | externalSlotProps: slotProps.valueLabel,
|
166 | ownerState
|
167 | });
|
168 | const Mark = (_slots$mark = slots.mark) != null ? _slots$mark : 'span';
|
169 | const markProps = useSlotProps({
|
170 | elementType: Mark,
|
171 | externalSlotProps: slotProps.mark,
|
172 | ownerState,
|
173 | className: classes.mark
|
174 | });
|
175 | const MarkLabel = (_slots$markLabel = slots.markLabel) != null ? _slots$markLabel : 'span';
|
176 | const markLabelProps = useSlotProps({
|
177 | elementType: MarkLabel,
|
178 | externalSlotProps: slotProps.markLabel,
|
179 | ownerState
|
180 | });
|
181 | const Input = slots.input || 'input';
|
182 | const inputProps = useSlotProps({
|
183 | elementType: Input,
|
184 | getSlotProps: getHiddenInputProps,
|
185 | externalSlotProps: slotProps.input,
|
186 | ownerState
|
187 | });
|
188 | return _jsxs(Root, _extends({}, rootProps, {
|
189 | children: [_jsx(Rail, _extends({}, railProps)), _jsx(Track, _extends({}, trackProps)), marks.filter(mark => mark.value >= min && mark.value <= max).map((mark, index) => {
|
190 | const percent = valueToPercent(mark.value, min, max);
|
191 | const style = axisProps[axis].offset(percent);
|
192 | let markActive;
|
193 | if (track === false) {
|
194 | markActive = values.indexOf(mark.value) !== -1;
|
195 | } else {
|
196 | markActive = track === 'normal' && (range ? mark.value >= values[0] && mark.value <= values[values.length - 1] : mark.value <= values[0]) || track === 'inverted' && (range ? mark.value <= values[0] || mark.value >= values[values.length - 1] : mark.value >= values[0]);
|
197 | }
|
198 | return _jsxs(React.Fragment, {
|
199 | children: [_jsx(Mark, _extends({
|
200 | "data-index": index
|
201 | }, markProps, !isHostComponent(Mark) && {
|
202 | markActive
|
203 | }, {
|
204 | style: _extends({}, style, markProps.style),
|
205 | className: clsx(markProps.className, markActive && classes.markActive)
|
206 | })), mark.label != null ? _jsx(MarkLabel, _extends({
|
207 | "aria-hidden": true,
|
208 | "data-index": index
|
209 | }, markLabelProps, !isHostComponent(MarkLabel) && {
|
210 | markLabelActive: markActive
|
211 | }, {
|
212 | style: _extends({}, style, markLabelProps.style),
|
213 | className: clsx(classes.markLabel, markLabelProps.className, markActive && classes.markLabelActive),
|
214 | children: mark.label
|
215 | })) : null]
|
216 | }, index);
|
217 | }), values.map((value, index) => {
|
218 | const percent = valueToPercent(value, min, max);
|
219 | const style = axisProps[axis].offset(percent);
|
220 | const resolvedSlotProps = resolveComponentProps(slotProps.thumb, ownerState, {
|
221 | index,
|
222 | focused: focusedThumbIndex === index,
|
223 | active: active === index
|
224 | });
|
225 | return _jsxs(Thumb, _extends({
|
226 | "data-index": index
|
227 | }, thumbProps, resolvedSlotProps, {
|
228 | className: clsx(classes.thumb, thumbProps.className, resolvedSlotProps == null ? void 0 : resolvedSlotProps.className, active === index && classes.active, focusedThumbIndex === index && classes.focusVisible),
|
229 | style: _extends({}, style, getThumbStyle(index), thumbProps.style, resolvedSlotProps == null ? void 0 : resolvedSlotProps.style),
|
230 | children: [_jsx(Input, _extends({
|
231 | "data-index": index,
|
232 | "aria-label": getAriaLabel ? getAriaLabel(index) : ariaLabel,
|
233 | "aria-valuenow": scale(value),
|
234 | "aria-labelledby": ariaLabelledby,
|
235 | "aria-valuetext": getAriaValueText ? getAriaValueText(scale(value), index) : ariaValuetext,
|
236 | value: values[index]
|
237 | }, inputProps)), ValueLabel ? _jsx(ValueLabel, _extends({}, !isHostComponent(ValueLabel) && {
|
238 | valueLabelFormat,
|
239 | index,
|
240 | disabled
|
241 | }, valueLabelProps, {
|
242 | children: typeof valueLabelFormat === 'function' ? valueLabelFormat(scale(value), index) : valueLabelFormat
|
243 | })) : null]
|
244 | }), index);
|
245 | })]
|
246 | }));
|
247 | });
|
248 | process.env.NODE_ENV !== "production" ? Slider.propTypes = {
|
249 |
|
250 |
|
251 |
|
252 |
|
253 | |
254 |
|
255 |
|
256 | 'aria-label': chainPropTypes(PropTypes.string, props => {
|
257 | const range = Array.isArray(props.value || props.defaultValue);
|
258 | if (range && props['aria-label'] != null) {
|
259 | return new Error('MUI: You need to use the `getAriaLabel` prop instead of `aria-label` when using a range slider.');
|
260 | }
|
261 | return null;
|
262 | }),
|
263 | |
264 |
|
265 |
|
266 | 'aria-labelledby': PropTypes.string,
|
267 | |
268 |
|
269 |
|
270 | 'aria-valuetext': chainPropTypes(PropTypes.string, props => {
|
271 | const range = Array.isArray(props.value || props.defaultValue);
|
272 | if (range && props['aria-valuetext'] != null) {
|
273 | return new Error('MUI: You need to use the `getAriaValueText` prop instead of `aria-valuetext` when using a range slider.');
|
274 | }
|
275 | return null;
|
276 | }),
|
277 | |
278 |
|
279 |
|
280 | defaultValue: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
|
281 | |
282 |
|
283 |
|
284 |
|
285 | disabled: PropTypes.bool,
|
286 | |
287 |
|
288 |
|
289 |
|
290 | disableSwap: PropTypes.bool,
|
291 | |
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 | getAriaLabel: PropTypes.func,
|
298 | |
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 | getAriaValueText: PropTypes.func,
|
306 | |
307 |
|
308 |
|
309 |
|
310 | isRtl: PropTypes.bool,
|
311 | |
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 | marks: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.shape({
|
318 | label: PropTypes.node,
|
319 | value: PropTypes.number.isRequired
|
320 | })), PropTypes.bool]),
|
321 | |
322 |
|
323 |
|
324 |
|
325 |
|
326 | max: PropTypes.number,
|
327 | |
328 |
|
329 |
|
330 |
|
331 |
|
332 | min: PropTypes.number,
|
333 | |
334 |
|
335 |
|
336 | name: PropTypes.string,
|
337 | |
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 | onChange: PropTypes.func,
|
347 | |
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 | onChangeCommitted: PropTypes.func,
|
354 | |
355 |
|
356 |
|
357 |
|
358 | orientation: PropTypes.oneOf(['horizontal', 'vertical']),
|
359 | |
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 | scale: PropTypes.func,
|
368 | |
369 |
|
370 |
|
371 |
|
372 | shiftStep: PropTypes.number,
|
373 | |
374 |
|
375 |
|
376 |
|
377 | slotProps: PropTypes.shape({
|
378 | input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
379 | mark: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
380 | markLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
381 | rail: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
382 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
383 | thumb: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
384 | track: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
385 | valueLabel: PropTypes.oneOfType([PropTypes.any, PropTypes.func])
|
386 | }),
|
387 | |
388 |
|
389 |
|
390 |
|
391 |
|
392 | slots: PropTypes.shape({
|
393 | input: PropTypes.elementType,
|
394 | mark: PropTypes.elementType,
|
395 | markLabel: PropTypes.elementType,
|
396 | rail: PropTypes.elementType,
|
397 | root: PropTypes.elementType,
|
398 | thumb: PropTypes.elementType,
|
399 | track: PropTypes.elementType,
|
400 | valueLabel: PropTypes.elementType
|
401 | }),
|
402 | |
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 | step: PropTypes.number,
|
411 | |
412 |
|
413 |
|
414 | tabIndex: PropTypes.number,
|
415 | |
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 | track: PropTypes.oneOf(['inverted', 'normal', false]),
|
424 | |
425 |
|
426 |
|
427 |
|
428 | value: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
|
429 | |
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 | valueLabelFormat: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
|
443 | } : void 0;
|
444 | export { Slider }; |
\ | No newline at end of file |