Replace theme spacing only on overrides
Co-authored-by: Patrik Oldsberg <poldsberg@gmail.com> Signed-off-by: Philipp Hugenroth <philipph@spotify.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/theme': patch
|
||||
---
|
||||
|
||||
Applying the modified `theme.spacing` method only to overrides instead of replacing it in the whole theme.
|
||||
@@ -77,16 +77,17 @@ function adaptV5Override(
|
||||
return undefined;
|
||||
}
|
||||
if (typeof overrides === 'object') {
|
||||
const _theme = { ...theme };
|
||||
const defaultSpacing = theme.spacing(1);
|
||||
if (typeof defaultSpacing === 'number') {
|
||||
// Override potential v4 spacing method: https://mui.com/material-ui/migration/v5-style-changes/#%E2%9C%85-remove-px-suffix
|
||||
// `adaptV4Theme as reference: https://github.com/mui/material-ui/blob/v5.x/packages/mui-material/src/styles/adaptV4Theme.js#L54C41-L54C41
|
||||
_theme.spacing = __v5Spacing(defaultSpacing);
|
||||
}
|
||||
return Object.fromEntries(
|
||||
Object.entries(overrides).map(([className, style]) => {
|
||||
if (typeof style === 'function') {
|
||||
const defaultSpacing = theme.spacing(1);
|
||||
if (typeof defaultSpacing === 'number') {
|
||||
// Override potential v4 spacing method: https://mui.com/material-ui/migration/v5-style-changes/#%E2%9C%85-remove-px-suffix
|
||||
// `adaptV4Theme as reference: https://github.com/mui/material-ui/blob/v5.x/packages/mui-material/src/styles/adaptV4Theme.js#L54C41-L54C41
|
||||
theme.spacing = __v5Spacing(defaultSpacing);
|
||||
}
|
||||
return [className, style({ theme })];
|
||||
return [className, style({ theme: _theme })];
|
||||
}
|
||||
return [className, style];
|
||||
}),
|
||||
|
||||
@@ -189,12 +189,12 @@ export const defaultComponentThemes: ThemeOptions['components'] = {
|
||||
color: theme.palette.grey[500],
|
||||
width: theme.spacing(3),
|
||||
height: theme.spacing(3),
|
||||
margin: `0 ${theme.spacing(0.75)} 0 -${theme.spacing(0.75)}`,
|
||||
margin: theme.spacing(0, 0.75, 0, -0.75),
|
||||
}),
|
||||
deleteIconSmall: ({ theme }) => ({
|
||||
width: theme.spacing(2),
|
||||
height: theme.spacing(2),
|
||||
margin: `0 ${theme.spacing(0.5)} 0 -${theme.spacing(0.5)}`,
|
||||
margin: theme.spacing(0, 0.5, 0, -0.5),
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user