Skip to content

Commit

Permalink
[theme] Add theme.mixins.gutters() in adaptV4Theme (mui#22396)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnajdova authored Aug 30, 2020
1 parent 7c29035 commit a8acbad
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 159 deletions.
37 changes: 15 additions & 22 deletions docs/src/pages/guides/migration-v4/migration-v4.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit a8acbad

Please sign in to comment.