1- import * as React from 'react' ;
2- import clsx from 'clsx' ;
3- import PropTypes from 'prop-types' ;
41import { unstable_composeClasses as composeClasses , useButton } from '@mui/base' ;
5- import { useSlotProps } from '@mui/base/utils' ;
62import { OverridableComponent } from '@mui/types' ;
73import { unstable_capitalize as capitalize , unstable_useId as useId } from '@mui/utils' ;
4+ import clsx from 'clsx' ;
5+ import PropTypes from 'prop-types' ;
6+ import * as React from 'react' ;
87import { useThemeProps } from '../styles' ;
98import styled from '../styles/styled' ;
9+ import useSlot from '../utils/useSlot' ;
1010import chipClasses , { getChipUtilityClass } from './chipClasses' ;
11- import { ChipProps , ChipOwnerState , ChipTypeMap } from './ChipProps' ;
1211import ChipContext from './ChipContext' ;
12+ import { ChipOwnerState , ChipProps , ChipTypeMap } from './ChipProps' ;
1313
1414const useUtilityClasses = ( ownerState : ChipOwnerState ) => {
1515 const { disabled, size, color, clickable, variant, focusVisible } = ownerState ;
@@ -203,7 +203,6 @@ const Chip = React.forwardRef(function Chip(inProps, ref) {
203203 className,
204204 componentsProps = { } ,
205205 color = 'primary' ,
206- component,
207206 onClick,
208207 disabled = false ,
209208 size = 'md' ,
@@ -216,7 +215,6 @@ const Chip = React.forwardRef(function Chip(inProps, ref) {
216215 const clickable = ! ! onClick || ! ! componentsProps . action ;
217216 const ownerState : ChipOwnerState = {
218217 ...props ,
219- component,
220218 disabled,
221219 size,
222220 color,
@@ -240,41 +238,49 @@ const Chip = React.forwardRef(function Chip(inProps, ref) {
240238
241239 const classes = useUtilityClasses ( ownerState ) ;
242240
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 } ,
246246 ownerState,
247+ } ) ;
248+
249+ const [ SlotLabel , labelProps ] = useSlot ( 'label' , {
247250 className : classes . label ,
251+ elementType : ChipLabel ,
252+ externalForwardedProps : { ...other , componentsProps } ,
253+ ownerState,
248254 } ) ;
249255
250256 // @ts -ignore internal logic.
251257 const id = useId ( labelProps . id ) ;
252258
253- const actionProps = useSlotProps ( {
259+ const [ SlotAction , actionProps ] = useSlot ( 'action' , {
260+ className : classes . action ,
254261 elementType : ChipAction ,
262+ externalForwardedProps : { ...other , componentsProps } ,
263+ ownerState,
255264 getSlotProps : getRootProps ,
256- externalSlotProps : componentsProps . action ,
257265 additionalProps : {
258266 'aria-labelledby' : id ,
259267 as : resolvedActionProps ?. component ,
260268 onClick,
261269 } ,
262- ownerState,
263- className : classes . action ,
264270 } ) ;
265271
266- const startDecoratorProps = useSlotProps ( {
272+ const [ SlotStartDecorator , startDecoratorProps ] = useSlot ( 'startDecorator' , {
273+ className : classes . startDecorator ,
267274 elementType : ChipStartDecorator ,
268- externalSlotProps : componentsProps . startDecorator ,
275+ externalForwardedProps : { ... other , componentsProps } ,
269276 ownerState,
270- className : classes . startDecorator ,
271277 } ) ;
272278
273- const endDecoratorProps = useSlotProps ( {
279+ const [ SlotEndDecorator , endDecoratorProps ] = useSlot ( 'startDecorator' , {
280+ className : classes . startDecorator ,
274281 elementType : ChipEndDecorator ,
275- externalSlotProps : componentsProps . endDecorator ,
282+ externalForwardedProps : { ... other , componentsProps } ,
276283 ownerState,
277- className : classes . endDecorator ,
278284 } ) ;
279285
280286 const chipContextValue = React . useMemo (
@@ -284,25 +290,19 @@ const Chip = React.forwardRef(function Chip(inProps, ref) {
284290
285291 return (
286292 < 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 } /> }
295295
296296 { /* 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 } >
298298 { children }
299- </ ChipLabel >
299+ </ SlotLabel >
300300 { startDecorator && (
301- < ChipStartDecorator { ...startDecoratorProps } > { startDecorator } </ ChipStartDecorator >
301+ < SlotStartDecorator { ...startDecoratorProps } > { startDecorator } </ SlotStartDecorator >
302302 ) }
303303
304- { endDecorator && < ChipEndDecorator { ...endDecoratorProps } > { endDecorator } </ ChipEndDecorator > }
305- </ ChipRoot >
304+ { endDecorator && < SlotEndDecorator { ...endDecoratorProps } > { endDecorator } </ SlotEndDecorator > }
305+ </ SlotRoot >
306306 </ ChipContext . Provider >
307307 ) ;
308308} ) as OverridableComponent < ChipTypeMap > ;
0 commit comments