Skip to content

Commit ff7c109

Browse files
authored
[CssBaseline] Fix typings for @global override (#20454)
1 parent 427a4d1 commit ff7c109

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

packages/material-ui/src/CssBaseline/CssBaseline.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export interface CssBaselineProps {
1616
*/
1717
declare const CssBaseline: React.ComponentType<CssBaselineProps>;
1818

19+
/**
20+
* @deprecated The name of this type is misleading. `CssBaseline` implements no class at all.
21+
*/
1922
export type CssBaselineClassKey = '@global';
2023

2124
export default CssBaseline;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { createMuiTheme } from '@material-ui/core';
2+
3+
// overrides story
4+
{
5+
// reduced example from
6+
// https://github.com/mui-org/material-ui/blob/master/docs/src/pages/customization/typography/typography.md
7+
createMuiTheme({
8+
overrides: {
9+
MuiCssBaseline: {
10+
'@global': {
11+
'@font-face': [{ fontFamily: 'custom', fontWeight: 600 }],
12+
},
13+
},
14+
},
15+
});
16+
// assuming "@global" is a class
17+
createMuiTheme({
18+
overrides: {
19+
MuiCssBaseline: {
20+
'@global': {
21+
// $ExpectError
22+
fontWeight: 'bold',
23+
},
24+
},
25+
},
26+
});
27+
// reset.css
28+
createMuiTheme({
29+
overrides: {
30+
MuiCssBaseline: {
31+
'@global': {
32+
ul: {
33+
'list-style': 'none',
34+
},
35+
p: {
36+
fontWeight: 'bolde', // undesired, should throw
37+
},
38+
},
39+
},
40+
},
41+
});
42+
}

packages/material-ui/src/styles/overrides.d.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { StyleRules } from './withStyles';
2-
1+
import { CSSProperties, StyleRules } from './withStyles';
32
import { AppBarClassKey } from '../AppBar';
43
import { AvatarClassKey } from '../Avatar';
54
import { BackdropClassKey } from '../Backdrop';
@@ -21,7 +20,6 @@ import { ChipClassKey } from '../Chip';
2120
import { CircularProgressClassKey } from '../CircularProgress';
2221
import { CollapseClassKey } from '../Collapse';
2322
import { ContainerClassKey } from '../Container';
24-
import { CssBaselineClassKey } from '../CssBaseline';
2523
import { DialogActionsClassKey } from '../DialogActions';
2624
import { DialogClassKey } from '../Dialog';
2725
import { DialogContentClassKey } from '../DialogContent';
@@ -100,6 +98,12 @@ import { TypographyClassKey } from '../Typography';
10098

10199
export type Overrides = {
102100
[Name in keyof ComponentNameToClassKey]?: Partial<StyleRules<ComponentNameToClassKey[Name]>>;
101+
} & {
102+
MuiCssBaseline?: {
103+
'@global'?: {
104+
'@font-face'?: CSSProperties['@font-face'];
105+
} & Record<string, CSSProperties['@font-face'] | CSSProperties>; // allow arbitrary selectors
106+
};
103107
};
104108

105109
export interface ComponentNameToClassKey {
@@ -124,7 +128,10 @@ export interface ComponentNameToClassKey {
124128
MuiCircularProgress: CircularProgressClassKey;
125129
MuiCollapse: CollapseClassKey;
126130
MuiContainer: ContainerClassKey;
127-
MuiCssBaseline: CssBaselineClassKey;
131+
/**
132+
* @deprecated See CssBaseline.d.ts
133+
*/
134+
MuiCssBaseline: '@global';
128135
MuiDialog: DialogClassKey;
129136
MuiDialogActions: DialogActionsClassKey;
130137
MuiDialogContent: DialogContentClassKey;

0 commit comments

Comments
 (0)