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

Make component theme default props variant-aware #34812

Open
2 tasks done
paulleonartcalvo opened this issue Oct 18, 2022 · 5 comments
Open
2 tasks done

Make component theme default props variant-aware #34812

paulleonartcalvo opened this issue Oct 18, 2022 · 5 comments
Labels
new feature New feature or request package: system Specific to @mui/system

Comments

@paulleonartcalvo
Copy link

paulleonartcalvo commented Oct 18, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

When passing component overrides to createTheme(), allow the variants objects for each component to define their own default props as a callback with theme as its argument (same as style on the same object). This would mean that given a minimum set of required props for the component to qualify as a 'variant', we can assign any other default props for that variant.

Examples 🌈

export const MuiAutocompleteOverrides: Components<Theme>['MuiAutocomplete'] = {
  defaultProps: { // THIS IS NOT VARIANT AWARE
    popupIcon: (
      <CaretDownOutlineIcon size={theme.iconScale['x-small']} color={theme.colors['neutral-75']} />
    )
  },
  variants: [
    {
      props: {
        size: 'medium'
      },
      style: (theme) => ({
        padding: 0
      }),
      defaultProps: (theme) => ({ // THIS IS VARIANT AWARE
        popupIcon: (
          <CaretDownOutlineIcon size={theme.iconScale['medium']} color={theme.colors['neutral-75']} />
        )
      })
    }
  ]
};

Motivation 🔦

I want to be able to define what the default props for a component should be given that it matches a specific variant which i have defined. Specifically, i want to define a default icon for the Autocomplete component whose size changes according to the size prop passed to the component. Without this ability, i am forced to use a default icon whose size won't intelligently match the Autocomplete depending on the size. Instead, i have to pass the icon as the appropriate size everywhere that i use the Autocomplete.

@paulleonartcalvo paulleonartcalvo added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 18, 2022
@paulleonartcalvo paulleonartcalvo changed the title Add default props definitions to custom theme variants Make component theme override default props variant-aware Oct 18, 2022
@paulleonartcalvo paulleonartcalvo changed the title Make component theme override default props variant-aware Make component theme default props variant-aware Oct 18, 2022
@zannager zannager added the package: system Specific to @mui/system label Oct 19, 2022
@siriwatknp siriwatknp added new feature New feature or request package: system Specific to @mui/system and removed package: system Specific to @mui/system status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 21, 2022
@aimad-majdou
Copy link

Any updates on this ? this is also mandatory to override the svg icons used by an Alert via createTheme

@kavlih
Copy link

kavlih commented Sep 5, 2023

Would also love to see this. Is there currently any work around to archieve this?

@Londeren
Copy link

It would be really cool to have this feature!

@paulleonartcalvo
Copy link
Author

Dusting off the cobwebs 🕸️ 🧹

@jcohen14
Copy link

jcohen14 commented Feb 6, 2025

Bumping this! Would love to have this feature!

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

7 participants