Skip to content

Commit 27d69b8

Browse files
committed
[SvgIcon] Remove classes prop and apply useSlot
1 parent c9f1d74 commit 27d69b8

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

packages/mui-joy/src/SvgIcon/SvgIcon.tsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import PropTypes from 'prop-types';
66
import * as React from 'react';
77
import styled from '../styles/styled';
88
import useThemeProps from '../styles/useThemeProps';
9+
import useSlot from '../utils/useSlot';
910
import { getSvgIconUtilityClass } from './svgIconClasses';
1011
import { SvgIconProps, SvgIconTypeMap, SvgIconOwnerState } from './SvgIconProps';
1112

1213
const useUtilityClasses = (ownerState: SvgIconOwnerState) => {
13-
const { color, fontSize, classes } = ownerState;
14+
const { color, fontSize } = ownerState;
1415

1516
const slots = {
1617
root: [
@@ -20,7 +21,7 @@ const useUtilityClasses = (ownerState: SvgIconOwnerState) => {
2021
],
2122
};
2223

23-
return composeClasses(slots, getSvgIconUtilityClass, classes);
24+
return composeClasses(slots, getSvgIconUtilityClass, {});
2425
};
2526

2627
const SvgIconRoot = styled('svg', {
@@ -86,22 +87,26 @@ const SvgIcon = React.forwardRef(function SvgIcon(inProps, ref) {
8687

8788
const classes = useUtilityClasses(ownerState);
8889

90+
const [SlotRoot, rootProps] = useSlot('root', {
91+
ref,
92+
className: clsx(classes.root, className),
93+
elementType: SvgIconRoot,
94+
externalForwardedProps: { ...other, component },
95+
ownerState,
96+
additionalProps: {
97+
color: htmlColor,
98+
focusable: 'false',
99+
...(titleAccess && { role: 'img' }),
100+
...(!titleAccess && { 'aria-hideen': true }),
101+
...(!inheritViewBox && { viewBox }),
102+
},
103+
});
104+
89105
return (
90-
<SvgIconRoot
91-
as={component}
92-
className={clsx(classes.root, className)}
93-
focusable="false"
94-
color={htmlColor}
95-
aria-hidden={titleAccess ? undefined : true}
96-
role={titleAccess ? 'img' : undefined}
97-
ref={ref}
98-
{...other}
99-
{...(!inheritViewBox && { viewBox })}
100-
ownerState={ownerState}
101-
>
106+
<SlotRoot {...rootProps}>
102107
{children}
103108
{titleAccess ? <title>{titleAccess}</title> : null}
104-
</SvgIconRoot>
109+
</SlotRoot>
105110
);
106111
}) as OverridableComponent<SvgIconTypeMap>;
107112

packages/mui-joy/src/SvgIcon/SvgIconProps.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { OverridableStringUnion, OverrideProps } from '@mui/types';
22
import * as React from 'react';
33
import { ColorPaletteProp, FontSize, SxProps, ApplyColorInversion } from '../styles/types';
4-
import { SvgIconClasses } from './svgIconClasses';
54

65
export type SvgIconSlot = 'root';
76

87
export interface SvgIconPropsSizeOverrides {}
9-
108
export interface SvgIconPropsColorOverrides {}
119

1210
export interface SvgIconTypeMap<P = {}, D extends React.ElementType = 'svg'> {
@@ -15,10 +13,6 @@ export interface SvgIconTypeMap<P = {}, D extends React.ElementType = 'svg'> {
1513
* Node passed into the SVG element.
1614
*/
1715
children?: React.ReactNode;
18-
/**
19-
* Override or extend the styles applied to the component.
20-
*/
21-
classes?: Partial<SvgIconClasses>;
2216
/**
2317
* The color of the component. It supports those theme colors that make sense for this component.
2418
* You can use the `htmlColor` prop to apply a color attribute to the SVG element.

0 commit comments

Comments
 (0)