@@ -2,14 +2,14 @@ import * as React from 'react';
2
2
import clsx from 'clsx' ;
3
3
import PropTypes from 'prop-types' ;
4
4
import { unstable_composeClasses as composeClasses , useButton } from '@mui/base' ;
5
- import { useSlotProps } from '@mui/base/utils' ;
6
5
import { OverridableComponent } from '@mui/types' ;
7
6
import { unstable_capitalize as capitalize , unstable_useId as useId } from '@mui/utils' ;
8
7
import { useThemeProps } from '../styles' ;
9
8
import styled from '../styles/styled' ;
10
9
import chipClasses , { getChipUtilityClass } from './chipClasses' ;
11
10
import { ChipProps , ChipOwnerState , ChipTypeMap } from './ChipProps' ;
12
11
import ChipContext from './ChipContext' ;
12
+ import useSlot from '../utils/useSlot' ;
13
13
14
14
const useUtilityClasses = ( ownerState : ChipOwnerState ) => {
15
15
const { disabled, size, color, clickable, variant, focusVisible } = ownerState ;
@@ -203,7 +203,6 @@ const Chip = React.forwardRef(function Chip(inProps, ref) {
203
203
className,
204
204
componentsProps = { } ,
205
205
color = 'primary' ,
206
- component,
207
206
onClick,
208
207
disabled = false ,
209
208
size = 'md' ,
@@ -216,7 +215,6 @@ const Chip = React.forwardRef(function Chip(inProps, ref) {
216
215
const clickable = ! ! onClick || ! ! componentsProps . action ;
217
216
const ownerState : ChipOwnerState = {
218
217
...props ,
219
- component,
220
218
disabled,
221
219
size,
222
220
color,
@@ -240,41 +238,49 @@ const Chip = React.forwardRef(function Chip(inProps, ref) {
240
238
241
239
const classes = useUtilityClasses ( ownerState ) ;
242
240
243
- const labelProps = useSlotProps ( {
244
- elementType : ChipLabel ,
245
- externalSlotProps : componentsProps . label ,
241
+ const [ SlotRoot , rootProps ] = useSlot ( 'root' , {
242
+ ref,
243
+ className : clsx ( classes . root , className ) ,
244
+ elementType : ChipRoot ,
245
+ externalForwardedProps : { ...other , componentsProps } ,
246
246
ownerState,
247
+ } ) ;
248
+
249
+ const [ SlotLabel , labelProps ] = useSlot ( 'label' , {
247
250
className : classes . label ,
251
+ elementType : ChipLabel ,
252
+ externalForwardedProps : { ...other , componentsProps } ,
253
+ ownerState,
248
254
} ) ;
249
255
250
256
// @ts -ignore internal logic.
251
257
const id = useId ( labelProps . id ) ;
252
258
253
- const actionProps = useSlotProps ( {
259
+ const [ SlotAction , actionProps ] = useSlot ( 'action' , {
260
+ className : classes . action ,
254
261
elementType : ChipAction ,
262
+ externalForwardedProps : { ...other , componentsProps } ,
263
+ ownerState,
255
264
getSlotProps : getRootProps ,
256
- externalSlotProps : componentsProps . action ,
257
265
additionalProps : {
258
266
'aria-labelledby' : id ,
259
267
as : resolvedActionProps ?. component ,
260
268
onClick,
261
269
} ,
262
- ownerState,
263
- className : classes . action ,
264
270
} ) ;
265
271
266
- const startDecoratorProps = useSlotProps ( {
272
+ const [ SlotStartDecorator , startDecoratorProps ] = useSlot ( 'startDecorator' , {
273
+ className : classes . startDecorator ,
267
274
elementType : ChipStartDecorator ,
268
- externalSlotProps : componentsProps . startDecorator ,
275
+ externalForwardedProps : { ... other , componentsProps } ,
269
276
ownerState,
270
- className : classes . startDecorator ,
271
277
} ) ;
272
278
273
- const endDecoratorProps = useSlotProps ( {
279
+ const [ SlotEndDecorator , endDecoratorProps ] = useSlot ( 'startDecorator' , {
280
+ className : classes . startDecorator ,
274
281
elementType : ChipEndDecorator ,
275
- externalSlotProps : componentsProps . endDecorator ,
282
+ externalForwardedProps : { ... other , componentsProps } ,
276
283
ownerState,
277
- className : classes . endDecorator ,
278
284
} ) ;
279
285
280
286
const chipContextValue = React . useMemo (
@@ -284,25 +290,19 @@ const Chip = React.forwardRef(function Chip(inProps, ref) {
284
290
285
291
return (
286
292
< ChipContext . Provider value = { chipContextValue } >
287
- < ChipRoot
288
- as = { component }
289
- className = { clsx ( classes . root , className ) }
290
- ref = { ref }
291
- ownerState = { ownerState }
292
- { ...other }
293
- >
294
- { clickable && < ChipAction { ...actionProps } /> }
293
+ < SlotRoot { ...rootProps } >
294
+ { clickable && < SlotAction { ...actionProps } /> }
295
295
296
296
{ /* label is always the first element for integrating with other controls, eg. Checkbox, Radio. Use CSS order to rearrange position */ }
297
- < ChipLabel { ...labelProps } id = { id } >
297
+ < SlotLabel { ...labelProps } id = { id } >
298
298
{ children }
299
- </ ChipLabel >
299
+ </ SlotLabel >
300
300
{ startDecorator && (
301
- < ChipStartDecorator { ...startDecoratorProps } > { startDecorator } </ ChipStartDecorator >
301
+ < SlotStartDecorator { ...startDecoratorProps } > { startDecorator } </ SlotStartDecorator >
302
302
) }
303
303
304
- { endDecorator && < ChipEndDecorator { ...endDecoratorProps } > { endDecorator } </ ChipEndDecorator > }
305
- </ ChipRoot >
304
+ { endDecorator && < SlotEndDecorator { ...endDecoratorProps } > { endDecorator } </ SlotEndDecorator > }
305
+ </ SlotRoot >
306
306
</ ChipContext . Provider >
307
307
) ;
308
308
} ) as OverridableComponent < ChipTypeMap > ;
0 commit comments