Skip to content

Commit 4dda393

Browse files
ZeeshanTamboliweb-flow
authored andcommitted
[theme] Generate color-mix value on top of default generated Material UI CSS variables (#47767)
1 parent f5572c0 commit 4dda393

2 files changed

Lines changed: 449 additions & 61 deletions

File tree

packages/mui-material/src/styles/createTheme.test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { expect } from 'chai';
2-
import { createRenderer, isJsdom } from '@mui/internal-test-utils';
2+
import { createRenderer, isJsdom, screen } from '@mui/internal-test-utils';
33
import {
44
alpha as systemAlpha,
55
lighten as systemLighten,
66
darken as systemDarken,
77
} from '@mui/system/colorManipulator';
88
import Button from '@mui/material/Button';
9+
import Alert from '@mui/material/Alert';
910
import Box from '@mui/material/Box';
11+
import GlobalStyles from '@mui/material/GlobalStyles';
1012
import { ThemeProvider, createTheme, styled } from '@mui/material/styles';
1113
import { deepOrange, green, grey } from '@mui/material/colors';
1214
import createPalette from './createPalette';
@@ -782,4 +784,42 @@ describe('createTheme', () => {
782784
);
783785
});
784786
});
787+
788+
// Skip WebKit and firefox because they have a slightly different value
789+
it.skipIf(isJSDOM || !/chrome/.test(window.navigator.userAgent))(
790+
'should build color-mix() on top of generated Material UI CSS variables',
791+
() => {
792+
function App() {
793+
const theme = createTheme({
794+
cssVariables: {
795+
nativeColor: true,
796+
},
797+
});
798+
799+
return (
800+
<ThemeProvider theme={theme}>
801+
{/* This is just to replicate the global CSS file */}
802+
<GlobalStyles
803+
styles={{
804+
':root': {
805+
'--mui-palette-info-main': '#d3b613 !important', // !important is to take precedence over the default one. This is just for test, in real world case global CSS file should be used.
806+
'--mui-palette-info-light': '#dfc21f !important',
807+
},
808+
}}
809+
/>
810+
811+
<Alert variant="standard" severity="info" data-testid="alert">
812+
Alert
813+
</Alert>
814+
</ThemeProvider>
815+
);
816+
}
817+
818+
render(<App />);
819+
820+
expect(screen.getByTestId('alert')).toHaveComputedStyle({
821+
backgroundColor: 'oklch(0.981465 0.01628 97.7526)', // browser converts color-mix to oklch in window.getComputedStyle()
822+
});
823+
},
824+
);
785825
});

0 commit comments

Comments
 (0)