11import * as React from 'react' ;
22import PropTypes from 'prop-types' ;
33import clsx from 'clsx' ;
4- import { unstable_extendSxProp as extendSxProp } from '@mui/system' ;
4+ import { getPath } from '@mui/system' ;
55import { unstable_composeClasses as composeClasses } from '@mui/base' ;
6- import styled from '../styles/styled' ;
6+ import styled , { rootShouldForwardProp } from '../styles/styled' ;
77import useThemeProps from '../styles/useThemeProps' ;
88import capitalize from '../utils/capitalize' ;
99import { getTypographyUtilityClass } from './typographyClasses' ;
@@ -28,6 +28,7 @@ const useUtilityClasses = (ownerState) => {
2828export const TypographyRoot = styled ( 'span' , {
2929 name : 'MuiTypography' ,
3030 slot : 'Root' ,
31+ shouldForwardProp : ( prop ) => rootShouldForwardProp ( prop ) && prop !== 'color' ,
3132 overridesResolver : ( props , styles ) => {
3233 const { ownerState } = props ;
3334
@@ -42,6 +43,7 @@ export const TypographyRoot = styled('span', {
4243 } ,
4344} ) ( ( { theme, ownerState } ) => ( {
4445 margin : 0 ,
46+ color : getPath ( theme , `palette.${ ownerState . color } ` , false ) || ownerState . color ,
4547 ...( ownerState . variant && theme . typography [ ownerState . variant ] ) ,
4648 ...( ownerState . align !== 'inherit' && {
4749 textAlign : ownerState . align ,
@@ -87,26 +89,27 @@ const transformDeprecatedColors = (color) => {
8789} ;
8890
8991const Typography = React . forwardRef ( function Typography ( inProps , ref ) {
90- const themeProps = useThemeProps ( { props : inProps , name : 'MuiTypography' } ) ;
91- const color = transformDeprecatedColors ( themeProps . color ) ;
92- const props = extendSxProp ( { ...themeProps , color } ) ;
92+ const props = useThemeProps ( { props : inProps , name : 'MuiTypography' } ) ;
9393
9494 const {
9595 align = 'inherit' ,
9696 className,
97+ // eslint-disable-next-line react/prop-types
98+ color,
9799 component,
98100 gutterBottom = false ,
99101 noWrap = false ,
100102 paragraph = false ,
101103 variant = 'body1' ,
102104 variantMapping = defaultVariantMapping ,
105+ sx,
103106 ...other
104107 } = props ;
105108
106109 const ownerState = {
107110 ...props ,
108111 align,
109- color,
112+ color : transformDeprecatedColors ( color ) ,
110113 className,
111114 component,
112115 gutterBottom,
@@ -129,6 +132,11 @@ const Typography = React.forwardRef(function Typography(inProps, ref) {
129132 ref = { ref }
130133 ownerState = { ownerState }
131134 className = { clsx ( classes . root , className ) }
135+ color = { color }
136+ sx = { [
137+ ...( ! Object . keys ( colorTransformations ) . includes ( color ) ? [ { color } ] : [ ] ) ,
138+ ...( Array . isArray ( sx ) ? sx : [ sx ] ) ,
139+ ] }
132140 { ...other }
133141 />
134142 ) ;
0 commit comments