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

No way to define Box variants? #29524

Open
2 tasks done
dkadrios opened this issue Nov 5, 2021 · 3 comments
Open
2 tasks done

No way to define Box variants? #29524

dkadrios opened this issue Nov 5, 2021 · 3 comments
Labels
support: question Community support but can be turned into an improvement

Comments

@dkadrios
Copy link

dkadrios commented Nov 5, 2021

Should we be able to provide styleOverrides, defaultProps or variants for Box?

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

I'm not sure if this is a bug, or if it's by design. Considering the flexibility of Box I can see where it might be difficult to do.

We've been making extensive use of the ability to declare our own variants for various mui components and have found it to be more desirable than dealing with classNames.

One component that doesn't seem to work with this model, however, is Box.
I've searched the existing issues as best I can but keep coming up empty, and haven't seen anyone else discussing Box variants. I'm hoping I've just missed something.

Here's a simplified example:

const theme = createTheme({
  components: {
    MuiBox: {
      variants: [
        {
          props: { variant: 'error' },
          style: {
            border: '3px dashed red',
            textAlign: 'center'
          },
        }
      ],
    },
  }
})

I've also tried with other props such as data-variant="error", in case it's just that Box doesn't recognize 'variant'.

Expected Behavior 🤔

MuiBox variants, defaultProps and styleOverrides should work as they do with other components.

Steps to Reproduce 🕹

While working on setting up this codebox, I noticed that MuiBox is not present in components.d.ts, so I guess this is more of a feature request than a bug report :-/

https://codesandbox.io/s/heuristic-water-pzsoz

@dkadrios dkadrios added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 5, 2021
@siriwatknp
Copy link
Member

Thanks for reporting about this. Currently, Box is meant to be used in a specific location. It is useful when you have to define a small stylesheet on it such as a flexbox wrapper.

I guess in your case, you should create a new component with styled and define variant prop by yourself. I think this is worth creating a doc about how to create a new themable component with MUI styled.

@siriwatknp siriwatknp added support: question Community support but can be turned into an improvement and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 8, 2021
@dkadrios
Copy link
Author

dkadrios commented Nov 8, 2021

Thanks @siriwatknp. Yeah, we currently used styled to create a number of variations based on Box. I was attempting to consolidate all these into a single place as we're able to do with every other mui component (so far). Box does appear to be an outlier.

At the moment I'm exploring using Container for this instead, though I suspect that has too much overhead. Having Box support variants and styleOverrides would be the ideal solution for us.

@Ben-CA
Copy link

Ben-CA commented Oct 10, 2024

+1 for this support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

3 participants