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

[theme] Add theme.mixins.gutters() in adaptV4Theme #22396

Merged
merged 2 commits into from Aug 30, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 15 additions & 22 deletions docs/src/pages/guides/migration-v4/migration-v4.md
Expand Up @@ -53,6 +53,21 @@ This change affects almost all components where you're using the `component` pro

### Theme

For a smoother transition, the `adaptV4Theme` helper allows you to iteratively upgrade to the new theme structure.

```diff
-import { createMuiTheme } from '@material-ui/core/styles';
+import { createMuiTheme, adaptV4Theme } from '@material-ui/core/styles';

-const theme = createMuitheme({
+const theme = createMuitheme(adaptV4Theme({
// v4 theme
-});
+}));
```

#### Changes

- The "gutters" abstraction hasn't proven to be used frequently enough to be valuable.

```diff
Expand Down Expand Up @@ -109,28 +124,6 @@ const theme = createMuitheme({
});
```

For a smoother transition, the `adaptV4Theme` helper allows you to iteratively upgrade to the new theme structure. Note that it will display a deprecation warning in the console, since it will be removed at the next major release.

```diff
-import { createMuiTheme } from '@material-ui/core/styles';
+import { createMuiTheme, adaptV4Theme } from '@material-ui/core/styles';

-const theme = createMuitheme({
+const theme = createMuitheme(adaptV4Theme({
props: {
MuiButton: {
disableRipple: true,
},
},
overrides: {
MuiButton: {
root: { padding: 0 },
},
},
-});
+}));
```

### Avatar

- Rename `circle` to `circular` for consistency. The possible values should be adjectives, not nouns:
Expand Down
24 changes: 24 additions & 0 deletions packages/material-ui/src/styles/adaptV4Theme.js
@@ -1,3 +1,6 @@
import createBreakpoints from './createBreakpoints';
import createSpacing from './createSpacing';

export default function adaptV4Theme(inputTheme) {
if (process.env.NODE_ENV !== 'production') {
console.warn(
Expand All @@ -13,6 +16,7 @@ export default function adaptV4Theme(inputTheme) {
defaultProps = {},
styleOverrides = {},
overrides = {},
mixins = {},
...other
} = inputTheme;
const theme = {
Expand Down Expand Up @@ -46,5 +50,25 @@ export default function adaptV4Theme(inputTheme) {
theme.components[component] = componentValue;
});

// theme.mixins.gutters
const breakpoints = createBreakpoints(inputTheme.breakpoints || {});
const spacing = createSpacing(inputTheme.spacing);

theme.mixins = {
gutters: (styles = {}) => {
return {
paddingLeft: spacing(2),
paddingRight: spacing(2),
...styles,
[breakpoints.up('sm')]: {
paddingLeft: spacing(3),
paddingRight: spacing(3),
...styles[breakpoints.up('sm')],
},
};
},
...mixins,
};

return theme;
}