question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[theme] Custom Variant

See original GitHub issue
  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔

I would love the ability to use a variant with any string and with that variant I could style the component using theme overrides. For example, let’s say I have 4 types of buttons throughout my app and each button has a custom variant, inside theme I would simply use MuiButton with my custom variant names and style them as I please. The variant would act as an identifier and would give the theme more flexibility in styling the entire app and it would not tie me down to a preset list of variants.

Current Behavior 😯

Currently variants are limited and come with additional styling.

Context 🔦

Limits my ability to use theme to a greater extent and pushes me to style more locally than globally.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:84
  • Comments:32 (10 by maintainers)

github_iconTop GitHub Comments

69reactions
philip-lfcommented, May 3, 2019

Thanks for your responses. @oliviertassinari , I don’t believe they are the same. Currently for Button I have these variants accessible to me: Screen Shot 2019-05-03 at 8 51 43 AM

Given two buttons, one with an outlined variant and the other without, the theme can target the button with the variant and style it specifically like this:

<Button  variant="outlined">
     Outlined Button
</Button>

<Button>
     Button
</Button>
const theme = createMuiTheme({
     overrides: {
          MuiButton: {
               root: {
                    backgroundColor: 'red'
               },
               outlined: {
                    backgroundColor: 'blue'
               }
          }
     }
})

The feature I would hope for is that a variant of any name can be applied and targeted through the theme. It would look something like this:

<Button  variant="customVariantName">
     Custom Button
</Button>

const theme = createMuiTheme({
     overrides: {
          MuiButton: {
               root: {
                    backgroundColor: 'red'
               },
               customVariantName: {
                    backgroundColor: 'blue'
               }
          }
     }
})

The variant would act as an identifier that could be accessed through the theme. So instead of applying unique styles to every component I would centralize my styles in one place.

43reactions
kylealwyncommented, Dec 30, 2019

MaterialUI has been a pleasure to work with but I’m surprised about the lack of support for custom colors/variants. I see this is bookmarked for v5 but the Oct. 2020 due date is some time away. Are there any updates / plans to support this in v4?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating custom variants with Material-UI - Stack Overflow
In Material-UI v5, you can easily create a new variants for your components (See the list of supported components in this RFC) using ......
Read more >
Variants - Theme UI
Variants allow you to define the styles used across multiple buttons, typographic elements, or any element in your theme object. For example, you...
Read more >
Components - MUI
You can use the variants key in the theme's components section to add new variants to MUI components. These new variants can specify...
Read more >
[theme] Custom Variant · Issue #15573 · mui/material-ui - GitHub
I am interested in creating custom variant in Typography. It seems to be working, however there are errors in console. Theme: const theme...
Read more >
Theme Variants | Styling and Themes | Flow | Vaadin 14 Docs
Custom variants allow you to freely customize the visual appearance of components. They are defined in an additional stylesheet which you import as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found