Skip to content

Commit ba16789

Browse files
committed
Update our usage of theme variables to support all MUI versions
1 parent fcd1359 commit ba16789

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+237
-139
lines changed

examples/demo/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const store = localStorageStore(undefined, 'ECommerce');
4343

4444
const App = () => {
4545
const [themeName] = useStore<ThemeName>('themeName', 'soft');
46+
const singleTheme = themes.find(theme => theme.name === themeName)?.single;
4647
const lightTheme = themes.find(theme => theme.name === themeName)?.light;
4748
const darkTheme = themes.find(theme => theme.name === themeName)?.dark;
4849
return (
@@ -58,6 +59,7 @@ const App = () => {
5859
layout={Layout}
5960
i18nProvider={i18nProvider}
6061
disableTelemetry
62+
theme={singleTheme}
6163
lightTheme={lightTheme}
6264
darkTheme={darkTheme}
6365
defaultTheme="light"

examples/demo/src/layout/Layout.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import AppBar from './AppBar';
44
import Menu from './Menu';
55

66
export default ({ children }: { children: React.ReactNode }) => (
7-
<Layout appBar={AppBar} menu={Menu}>
7+
<Layout
8+
appBar={AppBar}
9+
menu={Menu}
10+
sx={{
11+
backgroundColor: theme =>
12+
(theme.vars || theme).palette.background.default,
13+
}}
14+
>
815
{children}
916
</Layout>
1017
);

examples/demo/src/mui.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type {} from '@mui/material/themeCssVarsAugmentation';
2+
3+
declare module '@mui/material/styles' {
4+
interface PaletteOptions {
5+
bulkActionsToolbarColor?: string;
6+
bulkActionsToolbarBackgroundColor?: string;
7+
}
8+
interface Palette {
9+
bulkActionsToolbarColor: string;
10+
bulkActionsToolbarBackgroundColor: string;
11+
}
12+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { createTheme, lighten } from '@mui/material';
2+
import { RaThemeOptions } from 'react-admin';
3+
4+
const defaultTheme = createTheme();
5+
const lightTheme: RaThemeOptions = {
6+
palette: {
7+
mode: 'light',
8+
bulkActionsToolbarBackgroundColor: lighten(
9+
defaultTheme.palette.primary.light,
10+
0.8
11+
),
12+
},
13+
};
14+
const darkTheme: RaThemeOptions = {
15+
palette: {
16+
mode: 'dark',
17+
bulkActionsToolbarBackgroundColor: defaultTheme.palette.primary.dark,
18+
},
19+
};
20+
21+
export const cssVariablesTheme = createTheme({
22+
cssVariables: true,
23+
defaultColorScheme: 'light',
24+
colorSchemes: {
25+
light: lightTheme,
26+
dark: darkTheme,
27+
},
28+
});

examples/demo/src/themes/themes.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414

1515
import { softDarkTheme, softLightTheme } from './softTheme';
1616
import { chiptuneTheme } from './chiptuneTheme';
17+
import { cssVariablesTheme } from './cssVariablesTheme';
1718

1819
export type ThemeName =
1920
| 'soft'
@@ -22,13 +23,15 @@ export type ThemeName =
2223
| 'nano'
2324
| 'radiant'
2425
| 'house'
25-
| 'chiptune';
26+
| 'chiptune'
27+
| 'cssVariables';
2628

27-
export interface Theme {
29+
export type Theme = {
2830
name: ThemeName;
29-
light: RaThemeOptions;
31+
light?: RaThemeOptions;
3032
dark?: RaThemeOptions;
31-
}
33+
single?: RaThemeOptions;
34+
};
3235

3336
const BW_SIDEBAR_OVERRIDE = {
3437
styleOverrides: {
@@ -45,6 +48,10 @@ const BW_SIDEBAR_OVERRIDE = {
4548

4649
export const themes: Theme[] = [
4750
{ name: 'soft', light: softLightTheme, dark: softDarkTheme },
51+
{
52+
name: 'cssVariables',
53+
single: cssVariablesTheme,
54+
},
4855
{ name: 'default', light: defaultLightTheme, dark: defaultDarkTheme },
4956
{
5057
name: 'B&W',

packages/ra-input-rich-text/src/RichTextInput.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,26 +225,25 @@ const Root = styled('div', {
225225
[`& .${classes.editorContent}`]: {
226226
width: '100%',
227227
'& .ProseMirror': {
228-
backgroundColor: theme.palette.background.default,
229-
borderColor:
230-
theme.palette.mode === 'light'
231-
? 'rgba(0, 0, 0, 0.23)'
232-
: 'rgba(255, 255, 255, 0.23)',
228+
backgroundColor: (theme.vars || theme).palette.background.default,
229+
borderColor: (theme.vars || theme).palette.divider,
233230
borderRadius: theme.shape.borderRadius,
234231
borderStyle: 'solid',
235232
borderWidth: '1px',
236233
padding: theme.spacing(1),
237234

238235
'&[contenteditable="false"], &[contenteditable="false"]:hover, &[contenteditable="false"]:focus':
239236
{
240-
backgroundColor: theme.palette.action.disabledBackground,
237+
backgroundColor: (theme.vars || theme).palette.action
238+
.disabledBackground,
241239
},
242240

243241
'&:hover': {
244-
backgroundColor: theme.palette.action.hover,
242+
backgroundColor: (theme.vars || theme).palette.action.hover,
245243
},
246244
'&:focus': {
247-
backgroundColor: theme.palette.background.default,
245+
backgroundColor: (theme.vars || theme).palette.background
246+
.default,
248247
},
249248
'& p': {
250249
margin: '0 0 1em 0',

packages/ra-input-rich-text/src/buttons/LevelSelect.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Menu,
99
MenuItem,
1010
} from '@mui/material';
11-
import { styled, alpha } from '@mui/material/styles';
11+
import { styled } from '@mui/material/styles';
1212
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
1313
import { useTranslate } from 'ra-core';
1414
import clsx from 'clsx';
@@ -213,7 +213,7 @@ const classes = {
213213
const Root = styled('div')(({ theme }) => ({
214214
[`&.${classes.list}`]: {
215215
borderRadius: theme.shape.borderRadius,
216-
border: `1px solid ${alpha(theme.palette.action.active, 0.12)}`,
216+
border: `1px solid color-mix(in srgb, ${(theme.vars || theme).palette.action.active}, transparent 12%) solid 2px`,
217217
},
218218
[`& .${classes.sizeSmall}`]: {
219219
paddingTop: 1,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type {} from '@mui/material/themeCssVarsAugmentation';
2+
3+
declare module '@mui/material/styles' {
4+
interface PaletteOptions {
5+
bulkActionsToolbarColor?: string;
6+
bulkActionsToolbarBackgroundColor?: string;
7+
}
8+
interface Palette {
9+
bulkActionsToolbarColor: string;
10+
bulkActionsToolbarBackgroundColor: string;
11+
}
12+
}

packages/ra-no-code/src/ApplicationsDashboard/ApplicationsDashboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const StyledContainer = styled(Container)(({ theme }) => ({
4343
},
4444

4545
[`& .${classes.title}`]: {
46-
color: theme.palette.common.white,
46+
color: (theme.vars || theme).palette.common.white,
4747
marginBottom: theme.spacing(4),
4848
textAlign: 'center',
4949
},

packages/ra-no-code/src/ResourceConfiguration/ResourceConfiguration.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ const StyledCard = styled(Card)(({ theme }) => ({
163163
},
164164

165165
[`& .${classes.fieldList}`]: {
166-
backgroundColor: theme.palette.background.default,
166+
backgroundColor: (theme.vars || theme).palette.background.default,
167167
},
168168

169169
[`& .${classes.fieldTitle}`]: {
@@ -180,6 +180,6 @@ const StyledCard = styled(Card)(({ theme }) => ({
180180
},
181181

182182
[`& .${classes.actions}`]: {
183-
backgroundColor: theme.palette.background.default,
183+
backgroundColor: (theme.vars || theme).palette.background.default,
184184
},
185185
}));

0 commit comments

Comments
 (0)