1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import chainPropTypes from '@mui/utils/chainPropTypes';
|
7 | import composeClasses from '@mui/utils/composeClasses';
|
8 | import { alpha, lighten, darken } from '@mui/system/colorManipulator';
|
9 | import { useRtl } from '@mui/system/RtlProvider';
|
10 | import useSlotProps from '@mui/utils/useSlotProps';
|
11 | import { useSlider, valueToPercent } from "./useSlider.js";
|
12 | import isHostComponent from "../utils/isHostComponent.js";
|
13 | import { styled } from "../zero-styled/index.js";
|
14 | import memoTheme from "../utils/memoTheme.js";
|
15 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
16 | import slotShouldForwardProp from "../styles/slotShouldForwardProp.js";
|
17 | import shouldSpreadAdditionalProps from "../utils/shouldSpreadAdditionalProps.js";
|
18 | import capitalize from "../utils/capitalize.js";
|
19 | import createSimplePaletteValueFilter from "../utils/createSimplePaletteValueFilter.js";
|
20 | import BaseSliderValueLabel from "./SliderValueLabel.js";
|
21 | import sliderClasses, { getSliderUtilityClass } from "./sliderClasses.js";
|
22 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
23 | function Identity(x) {
|
24 | return x;
|
25 | }
|
26 | export const SliderRoot = styled('span', {
|
27 | name: 'MuiSlider',
|
28 | slot: 'Root',
|
29 | overridesResolver: (props, styles) => {
|
30 | const {
|
31 | ownerState
|
32 | } = props;
|
33 | return [styles.root, styles[`color${capitalize(ownerState.color)}`], ownerState.size !== 'medium' && styles[`size${capitalize(ownerState.size)}`], ownerState.marked && styles.marked, ownerState.orientation === 'vertical' && styles.vertical, ownerState.track === 'inverted' && styles.trackInverted, ownerState.track === false && styles.trackFalse];
|
34 | }
|
35 | })(memoTheme(({
|
36 | theme
|
37 | }) => ({
|
38 | borderRadius: 12,
|
39 | boxSizing: 'content-box',
|
40 | display: 'inline-block',
|
41 | position: 'relative',
|
42 | cursor: 'pointer',
|
43 | touchAction: 'none',
|
44 | WebkitTapHighlightColor: 'transparent',
|
45 | '@media print': {
|
46 | colorAdjust: 'exact'
|
47 | },
|
48 | [`&.${sliderClasses.disabled}`]: {
|
49 | pointerEvents: 'none',
|
50 | cursor: 'default',
|
51 | color: (theme.vars || theme).palette.grey[400]
|
52 | },
|
53 | [`&.${sliderClasses.dragging}`]: {
|
54 | [`& .${sliderClasses.thumb}, & .${sliderClasses.track}`]: {
|
55 | transition: 'none'
|
56 | }
|
57 | },
|
58 | variants: [...Object.entries(theme.palette).filter(createSimplePaletteValueFilter()).map(([color]) => ({
|
59 | props: {
|
60 | color
|
61 | },
|
62 | style: {
|
63 | color: (theme.vars || theme).palette[color].main
|
64 | }
|
65 | })), {
|
66 | props: {
|
67 | orientation: 'horizontal'
|
68 | },
|
69 | style: {
|
70 | height: 4,
|
71 | width: '100%',
|
72 | padding: '13px 0',
|
73 |
|
74 | '@media (pointer: coarse)': {
|
75 |
|
76 | padding: '20px 0'
|
77 | }
|
78 | }
|
79 | }, {
|
80 | props: {
|
81 | orientation: 'horizontal',
|
82 | size: 'small'
|
83 | },
|
84 | style: {
|
85 | height: 2
|
86 | }
|
87 | }, {
|
88 | props: {
|
89 | orientation: 'horizontal',
|
90 | marked: true
|
91 | },
|
92 | style: {
|
93 | marginBottom: 20
|
94 | }
|
95 | }, {
|
96 | props: {
|
97 | orientation: 'vertical'
|
98 | },
|
99 | style: {
|
100 | height: '100%',
|
101 | width: 4,
|
102 | padding: '0 13px',
|
103 |
|
104 | '@media (pointer: coarse)': {
|
105 |
|
106 | padding: '0 20px'
|
107 | }
|
108 | }
|
109 | }, {
|
110 | props: {
|
111 | orientation: 'vertical',
|
112 | size: 'small'
|
113 | },
|
114 | style: {
|
115 | width: 2
|
116 | }
|
117 | }, {
|
118 | props: {
|
119 | orientation: 'vertical',
|
120 | marked: true
|
121 | },
|
122 | style: {
|
123 | marginRight: 44
|
124 | }
|
125 | }]
|
126 | })));
|
127 | export const SliderRail = styled('span', {
|
128 | name: 'MuiSlider',
|
129 | slot: 'Rail',
|
130 | overridesResolver: (props, styles) => styles.rail
|
131 | })({
|
132 | display: 'block',
|
133 | position: 'absolute',
|
134 | borderRadius: 'inherit',
|
135 | backgroundColor: 'currentColor',
|
136 | opacity: 0.38,
|
137 | variants: [{
|
138 | props: {
|
139 | orientation: 'horizontal'
|
140 | },
|
141 | style: {
|
142 | width: '100%',
|
143 | height: 'inherit',
|
144 | top: '50%',
|
145 | transform: 'translateY(-50%)'
|
146 | }
|
147 | }, {
|
148 | props: {
|
149 | orientation: 'vertical'
|
150 | },
|
151 | style: {
|
152 | height: '100%',
|
153 | width: 'inherit',
|
154 | left: '50%',
|
155 | transform: 'translateX(-50%)'
|
156 | }
|
157 | }, {
|
158 | props: {
|
159 | track: 'inverted'
|
160 | },
|
161 | style: {
|
162 | opacity: 1
|
163 | }
|
164 | }]
|
165 | });
|
166 | export const SliderTrack = styled('span', {
|
167 | name: 'MuiSlider',
|
168 | slot: 'Track',
|
169 | overridesResolver: (props, styles) => styles.track
|
170 | })(memoTheme(({
|
171 | theme
|
172 | }) => {
|
173 | return {
|
174 | display: 'block',
|
175 | position: 'absolute',
|
176 | borderRadius: 'inherit',
|
177 | border: '1px solid currentColor',
|
178 | backgroundColor: 'currentColor',
|
179 | transition: theme.transitions.create(['left', 'width', 'bottom', 'height'], {
|
180 | duration: theme.transitions.duration.shortest
|
181 | }),
|
182 | variants: [{
|
183 | props: {
|
184 | size: 'small'
|
185 | },
|
186 | style: {
|
187 | border: 'none'
|
188 | }
|
189 | }, {
|
190 | props: {
|
191 | orientation: 'horizontal'
|
192 | },
|
193 | style: {
|
194 | height: 'inherit',
|
195 | top: '50%',
|
196 | transform: 'translateY(-50%)'
|
197 | }
|
198 | }, {
|
199 | props: {
|
200 | orientation: 'vertical'
|
201 | },
|
202 | style: {
|
203 | width: 'inherit',
|
204 | left: '50%',
|
205 | transform: 'translateX(-50%)'
|
206 | }
|
207 | }, {
|
208 | props: {
|
209 | track: false
|
210 | },
|
211 | style: {
|
212 | display: 'none'
|
213 | }
|
214 | }, ...Object.entries(theme.palette).filter(createSimplePaletteValueFilter()).map(([color]) => ({
|
215 | props: {
|
216 | color,
|
217 | track: 'inverted'
|
218 | },
|
219 | style: {
|
220 | ...(theme.vars ? {
|
221 | backgroundColor: theme.vars.palette.Slider[`${color}Track`],
|
222 | borderColor: theme.vars.palette.Slider[`${color}Track`]
|
223 | } : {
|
224 | backgroundColor: lighten(theme.palette[color].main, 0.62),
|
225 | borderColor: lighten(theme.palette[color].main, 0.62),
|
226 | ...theme.applyStyles('dark', {
|
227 | backgroundColor: darken(theme.palette[color].main, 0.5)
|
228 | }),
|
229 | ...theme.applyStyles('dark', {
|
230 | borderColor: darken(theme.palette[color].main, 0.5)
|
231 | })
|
232 | })
|
233 | }
|
234 | }))]
|
235 | };
|
236 | }));
|
237 | export const SliderThumb = styled('span', {
|
238 | name: 'MuiSlider',
|
239 | slot: 'Thumb',
|
240 | overridesResolver: (props, styles) => {
|
241 | const {
|
242 | ownerState
|
243 | } = props;
|
244 | return [styles.thumb, styles[`thumbColor${capitalize(ownerState.color)}`], ownerState.size !== 'medium' && styles[`thumbSize${capitalize(ownerState.size)}`]];
|
245 | }
|
246 | })(memoTheme(({
|
247 | theme
|
248 | }) => ({
|
249 | position: 'absolute',
|
250 | width: 20,
|
251 | height: 20,
|
252 | boxSizing: 'border-box',
|
253 | borderRadius: '50%',
|
254 | outline: 0,
|
255 | backgroundColor: 'currentColor',
|
256 | display: 'flex',
|
257 | alignItems: 'center',
|
258 | justifyContent: 'center',
|
259 | transition: theme.transitions.create(['box-shadow', 'left', 'bottom'], {
|
260 | duration: theme.transitions.duration.shortest
|
261 | }),
|
262 | '&::before': {
|
263 | position: 'absolute',
|
264 | content: '""',
|
265 | borderRadius: 'inherit',
|
266 | width: '100%',
|
267 | height: '100%',
|
268 | boxShadow: (theme.vars || theme).shadows[2]
|
269 | },
|
270 | '&::after': {
|
271 | position: 'absolute',
|
272 | content: '""',
|
273 | borderRadius: '50%',
|
274 |
|
275 | width: 42,
|
276 | height: 42,
|
277 | top: '50%',
|
278 | left: '50%',
|
279 | transform: 'translate(-50%, -50%)'
|
280 | },
|
281 | [`&.${sliderClasses.disabled}`]: {
|
282 | '&:hover': {
|
283 | boxShadow: 'none'
|
284 | }
|
285 | },
|
286 | variants: [{
|
287 | props: {
|
288 | size: 'small'
|
289 | },
|
290 | style: {
|
291 | width: 12,
|
292 | height: 12,
|
293 | '&::before': {
|
294 | boxShadow: 'none'
|
295 | }
|
296 | }
|
297 | }, {
|
298 | props: {
|
299 | orientation: 'horizontal'
|
300 | },
|
301 | style: {
|
302 | top: '50%',
|
303 | transform: 'translate(-50%, -50%)'
|
304 | }
|
305 | }, {
|
306 | props: {
|
307 | orientation: 'vertical'
|
308 | },
|
309 | style: {
|
310 | left: '50%',
|
311 | transform: 'translate(-50%, 50%)'
|
312 | }
|
313 | }, ...Object.entries(theme.palette).filter(createSimplePaletteValueFilter()).map(([color]) => ({
|
314 | props: {
|
315 | color
|
316 | },
|
317 | style: {
|
318 | [`&:hover, &.${sliderClasses.focusVisible}`]: {
|
319 | ...(theme.vars ? {
|
320 | boxShadow: `0px 0px 0px 8px rgba(${theme.vars.palette[color].mainChannel} / 0.16)`
|
321 | } : {
|
322 | boxShadow: `0px 0px 0px 8px ${alpha(theme.palette[color].main, 0.16)}`
|
323 | }),
|
324 | '@media (hover: none)': {
|
325 | boxShadow: 'none'
|
326 | }
|
327 | },
|
328 | [`&.${sliderClasses.active}`]: {
|
329 | ...(theme.vars ? {
|
330 | boxShadow: `0px 0px 0px 14px rgba(${theme.vars.palette[color].mainChannel} / 0.16)`
|
331 | } : {
|
332 | boxShadow: `0px 0px 0px 14px ${alpha(theme.palette[color].main, 0.16)}`
|
333 | })
|
334 | }
|
335 | }
|
336 | }))]
|
337 | })));
|
338 | const SliderValueLabel = styled(BaseSliderValueLabel, {
|
339 | name: 'MuiSlider',
|
340 | slot: 'ValueLabel',
|
341 | overridesResolver: (props, styles) => styles.valueLabel
|
342 | })(memoTheme(({
|
343 | theme
|
344 | }) => ({
|
345 | zIndex: 1,
|
346 | whiteSpace: 'nowrap',
|
347 | ...theme.typography.body2,
|
348 | fontWeight: 500,
|
349 | transition: theme.transitions.create(['transform'], {
|
350 | duration: theme.transitions.duration.shortest
|
351 | }),
|
352 | position: 'absolute',
|
353 | backgroundColor: (theme.vars || theme).palette.grey[600],
|
354 | borderRadius: 2,
|
355 | color: (theme.vars || theme).palette.common.white,
|
356 | display: 'flex',
|
357 | alignItems: 'center',
|
358 | justifyContent: 'center',
|
359 | padding: '0.25rem 0.75rem',
|
360 | variants: [{
|
361 | props: {
|
362 | orientation: 'horizontal'
|
363 | },
|
364 | style: {
|
365 | transform: 'translateY(-100%) scale(0)',
|
366 | top: '-10px',
|
367 | transformOrigin: 'bottom center',
|
368 | '&::before': {
|
369 | position: 'absolute',
|
370 | content: '""',
|
371 | width: 8,
|
372 | height: 8,
|
373 | transform: 'translate(-50%, 50%) rotate(45deg)',
|
374 | backgroundColor: 'inherit',
|
375 | bottom: 0,
|
376 | left: '50%'
|
377 | },
|
378 | [`&.${sliderClasses.valueLabelOpen}`]: {
|
379 | transform: 'translateY(-100%) scale(1)'
|
380 | }
|
381 | }
|
382 | }, {
|
383 | props: {
|
384 | orientation: 'vertical'
|
385 | },
|
386 | style: {
|
387 | transform: 'translateY(-50%) scale(0)',
|
388 | right: '30px',
|
389 | top: '50%',
|
390 | transformOrigin: 'right center',
|
391 | '&::before': {
|
392 | position: 'absolute',
|
393 | content: '""',
|
394 | width: 8,
|
395 | height: 8,
|
396 | transform: 'translate(-50%, -50%) rotate(45deg)',
|
397 | backgroundColor: 'inherit',
|
398 | right: -8,
|
399 | top: '50%'
|
400 | },
|
401 | [`&.${sliderClasses.valueLabelOpen}`]: {
|
402 | transform: 'translateY(-50%) scale(1)'
|
403 | }
|
404 | }
|
405 | }, {
|
406 | props: {
|
407 | size: 'small'
|
408 | },
|
409 | style: {
|
410 | fontSize: theme.typography.pxToRem(12),
|
411 | padding: '0.25rem 0.5rem'
|
412 | }
|
413 | }, {
|
414 | props: {
|
415 | orientation: 'vertical',
|
416 | size: 'small'
|
417 | },
|
418 | style: {
|
419 | right: '20px'
|
420 | }
|
421 | }]
|
422 | })));
|
423 | process.env.NODE_ENV !== "production" ? SliderValueLabel.propTypes = {
|
424 |
|
425 |
|
426 |
|
427 |
|
428 | |
429 |
|
430 |
|
431 | children: PropTypes.element.isRequired,
|
432 | |
433 |
|
434 |
|
435 | index: PropTypes.number.isRequired,
|
436 | |
437 |
|
438 |
|
439 | open: PropTypes.bool.isRequired,
|
440 | |
441 |
|
442 |
|
443 | value: PropTypes.node
|
444 | } : void 0;
|
445 | export { SliderValueLabel };
|
446 | export const SliderMark = styled('span', {
|
447 | name: 'MuiSlider',
|
448 | slot: 'Mark',
|
449 | shouldForwardProp: prop => slotShouldForwardProp(prop) && prop !== 'markActive',
|
450 | overridesResolver: (props, styles) => {
|
451 | const {
|
452 | markActive
|
453 | } = props;
|
454 | return [styles.mark, markActive && styles.markActive];
|
455 | }
|
456 | })(memoTheme(({
|
457 | theme
|
458 | }) => ({
|
459 | position: 'absolute',
|
460 | width: 2,
|
461 | height: 2,
|
462 | borderRadius: 1,
|
463 | backgroundColor: 'currentColor',
|
464 | variants: [{
|
465 | props: {
|
466 | orientation: 'horizontal'
|
467 | },
|
468 | style: {
|
469 | top: '50%',
|
470 | transform: 'translate(-1px, -50%)'
|
471 | }
|
472 | }, {
|
473 | props: {
|
474 | orientation: 'vertical'
|
475 | },
|
476 | style: {
|
477 | left: '50%',
|
478 | transform: 'translate(-50%, 1px)'
|
479 | }
|
480 | }, {
|
481 | props: {
|
482 | markActive: true
|
483 | },
|
484 | style: {
|
485 | backgroundColor: (theme.vars || theme).palette.background.paper,
|
486 | opacity: 0.8
|
487 | }
|
488 | }]
|
489 | })));
|
490 | export const SliderMarkLabel = styled('span', {
|
491 | name: 'MuiSlider',
|
492 | slot: 'MarkLabel',
|
493 | shouldForwardProp: prop => slotShouldForwardProp(prop) && prop !== 'markLabelActive',
|
494 | overridesResolver: (props, styles) => styles.markLabel
|
495 | })(memoTheme(({
|
496 | theme
|
497 | }) => ({
|
498 | ...theme.typography.body2,
|
499 | color: (theme.vars || theme).palette.text.secondary,
|
500 | position: 'absolute',
|
501 | whiteSpace: 'nowrap',
|
502 | variants: [{
|
503 | props: {
|
504 | orientation: 'horizontal'
|
505 | },
|
506 | style: {
|
507 | top: 30,
|
508 | transform: 'translateX(-50%)',
|
509 | '@media (pointer: coarse)': {
|
510 | top: 40
|
511 | }
|
512 | }
|
513 | }, {
|
514 | props: {
|
515 | orientation: 'vertical'
|
516 | },
|
517 | style: {
|
518 | left: 36,
|
519 | transform: 'translateY(50%)',
|
520 | '@media (pointer: coarse)': {
|
521 | left: 44
|
522 | }
|
523 | }
|
524 | }, {
|
525 | props: {
|
526 | markLabelActive: true
|
527 | },
|
528 | style: {
|
529 | color: (theme.vars || theme).palette.text.primary
|
530 | }
|
531 | }]
|
532 | })));
|
533 | const useUtilityClasses = ownerState => {
|
534 | const {
|
535 | disabled,
|
536 | dragging,
|
537 | marked,
|
538 | orientation,
|
539 | track,
|
540 | classes,
|
541 | color,
|
542 | size
|
543 | } = ownerState;
|
544 | const slots = {
|
545 | root: ['root', disabled && 'disabled', dragging && 'dragging', marked && 'marked', orientation === 'vertical' && 'vertical', track === 'inverted' && 'trackInverted', track === false && 'trackFalse', color && `color${capitalize(color)}`, size && `size${capitalize(size)}`],
|
546 | rail: ['rail'],
|
547 | track: ['track'],
|
548 | mark: ['mark'],
|
549 | markActive: ['markActive'],
|
550 | markLabel: ['markLabel'],
|
551 | markLabelActive: ['markLabelActive'],
|
552 | valueLabel: ['valueLabel'],
|
553 | thumb: ['thumb', disabled && 'disabled', size && `thumbSize${capitalize(size)}`, color && `thumbColor${capitalize(color)}`],
|
554 | active: ['active'],
|
555 | disabled: ['disabled'],
|
556 | focusVisible: ['focusVisible']
|
557 | };
|
558 | return composeClasses(slots, getSliderUtilityClass, classes);
|
559 | };
|
560 | const Forward = ({
|
561 | children
|
562 | }) => children;
|
563 | const Slider = React.forwardRef(function Slider(inputProps, ref) {
|
564 | const props = useDefaultProps({
|
565 | props: inputProps,
|
566 | name: 'MuiSlider'
|
567 | });
|
568 | const isRtl = useRtl();
|
569 | const {
|
570 | 'aria-label': ariaLabel,
|
571 | 'aria-valuetext': ariaValuetext,
|
572 | 'aria-labelledby': ariaLabelledby,
|
573 |
|
574 | component = 'span',
|
575 | components = {},
|
576 | componentsProps = {},
|
577 | color = 'primary',
|
578 | classes: classesProp,
|
579 | className,
|
580 | disableSwap = false,
|
581 | disabled = false,
|
582 | getAriaLabel,
|
583 | getAriaValueText,
|
584 | marks: marksProp = false,
|
585 | max = 100,
|
586 | min = 0,
|
587 | name,
|
588 | onChange,
|
589 | onChangeCommitted,
|
590 | orientation = 'horizontal',
|
591 | shiftStep = 10,
|
592 | size = 'medium',
|
593 | step = 1,
|
594 | scale = Identity,
|
595 | slotProps,
|
596 | slots,
|
597 | tabIndex,
|
598 | track = 'normal',
|
599 | value: valueProp,
|
600 | valueLabelDisplay = 'off',
|
601 | valueLabelFormat = Identity,
|
602 | ...other
|
603 | } = props;
|
604 | const ownerState = {
|
605 | ...props,
|
606 | isRtl,
|
607 | max,
|
608 | min,
|
609 | classes: classesProp,
|
610 | disabled,
|
611 | disableSwap,
|
612 | orientation,
|
613 | marks: marksProp,
|
614 | color,
|
615 | size,
|
616 | step,
|
617 | shiftStep,
|
618 | scale,
|
619 | track,
|
620 | valueLabelDisplay,
|
621 | valueLabelFormat
|
622 | };
|
623 | const {
|
624 | axisProps,
|
625 | getRootProps,
|
626 | getHiddenInputProps,
|
627 | getThumbProps,
|
628 | open,
|
629 | active,
|
630 | axis,
|
631 | focusedThumbIndex,
|
632 | range,
|
633 | dragging,
|
634 | marks,
|
635 | values,
|
636 | trackOffset,
|
637 | trackLeap,
|
638 | getThumbStyle
|
639 | } = useSlider({
|
640 | ...ownerState,
|
641 | rootRef: ref
|
642 | });
|
643 | ownerState.marked = marks.length > 0 && marks.some(mark => mark.label);
|
644 | ownerState.dragging = dragging;
|
645 | ownerState.focusedThumbIndex = focusedThumbIndex;
|
646 | const classes = useUtilityClasses(ownerState);
|
647 |
|
648 |
|
649 | const RootSlot = slots?.root ?? components.Root ?? SliderRoot;
|
650 | const RailSlot = slots?.rail ?? components.Rail ?? SliderRail;
|
651 | const TrackSlot = slots?.track ?? components.Track ?? SliderTrack;
|
652 | const ThumbSlot = slots?.thumb ?? components.Thumb ?? SliderThumb;
|
653 | const ValueLabelSlot = slots?.valueLabel ?? components.ValueLabel ?? SliderValueLabel;
|
654 | const MarkSlot = slots?.mark ?? components.Mark ?? SliderMark;
|
655 | const MarkLabelSlot = slots?.markLabel ?? components.MarkLabel ?? SliderMarkLabel;
|
656 | const InputSlot = slots?.input ?? components.Input ?? 'input';
|
657 | const rootSlotProps = slotProps?.root ?? componentsProps.root;
|
658 | const railSlotProps = slotProps?.rail ?? componentsProps.rail;
|
659 | const trackSlotProps = slotProps?.track ?? componentsProps.track;
|
660 | const thumbSlotProps = slotProps?.thumb ?? componentsProps.thumb;
|
661 | const valueLabelSlotProps = slotProps?.valueLabel ?? componentsProps.valueLabel;
|
662 | const markSlotProps = slotProps?.mark ?? componentsProps.mark;
|
663 | const markLabelSlotProps = slotProps?.markLabel ?? componentsProps.markLabel;
|
664 | const inputSlotProps = slotProps?.input ?? componentsProps.input;
|
665 | const rootProps = useSlotProps({
|
666 | elementType: RootSlot,
|
667 | getSlotProps: getRootProps,
|
668 | externalSlotProps: rootSlotProps,
|
669 | externalForwardedProps: other,
|
670 | additionalProps: {
|
671 | ...(shouldSpreadAdditionalProps(RootSlot) && {
|
672 | as: component
|
673 | })
|
674 | },
|
675 | ownerState: {
|
676 | ...ownerState,
|
677 | ...rootSlotProps?.ownerState
|
678 | },
|
679 | className: [classes.root, className]
|
680 | });
|
681 | const railProps = useSlotProps({
|
682 | elementType: RailSlot,
|
683 | externalSlotProps: railSlotProps,
|
684 | ownerState,
|
685 | className: classes.rail
|
686 | });
|
687 | const trackProps = useSlotProps({
|
688 | elementType: TrackSlot,
|
689 | externalSlotProps: trackSlotProps,
|
690 | additionalProps: {
|
691 | style: {
|
692 | ...axisProps[axis].offset(trackOffset),
|
693 | ...axisProps[axis].leap(trackLeap)
|
694 | }
|
695 | },
|
696 | ownerState: {
|
697 | ...ownerState,
|
698 | ...trackSlotProps?.ownerState
|
699 | },
|
700 | className: classes.track
|
701 | });
|
702 | const thumbProps = useSlotProps({
|
703 | elementType: ThumbSlot,
|
704 | getSlotProps: getThumbProps,
|
705 | externalSlotProps: thumbSlotProps,
|
706 | ownerState: {
|
707 | ...ownerState,
|
708 | ...thumbSlotProps?.ownerState
|
709 | },
|
710 | className: classes.thumb
|
711 | });
|
712 | const valueLabelProps = useSlotProps({
|
713 | elementType: ValueLabelSlot,
|
714 | externalSlotProps: valueLabelSlotProps,
|
715 | ownerState: {
|
716 | ...ownerState,
|
717 | ...valueLabelSlotProps?.ownerState
|
718 | },
|
719 | className: classes.valueLabel
|
720 | });
|
721 | const markProps = useSlotProps({
|
722 | elementType: MarkSlot,
|
723 | externalSlotProps: markSlotProps,
|
724 | ownerState,
|
725 | className: classes.mark
|
726 | });
|
727 | const markLabelProps = useSlotProps({
|
728 | elementType: MarkLabelSlot,
|
729 | externalSlotProps: markLabelSlotProps,
|
730 | ownerState,
|
731 | className: classes.markLabel
|
732 | });
|
733 | const inputSliderProps = useSlotProps({
|
734 | elementType: InputSlot,
|
735 | getSlotProps: getHiddenInputProps,
|
736 | externalSlotProps: inputSlotProps,
|
737 | ownerState
|
738 | });
|
739 | return _jsxs(RootSlot, {
|
740 | ...rootProps,
|
741 | children: [_jsx(RailSlot, {
|
742 | ...railProps
|
743 | }), _jsx(TrackSlot, {
|
744 | ...trackProps
|
745 | }), marks.filter(mark => mark.value >= min && mark.value <= max).map((mark, index) => {
|
746 | const percent = valueToPercent(mark.value, min, max);
|
747 | const style = axisProps[axis].offset(percent);
|
748 | let markActive;
|
749 | if (track === false) {
|
750 | markActive = values.includes(mark.value);
|
751 | } else {
|
752 | 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]);
|
753 | }
|
754 | return _jsxs(React.Fragment, {
|
755 | children: [_jsx(MarkSlot, {
|
756 | "data-index": index,
|
757 | ...markProps,
|
758 | ...(!isHostComponent(MarkSlot) && {
|
759 | markActive
|
760 | }),
|
761 | style: {
|
762 | ...style,
|
763 | ...markProps.style
|
764 | },
|
765 | className: clsx(markProps.className, markActive && classes.markActive)
|
766 | }), mark.label != null ? _jsx(MarkLabelSlot, {
|
767 | "aria-hidden": true,
|
768 | "data-index": index,
|
769 | ...markLabelProps,
|
770 | ...(!isHostComponent(MarkLabelSlot) && {
|
771 | markLabelActive: markActive
|
772 | }),
|
773 | style: {
|
774 | ...style,
|
775 | ...markLabelProps.style
|
776 | },
|
777 | className: clsx(classes.markLabel, markLabelProps.className, markActive && classes.markLabelActive),
|
778 | children: mark.label
|
779 | }) : null]
|
780 | }, index);
|
781 | }), values.map((value, index) => {
|
782 | const percent = valueToPercent(value, min, max);
|
783 | const style = axisProps[axis].offset(percent);
|
784 | const ValueLabelComponent = valueLabelDisplay === 'off' ? Forward : ValueLabelSlot;
|
785 | return _jsx(ValueLabelComponent, {
|
786 | ...(!isHostComponent(ValueLabelComponent) && {
|
787 | valueLabelFormat,
|
788 | valueLabelDisplay,
|
789 | value: typeof valueLabelFormat === 'function' ? valueLabelFormat(scale(value), index) : valueLabelFormat,
|
790 | index,
|
791 | open: open === index || active === index || valueLabelDisplay === 'on',
|
792 | disabled
|
793 | }),
|
794 | ...valueLabelProps,
|
795 | children: _jsx(ThumbSlot, {
|
796 | "data-index": index,
|
797 | ...thumbProps,
|
798 | className: clsx(classes.thumb, thumbProps.className, active === index && classes.active, focusedThumbIndex === index && classes.focusVisible),
|
799 | style: {
|
800 | ...style,
|
801 | ...getThumbStyle(index),
|
802 | ...thumbProps.style
|
803 | },
|
804 | children: _jsx(InputSlot, {
|
805 | "data-index": index,
|
806 | "aria-label": getAriaLabel ? getAriaLabel(index) : ariaLabel,
|
807 | "aria-valuenow": scale(value),
|
808 | "aria-labelledby": ariaLabelledby,
|
809 | "aria-valuetext": getAriaValueText ? getAriaValueText(scale(value), index) : ariaValuetext,
|
810 | value: values[index],
|
811 | ...inputSliderProps
|
812 | })
|
813 | })
|
814 | }, index);
|
815 | })]
|
816 | });
|
817 | });
|
818 | process.env.NODE_ENV !== "production" ? Slider.propTypes = {
|
819 |
|
820 |
|
821 |
|
822 |
|
823 | |
824 |
|
825 |
|
826 | 'aria-label': chainPropTypes(PropTypes.string, props => {
|
827 | const range = Array.isArray(props.value || props.defaultValue);
|
828 | if (range && props['aria-label'] != null) {
|
829 | return new Error('MUI: You need to use the `getAriaLabel` prop instead of `aria-label` when using a range slider.');
|
830 | }
|
831 | return null;
|
832 | }),
|
833 | |
834 |
|
835 |
|
836 | 'aria-labelledby': PropTypes.string,
|
837 | |
838 |
|
839 |
|
840 | 'aria-valuetext': chainPropTypes(PropTypes.string, props => {
|
841 | const range = Array.isArray(props.value || props.defaultValue);
|
842 | if (range && props['aria-valuetext'] != null) {
|
843 | return new Error('MUI: You need to use the `getAriaValueText` prop instead of `aria-valuetext` when using a range slider.');
|
844 | }
|
845 | return null;
|
846 | }),
|
847 | |
848 |
|
849 |
|
850 | children: PropTypes.node,
|
851 | |
852 |
|
853 |
|
854 | classes: PropTypes.object,
|
855 | |
856 |
|
857 |
|
858 | className: PropTypes.string,
|
859 | |
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 | color: PropTypes .oneOfType([PropTypes.oneOf(['primary', 'secondary', 'error', 'info', 'success', 'warning']), PropTypes.string]),
|
866 | |
867 |
|
868 |
|
869 |
|
870 |
|
871 |
|
872 |
|
873 | components: PropTypes.shape({
|
874 | Input: PropTypes.elementType,
|
875 | Mark: PropTypes.elementType,
|
876 | MarkLabel: PropTypes.elementType,
|
877 | Rail: PropTypes.elementType,
|
878 | Root: PropTypes.elementType,
|
879 | Thumb: PropTypes.elementType,
|
880 | Track: PropTypes.elementType,
|
881 | ValueLabel: PropTypes.elementType
|
882 | }),
|
883 | |
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 | componentsProps: PropTypes.shape({
|
892 | input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
893 | mark: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
894 | markLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
895 | rail: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
896 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
897 | thumb: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
898 | track: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
899 | valueLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
900 | children: PropTypes.element,
|
901 | className: PropTypes.string,
|
902 | open: PropTypes.bool,
|
903 | style: PropTypes.object,
|
904 | value: PropTypes.node,
|
905 | valueLabelDisplay: PropTypes.oneOf(['auto', 'off', 'on'])
|
906 | })])
|
907 | }),
|
908 | |
909 |
|
910 |
|
911 | defaultValue: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
|
912 | |
913 |
|
914 |
|
915 |
|
916 | disabled: PropTypes.bool,
|
917 | |
918 |
|
919 |
|
920 |
|
921 | disableSwap: PropTypes.bool,
|
922 | |
923 |
|
924 |
|
925 |
|
926 |
|
927 |
|
928 | getAriaLabel: PropTypes.func,
|
929 | |
930 |
|
931 |
|
932 |
|
933 |
|
934 |
|
935 |
|
936 | getAriaValueText: PropTypes.func,
|
937 | |
938 |
|
939 |
|
940 |
|
941 |
|
942 |
|
943 | marks: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.shape({
|
944 | label: PropTypes.node,
|
945 | value: PropTypes.number.isRequired
|
946 | })), PropTypes.bool]),
|
947 | |
948 |
|
949 |
|
950 |
|
951 |
|
952 | max: PropTypes.number,
|
953 | |
954 |
|
955 |
|
956 |
|
957 |
|
958 | min: PropTypes.number,
|
959 | |
960 |
|
961 |
|
962 | name: PropTypes.string,
|
963 | |
964 |
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
|
972 | onChange: PropTypes.func,
|
973 | |
974 |
|
975 |
|
976 |
|
977 |
|
978 |
|
979 | onChangeCommitted: PropTypes.func,
|
980 | |
981 |
|
982 |
|
983 |
|
984 | orientation: PropTypes.oneOf(['horizontal', 'vertical']),
|
985 | |
986 |
|
987 |
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 | scale: PropTypes.func,
|
994 | |
995 |
|
996 |
|
997 |
|
998 | shiftStep: PropTypes.number,
|
999 | |
1000 |
|
1001 |
|
1002 |
|
1003 | size: PropTypes .oneOfType([PropTypes.oneOf(['small', 'medium']), PropTypes.string]),
|
1004 | |
1005 |
|
1006 |
|
1007 |
|
1008 | slotProps: PropTypes.shape({
|
1009 | input: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
1010 | mark: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
1011 | markLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
1012 | rail: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
1013 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
1014 | thumb: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
1015 | track: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
1016 | valueLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
1017 | children: PropTypes.element,
|
1018 | className: PropTypes.string,
|
1019 | open: PropTypes.bool,
|
1020 | style: PropTypes.object,
|
1021 | value: PropTypes.node,
|
1022 | valueLabelDisplay: PropTypes.oneOf(['auto', 'off', 'on'])
|
1023 | })])
|
1024 | }),
|
1025 | |
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 | slots: PropTypes.shape({
|
1031 | input: PropTypes.elementType,
|
1032 | mark: PropTypes.elementType,
|
1033 | markLabel: PropTypes.elementType,
|
1034 | rail: PropTypes.elementType,
|
1035 | root: PropTypes.elementType,
|
1036 | thumb: PropTypes.elementType,
|
1037 | track: PropTypes.elementType,
|
1038 | valueLabel: PropTypes.elementType
|
1039 | }),
|
1040 | |
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 | step: PropTypes.number,
|
1049 | |
1050 |
|
1051 |
|
1052 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
1053 | |
1054 |
|
1055 |
|
1056 | tabIndex: PropTypes.number,
|
1057 | |
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 | track: PropTypes.oneOf(['inverted', 'normal', false]),
|
1066 | |
1067 |
|
1068 |
|
1069 |
|
1070 | value: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.number), PropTypes.number]),
|
1071 | |
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 | valueLabelDisplay: PropTypes.oneOf(['auto', 'off', 'on']),
|
1080 | |
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 | valueLabelFormat: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
|
1094 | } : void 0;
|
1095 | export default Slider; |
\ | No newline at end of file |