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] Give same treatment to custom mixins as internal createMixins (as done with createTypography) #32721

Open
2 tasks done
maeertin opened this issue May 10, 2022 · 2 comments
Labels
new feature New feature or request package: system Specific to @mui/system

Comments

@maeertin
Copy link

maeertin commented May 10, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

export default function createMixins(breakpoints, spacing, mixins) {
  return {
    toolbar: {
      minHeight: 56,
      [`${breakpoints.up('xs')} and (orientation: landscape)`]: {
        minHeight: 48,
      },
      [breakpoints.up('sm')]: {
        minHeight: 64,
      },
    },
    ...(typeof mixins === 'function' ? mixins(breakpoints, spacing) : mixins),
  };
}

Update https://github.com/mui/material-ui/blob/master/packages/mui-material/src/styles/createMixins.js so that it forwards createMixins arguments to the "mixinsInput" if passed as a function to createTheme. Suggestion added above.

Examples 🌈

} = typeof typography === 'function' ? typography(palette) : typography;

createTypography is already set up in this this way.

Motivation 🔦

For the same reason that the internal mui createMixins has access to breakpoints/spacing, I think that theme creators should have the same possibilities when creating custom mixins.

For example:

const theme = createTheme({
  mixins: (breakpoints, spacing) => ({
    myCustomGuttersMixin: {
      paddingLeft: spacing(2),
      paddingRight: spacing(2),
      [breakpoints.up('sm')]: {
        paddingLeft: spacing(4),
        paddingRight: spacing(4),
      },
    }
  })
})
@maeertin maeertin added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 10, 2022
@mnajdova mnajdova added new feature New feature or request package: system Specific to @mui/system and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 17, 2022
@mnajdova
Copy link
Member

Looks like an interesting proposal. However, in order for creating a custom mixin, I would expect you may need more things from the theme (maybe the whole resolved theme actually). My proposal would be doing something like this: https://codesandbox.io/s/sweet-microservice-htiq4r?file=/src/App.tsx

You can also use the proposal from this section - https://mui.com/material-ui/customization/theming/#createtheme-options-args-theme for example using the second arg in createTheme, although for this scenario that you have the codesandbox example should be enough.

While doing the codesandbox, I noticed that we probably want to export the Mixins type from @mui/material/styles directly, so that developers don't need to know our internals.

@maeertin
Copy link
Author

maeertin commented May 20, 2022

Hi there :) That's actually what I'm currently doing but only needing breakpoints & spacing, but was worth a shot as a proposal. Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request package: system Specific to @mui/system
Projects
None yet
Development

No branches or pull requests

2 participants