Skip to content

Commit

Permalink
[CssBaseline] Fix typings for @global override
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 7, 2020
1 parent 797e738 commit 091d169
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
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

0 comments on commit 091d169

Please sign in to comment.