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

[docs] do slots in styleOverrides always support callbacks? #44293

Closed
GBvanDam opened this issue Nov 2, 2024 · 3 comments
Closed

[docs] do slots in styleOverrides always support callbacks? #44293

GBvanDam opened this issue Nov 2, 2024 · 3 comments
Assignees
Labels
customization: theme Centered around the theming features docs Improvements or additions to the documentation support: docs-feedback Feedback from documentation page

Comments

@GBvanDam
Copy link

GBvanDam commented Nov 2, 2024

Related page

https://mui.com/material-ui/customization/theme-components/#theme-style-overrides

Kind of issue

Missing information

Issue description

https://mui.com/material-ui/customization/theme-components/#theme-style-overrides is not saying anything about the support for callbacks on a slot in styleOverrides.

https://mui.com/material-ui/customization/theme-components/#the-sx-syntax-experimental not only introduced me to the experimental sx syntax (great one!), but also introduced me to using callbacks inside of slots in styleOverrides.

my use-case would be something like this:

const finalTheme = createTheme({
  components: {
    MuiChip: {
      styleOverrides: {
        icon: ({ theme }) => ({
          color: theme.vars.palette.primary.main
        })
      },
    },
  },
});

If this is possible, I would suggest https://mui.com/material-ui/customization/theme-components/#theme-style-overrides to tell about it! The same applies to the usage of variants, if you can utilise callbacks containing a theme in its style key, than I would suggest the docs to at least mention it briefly. Generically speaking; any place where this is possible might need a brief extra sentence that callbacks are supported.

Context

Here is the example I saw using the callbacks:

const finalTheme = createTheme({
  components: {
    MuiChip: {
      styleOverrides: {
        icon: ({ theme }) =>
          theme.unstable_sx({
            mr: 0.5,
            ml: '-2px',
          }),
      },
    },
  },
});

Search keywords: styleOverrides, callback

@GBvanDam GBvanDam added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: docs-feedback Feedback from documentation page labels Nov 2, 2024
@zannager zannager added docs Improvements or additions to the documentation customization: theme Centered around the theming features labels Nov 4, 2024
@siriwatknp
Copy link
Member

siriwatknp commented Nov 11, 2024

At the moment, it's possible but the reason we don't document it because it might be removed in the future to be compatible with Pigment CSS. It's recommended to use variants instead so that the theme is static.

const finalTheme = createTheme({
  components: {
    MuiChip: {
      styleOverrides: {
        icon: {
          variants: [...]
        },
      },
    },
  },
});

@siriwatknp siriwatknp removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 11, 2024
Copy link

This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

Note

@GBvanDam How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

@GBvanDam
Copy link
Author

@siriwatknp that of course solves requirements like: make the border squared if variant equals 'outlined'. What is your advice on re-using css vars in your createTheme call? What I mean is that you are creating a theme where you first of all define colorSchemes, but then you're also overriding some components to use these colors (e.g. setting tab bgcolor to secondary.light).

I see 3 options right now:

  • hardcode hexadecimals (bad choice)
  • hardcode css vars (--palette-secondary-light)
  • create local const variables that hold the color hexadecimals

What I liked about the (theme) => theme.vars.palette.primary.main approach is that Typescript/Next.js will fail if a color has been re-named or anything like that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: theme Centered around the theming features docs Improvements or additions to the documentation support: docs-feedback Feedback from documentation page
Projects
None yet
Development

No branches or pull requests

3 participants