Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CssBaseline] Fix typings for @global override #20454

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/material-ui/src/CssBaseline/CssBaseline.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export interface CssBaselineProps {
*/
declare const CssBaseline: React.ComponentType<CssBaselineProps>;

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

export default CssBaseline;
42 changes: 42 additions & 0 deletions packages/material-ui/src/CssBaseline/CssBaseline.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { createMuiTheme } from '@material-ui/core';

// overrides story
{
// reduced example from
// https://github.com/mui-org/material-ui/blob/master/docs/src/pages/customization/typography/typography.md
createMuiTheme({
overrides: {
MuiCssBaseline: {
'@global': {
'@font-face': [{ fontFamily: 'custom', fontWeight: 600 }],
},
},
},
});
// assuming "@global" is a class
createMuiTheme({
overrides: {
MuiCssBaseline: {
'@global': {
// $ExpectError
fontWeight: 'bold',
},
},
},
});
// reset.css
createMuiTheme({
overrides: {
MuiCssBaseline: {
'@global': {
ul: {
'list-style': 'none',
},
p: {
fontWeight: 'bolde', // undesired, should throw
},
},
},
},
});
}
15 changes: 11 additions & 4 deletions packages/material-ui/src/styles/overrides.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { StyleRules } from './withStyles';

import { CSSProperties, StyleRules } from './withStyles';
import { AppBarClassKey } from '../AppBar';
import { AvatarClassKey } from '../Avatar';
import { BackdropClassKey } from '../Backdrop';
Expand All @@ -21,7 +20,6 @@ import { ChipClassKey } from '../Chip';
import { CircularProgressClassKey } from '../CircularProgress';
import { CollapseClassKey } from '../Collapse';
import { ContainerClassKey } from '../Container';
import { CssBaselineClassKey } from '../CssBaseline';
import { DialogActionsClassKey } from '../DialogActions';
import { DialogClassKey } from '../Dialog';
import { DialogContentClassKey } from '../DialogContent';
Expand Down Expand Up @@ -100,6 +98,12 @@ import { TypographyClassKey } from '../Typography';

export type Overrides = {
[Name in keyof ComponentNameToClassKey]?: Partial<StyleRules<ComponentNameToClassKey[Name]>>;
} & {
MuiCssBaseline?: {
'@global'?: {
'@font-face'?: CSSProperties['@font-face'];
} & Record<string, CSSProperties['@font-face'] | CSSProperties>; // allow arbitrary selectors
};
};

export interface ComponentNameToClassKey {
Expand All @@ -124,7 +128,10 @@ export interface ComponentNameToClassKey {
MuiCircularProgress: CircularProgressClassKey;
MuiCollapse: CollapseClassKey;
MuiContainer: ContainerClassKey;
MuiCssBaseline: CssBaselineClassKey;
/**
* @deprecated See CssBaseline.d.ts
*/
MuiCssBaseline: '@global';
MuiDialog: DialogClassKey;
MuiDialogActions: DialogActionsClassKey;
MuiDialogContent: DialogContentClassKey;
Expand Down