Skip to content

Commit

Permalink
makes theme default props configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Mar 2, 2022
1 parent 9da7a6a commit 354b3a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/mui-joy/src/styles/CssVarsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import defaultTheme, {
import { DefaultColorScheme, ExtendedColorScheme } from './types/colorScheme';
import { Variants } from './types/variants';
import { ColorSystem } from './types/colorSystem';
import { TypographySystem } from './types/typography';
import { TypographySystem, FontSize } from './types/typography';
import { Components } from './components';
import { createVariant, createTextOverrides, createContainedOverrides } from './variantUtils';

Expand Down Expand Up @@ -64,22 +64,24 @@ const { CssVarsProvider, useColorScheme, getInitColorSchemeScript } = createCssV
components: {
// TODO: find a way to abstract SvgIcon out of @mui/material
MuiSvgIcon: {
// Note: do not specify default props here because it will break the adaptive component.
// To fix this we need to know if developer pass fontSize through `inProps` or not which is impossible right not in theming
// because `ownerState.fontSize` is the merged value by theme default props.
defaultProps: {
fontSize: 'xl',
},
styleOverrides: {
root: ({ ownerState, theme }) => {
const instanceFontSize = ownerState.instanceFontSize as 'inherit' | keyof FontSize;
return {
fontSize: `var(--Icon-fontSize, ${theme.fontSize.xl})`,
...(ownerState.fontSize &&
ownerState.fontSize !== 'inherit' && {
fontSize: `var(--Icon-fontSize, ${theme.fontSize[ownerState.fontSize]})`,
}),
...(ownerState.color &&
ownerState.color !== 'inherit' && {
color: theme.vars.palette[ownerState.color].textColor,
}),
...(ownerState.fontSize &&
// @ts-ignore
ownerState.fontSize !== 'medium' &&
ownerState.fontSize !== 'inherit' && {
'--Icon-fontSize': theme.vars.fontSize[ownerState.fontSize],
...(instanceFontSize &&
instanceFontSize !== 'inherit' && {
'--Icon-fontSize': theme.vars.fontSize[instanceFontSize],
}),
};
},
Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/SvgIcon/SvgIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const SvgIcon = React.forwardRef(function SvgIcon(inProps, ref) {
color,
component,
fontSize,
instanceFontSize: inProps.fontSize,
inheritViewBox,
viewBox,
};
Expand Down

0 comments on commit 354b3a1

Please sign in to comment.