@@ -3,9 +3,9 @@ import PropTypes from 'prop-types';
3
3
import { OverridableComponent } from '@mui/types' ;
4
4
import { unstable_useId as useId , unstable_capitalize as capitalize } from '@mui/utils' ;
5
5
import { unstable_composeClasses as composeClasses } from '@mui/base' ;
6
- import { useSlotProps } from '@mui/base/utils' ;
7
6
import { useSwitch } from '@mui/base/SwitchUnstyled' ;
8
7
import { styled , useThemeProps } from '../styles' ;
8
+ import useSlot from '../utils/useSlot' ;
9
9
import checkboxClasses , { getCheckboxUtilityClass } from './checkboxClasses' ;
10
10
import { CheckboxOwnerState , CheckboxTypeMap } from './CheckboxProps' ;
11
11
import CheckIcon from '../internal/svg-icons/Check' ;
@@ -188,8 +188,7 @@ const Checkbox = React.forwardRef(function Checkbox(inProps, ref) {
188
188
uncheckedIcon,
189
189
checkedIcon = defaultCheckedIcon ,
190
190
label,
191
- component,
192
- componentsProps = { } ,
191
+ component = 'span' ,
193
192
defaultChecked,
194
193
disabled : disabledExternalProp ,
195
194
disableIcon = false ,
@@ -261,38 +260,31 @@ const Checkbox = React.forwardRef(function Checkbox(inProps, ref) {
261
260
} ;
262
261
263
262
const classes = useUtilityClasses ( ownerState ) ;
263
+ const externalForwardedProps = { ...other , component } ;
264
264
265
- const rootProps = useSlotProps ( {
265
+ const [ SlotRoot , rootProps ] = useSlot ( 'root' , {
266
+ ref,
267
+ className : classes . root ,
266
268
elementType : CheckboxRoot ,
267
- externalSlotProps : componentsProps . root ,
268
- externalForwardedProps : other ,
269
+ externalForwardedProps,
269
270
ownerState,
270
- additionalProps : {
271
- ref,
272
- as : component ,
273
- } ,
274
- className : classes . root ,
275
271
} ) ;
276
272
277
- const checkboxProps = useSlotProps ( {
273
+ const [ SlotCheckbox , checkboxProps ] = useSlot ( 'checkbox' , {
274
+ className : classes . checkbox ,
278
275
elementType : CheckboxCheckbox ,
279
- externalSlotProps : componentsProps . checkbox ,
276
+ externalForwardedProps ,
280
277
ownerState,
281
- className : classes . checkbox ,
282
278
} ) ;
283
279
284
- const actionProps = useSlotProps ( {
280
+ const [ SlotAction , actionProps ] = useSlot ( 'action' , {
281
+ className : classes . action ,
285
282
elementType : CheckboxAction ,
286
- externalSlotProps : componentsProps . action ,
283
+ externalForwardedProps ,
287
284
ownerState,
288
- className : classes . action ,
289
285
} ) ;
290
286
291
- const inputProps = useSlotProps ( {
292
- elementType : CheckboxInput ,
293
- getSlotProps : getInputProps ,
294
- externalSlotProps : componentsProps . input ,
295
- ownerState,
287
+ const [ SlotInput , inputProps ] = useSlot ( 'input' , {
296
288
additionalProps : {
297
289
id,
298
290
name,
@@ -306,34 +298,38 @@ const Checkbox = React.forwardRef(function Checkbox(inProps, ref) {
306
298
} ) ,
307
299
} ,
308
300
className : classes . input ,
301
+ elementType : CheckboxInput ,
302
+ externalForwardedProps,
303
+ getSlotProps : getInputProps ,
304
+ ownerState,
309
305
} ) ;
310
306
311
- const labelProps = useSlotProps ( {
312
- elementType : CheckboxLabel ,
313
- externalSlotProps : componentsProps . label ,
314
- ownerState,
307
+ const [ SlotLabel , labelProps ] = useSlot ( 'label' , {
315
308
additionalProps : {
316
309
htmlFor : id ,
317
310
} ,
318
311
className : classes . label ,
312
+ elementType : CheckboxLabel ,
313
+ externalForwardedProps,
314
+ ownerState,
319
315
} ) ;
320
316
321
317
return (
322
- < CheckboxRoot { ...rootProps } >
323
- < CheckboxCheckbox { ...checkboxProps } >
324
- < CheckboxAction { ...actionProps } >
325
- < CheckboxInput { ...inputProps } />
326
- </ CheckboxAction >
318
+ < SlotRoot { ...rootProps } >
319
+ < SlotCheckbox { ...checkboxProps } >
320
+ < SlotAction { ...actionProps } >
321
+ < SlotInput { ...inputProps } />
322
+ </ SlotAction >
327
323
{ indeterminate && ! checked && ! disableIcon && indeterminateIcon }
328
324
{ checked && ! disableIcon && checkedIcon }
329
325
{ ! checked && ! disableIcon && ! indeterminate && uncheckedIcon }
330
- </ CheckboxCheckbox >
326
+ </ SlotCheckbox >
331
327
{ label && (
332
328
< TypographyContext . Provider value >
333
- < CheckboxLabel { ...labelProps } > { label } </ CheckboxLabel >
329
+ < SlotLabel { ...labelProps } > { label } </ SlotLabel >
334
330
</ TypographyContext . Provider >
335
331
) }
336
- </ CheckboxRoot >
332
+ </ SlotRoot >
337
333
) ;
338
334
} ) as OverridableComponent < CheckboxTypeMap > ;
339
335
@@ -376,7 +372,7 @@ Checkbox.propTypes /* remove-proptypes */ = {
376
372
* The props used for each slot inside the component.
377
373
* @default {}
378
374
*/
379
- componentsProps : PropTypes . shape ( {
375
+ slotProps : PropTypes . shape ( {
380
376
action : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
381
377
checkbox : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
382
378
input : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . object ] ) ,
0 commit comments