7
7
} from '@mui/utils' ;
8
8
import { OverridableComponent } from '@mui/types' ;
9
9
import { useSlider } from '@mui/base/SliderUnstyled' ;
10
- import { useSlotProps } from '@mui/base/utils' ;
11
10
import { useThemeProps , styled , Theme } from '../styles' ;
11
+ import useSlot from '../utils/useSlot' ;
12
12
import sliderClasses , { getSliderUtilityClass } from './sliderClasses' ;
13
13
import { SliderProps , SliderTypeMap , SliderOwnerState } from './SliderProps' ;
14
14
@@ -34,13 +34,14 @@ const useUtilityClasses = (ownerState: SliderOwnerState) => {
34
34
] ,
35
35
rail : [ 'rail' ] ,
36
36
track : [ 'track' ] ,
37
+ thumb : [ 'thumb' , disabled && 'disabled' ] ,
38
+ input : [ 'input' ] ,
37
39
mark : [ 'mark' ] ,
38
40
markActive : [ 'markActive' ] ,
39
41
markLabel : [ 'markLabel' ] ,
40
42
markLabelActive : [ 'markLabelActive' ] ,
41
43
valueLabel : [ 'valueLabel' ] ,
42
44
valueLabelOpen : [ 'valueLabelOpen' ] ,
43
- thumb : [ 'thumb' , disabled && 'disabled' ] ,
44
45
active : [ 'active' ] ,
45
46
focusVisible : [ 'focusVisible' ] ,
46
47
} ;
@@ -399,7 +400,8 @@ const Slider = React.forwardRef(function Slider(inProps, ref) {
399
400
const {
400
401
'aria-label' : ariaLabel ,
401
402
'aria-valuetext' : ariaValuetext ,
402
- component,
403
+ className,
404
+ component = 'span' ,
403
405
componentsProps = { } ,
404
406
classes : classesProp ,
405
407
disableSwap = false ,
@@ -475,76 +477,75 @@ const Slider = React.forwardRef(function Slider(inProps, ref) {
475
477
} ;
476
478
477
479
const classes = useUtilityClasses ( ownerState ) ;
480
+ const externalForwardedProps = { ...other , component, componentsProps } ;
478
481
479
- const rootProps = useSlotProps ( {
482
+ const [ SlotRoot , rootProps ] = useSlot ( 'root' , {
483
+ ref,
484
+ className : clsx ( classes . root , className ) ,
480
485
elementType : SliderRoot ,
486
+ externalForwardedProps,
481
487
getSlotProps : getRootProps ,
482
- externalSlotProps : componentsProps . root ,
483
- externalForwardedProps : other ,
484
- additionalProps : {
485
- as : component ,
486
- } ,
487
488
ownerState,
488
- className : classes . root ,
489
489
} ) ;
490
490
491
- const railProps = useSlotProps ( {
491
+ const [ SlotRail , railProps ] = useSlot ( 'rail' , {
492
+ className : classes . rail ,
492
493
elementType : SliderRail ,
493
- externalSlotProps : componentsProps . rail ,
494
+ externalForwardedProps ,
494
495
ownerState,
495
- className : classes . rail ,
496
496
} ) ;
497
497
498
- const trackProps = useSlotProps ( {
499
- elementType : SliderTrack ,
500
- externalSlotProps : componentsProps . track ,
498
+ const [ SlotTrack , trackProps ] = useSlot ( 'track' , {
501
499
additionalProps : {
502
500
style : trackStyle ,
503
501
} ,
504
- ownerState,
505
502
className : classes . track ,
503
+ elementType : SliderTrack ,
504
+ externalForwardedProps,
505
+ ownerState,
506
506
} ) ;
507
507
508
- const markProps = useSlotProps ( {
508
+ const [ SlotMark , markProps ] = useSlot ( 'mark' , {
509
+ className : classes . mark ,
509
510
elementType : SliderMark ,
510
- externalSlotProps : componentsProps . mark ,
511
+ externalForwardedProps ,
511
512
ownerState,
512
- className : classes . mark ,
513
513
} ) ;
514
514
515
- const markLabelProps = useSlotProps ( {
515
+ const [ SlotMarkLabel , markLabelProps ] = useSlot ( 'markLabel' , {
516
+ className : classes . markLabel ,
516
517
elementType : SliderMarkLabel ,
517
- externalSlotProps : componentsProps . markLabel ,
518
+ externalForwardedProps ,
518
519
ownerState,
519
- className : classes . markLabel ,
520
520
} ) ;
521
521
522
- const thumbProps = useSlotProps ( {
522
+ const [ SlotThumb , thumbProps ] = useSlot ( 'thumb' , {
523
+ className : classes . thumb ,
523
524
elementType : SliderThumb ,
525
+ externalForwardedProps,
524
526
getSlotProps : getThumbProps ,
525
- externalSlotProps : componentsProps . thumb ,
526
527
ownerState,
527
- className : classes . thumb ,
528
528
} ) ;
529
529
530
- const inputProps = useSlotProps ( {
530
+ const [ SlotInput , inputProps ] = useSlot ( 'input' , {
531
+ className : classes . input ,
531
532
elementType : SliderInput ,
533
+ externalForwardedProps,
532
534
getSlotProps : getHiddenInputProps ,
533
- externalSlotProps : componentsProps . input ,
534
535
ownerState,
535
536
} ) ;
536
537
537
- const valueLabelProps = useSlotProps ( {
538
+ const [ SlotValueLabel , valueLabelProps ] = useSlot ( 'valueLabel' , {
539
+ className : classes . valueLabel ,
538
540
elementType : SliderValueLabel ,
539
- externalSlotProps : componentsProps . valueLabel ,
541
+ externalForwardedProps ,
540
542
ownerState,
541
- className : classes . valueLabel ,
542
543
} ) ;
543
544
544
545
return (
545
- < SliderRoot { ...rootProps } >
546
- < SliderRail { ...railProps } />
547
- < SliderTrack { ...trackProps } />
546
+ < SlotRoot { ...rootProps } >
547
+ < SlotRail { ...railProps } />
548
+ < SlotTrack { ...trackProps } />
548
549
{ marks
549
550
. filter ( ( mark ) => mark . value >= min && mark . value <= max )
550
551
. map ( ( mark , index ) => {
@@ -568,7 +569,7 @@ const Slider = React.forwardRef(function Slider(inProps, ref) {
568
569
569
570
return (
570
571
< React . Fragment key = { mark . value } >
571
- < SliderMark
572
+ < SlotMark
572
573
data-index = { index }
573
574
{ ...markProps }
574
575
style = { { ...style , ...markProps . style } }
@@ -578,7 +579,7 @@ const Slider = React.forwardRef(function Slider(inProps, ref) {
578
579
} ) }
579
580
/>
580
581
{ mark . label != null ? (
581
- < SliderMarkLabel
582
+ < SlotMarkLabel
582
583
aria-hidden
583
584
data-index = { index }
584
585
{ ...markLabelProps }
@@ -589,7 +590,7 @@ const Slider = React.forwardRef(function Slider(inProps, ref) {
589
590
} ) }
590
591
>
591
592
{ mark . label }
592
- </ SliderMarkLabel >
593
+ </ SlotMarkLabel >
593
594
) : null }
594
595
</ React . Fragment >
595
596
) ;
@@ -598,7 +599,7 @@ const Slider = React.forwardRef(function Slider(inProps, ref) {
598
599
const percent = valueToPercent ( value , min , max ) ;
599
600
const style = axisProps [ axis ] . offset ( percent ) ;
600
601
return (
601
- < SliderThumb
602
+ < SlotThumb
602
603
key = { index }
603
604
data-index = { index }
604
605
{ ...thumbProps }
@@ -612,7 +613,7 @@ const Slider = React.forwardRef(function Slider(inProps, ref) {
612
613
...thumbProps . style ,
613
614
} }
614
615
>
615
- < SliderInput
616
+ < SlotInput
616
617
data-index = { index }
617
618
aria-label = { getAriaLabel ? getAriaLabel ( index ) : ariaLabel }
618
619
aria-valuenow = { scale ( value ) }
@@ -623,7 +624,7 @@ const Slider = React.forwardRef(function Slider(inProps, ref) {
623
624
{ ...inputProps }
624
625
/>
625
626
{ valueLabelDisplay !== 'off' ? (
626
- < SliderValueLabel
627
+ < SlotValueLabel
627
628
{ ...valueLabelProps }
628
629
className = { clsx ( valueLabelProps . className , {
629
630
[ classes . valueLabelOpen ] :
@@ -633,12 +634,12 @@ const Slider = React.forwardRef(function Slider(inProps, ref) {
633
634
{ typeof valueLabelFormat === 'function'
634
635
? valueLabelFormat ( scale ( value ) , index )
635
636
: valueLabelFormat }
636
- </ SliderValueLabel >
637
+ </ SlotValueLabel >
637
638
) : null }
638
- </ SliderThumb >
639
+ </ SlotThumb >
639
640
) ;
640
641
} ) }
641
- </ SliderRoot >
642
+ </ SlotRoot >
642
643
) ;
643
644
} ) as OverridableComponent < SliderTypeMap > ;
644
645
@@ -663,6 +664,10 @@ Slider.propTypes /* remove-proptypes */ = {
663
664
* Override or extend the styles applied to the component.
664
665
*/
665
666
classes : PropTypes . object ,
667
+ /**
668
+ * @ignore
669
+ */
670
+ className : PropTypes . string ,
666
671
/**
667
672
* The color of the component. It supports those theme colors that make sense for this component.
668
673
* @default 'primary'
@@ -677,7 +682,20 @@ Slider.propTypes /* remove-proptypes */ = {
677
682
*/
678
683
component : PropTypes . elementType ,
679
684
/**
680
- * The props used for each slot inside the Slider.
685
+ * Replace the default slots.
686
+ */
687
+ components : PropTypes . shape ( {
688
+ input : PropTypes . elementType ,
689
+ mark : PropTypes . elementType ,
690
+ markLabel : PropTypes . elementType ,
691
+ rail : PropTypes . elementType ,
692
+ root : PropTypes . elementType ,
693
+ thumb : PropTypes . elementType ,
694
+ track : PropTypes . elementType ,
695
+ valueLabel : PropTypes . elementType ,
696
+ } ) ,
697
+ /**
698
+ * The props used for each slot inside the component.
681
699
* @default {}
682
700
*/
683
701
componentsProps : PropTypes . shape ( {
0 commit comments