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

MuiThemeProvider as an override mechanism for a subtree #6129

Closed
kof opened this issue Feb 13, 2017 · 13 comments
Closed

MuiThemeProvider as an override mechanism for a subtree #6129

kof opened this issue Feb 13, 2017 · 13 comments
Assignees
Labels
new feature New feature or request
Milestone

Comments

@kof
Copy link
Contributor

kof commented Feb 13, 2017

Given a case: I have 2 types of a Button, first one with rounded corners, second one without. Now in case I want all buttons inside of some subtree use the second type, I would want to use the MuiThemeProvider.

const theme1 = createMuiTheme({
  overrides: {
    Button: {
      root:  {
        borderRadius: 10
      }
    }
  }
}) 

const theme2 = createMuiTheme({
  overrides: {
    Button: {
      root:  {
        borderRadius: 0
      }
    }
  }
}) 

class Subtree extends Component {
  render() {
    return (
      <ThemeProvider theme={theme2}>
        <Button>Click  me hard</Button>
     </ThemeProvider>
    )
  }
} 

class App extends Component {
  render() {
    return (
      <ThemeProvider theme={theme1}>
        <Subtree />
      </ThemeProvider>
    )
  }
}

In this case, theme2 will overwrite theme1 style sheet.

@oliviertassinari oliviertassinari changed the title MuiThemeProvider as an override mechanism for a subtree (next) MuiThemeProvider as an override mechanism for a subtree Feb 13, 2017
@oliviertassinari
Copy link
Member

oliviertassinari commented Feb 13, 2017

In this case, the inner ThemeProvider will be ignored. Any ideas why?

Because we haven't implemented it. The <ThemeProvider /> isn't looking into the context. He is only providing a new one. Hence, the child is overriding the context of the parent.
I think that we should support it.

@nathanmarks What do you think?

@kof
Copy link
Contributor Author

kof commented Feb 14, 2017

We need to do here the same like styled-components do

@kof
Copy link
Contributor Author

kof commented Feb 14, 2017

Wait, providing a new value on the context would not be an issue in my case. I just learned that the context is a new one for each subtree, so they don't collide when redefined. I thought its a collision because the inner provider overrides mui on the context for everything else, but its not!

@kof
Copy link
Contributor Author

kof commented Feb 14, 2017

It turns out the issue is that once you try to override the same component using a provider, it still uses the same style tag and overwrites it completely. cc @nathanmarks

@kof
Copy link
Contributor Author

kof commented Feb 14, 2017

Updated the example in main description.

@kof
Copy link
Contributor Author

kof commented Jul 4, 2017

We should switch to https://github.com/iamstarkov/theming. It is a unifying theming solution for all styling libs and some of popular once already committed the migration (which is easy).

@nathanmarks
Copy link
Member

@kof do you want to have a go at switching it in?

@oliviertassinari oliviertassinari added new feature New feature or request and removed discussion labels Jul 5, 2017
@kof
Copy link
Contributor Author

kof commented Jul 5, 2017

I am not sure if I am able to actually do it, because of time but yeah, we should at least discuss and and agree on that.

@oliviertassinari
Copy link
Member

Theme nesting is fully supported now. It's all in the documentation.

@andrispraulitis
Copy link

andrispraulitis commented Jan 31, 2018

@oliviertassinari

Except that overrides are extended which means I have to re-override in every sub tree. I want nested themes where I start completely fresh overrides with createMuiTheme(), is that possible?

My goal is to use Portal for some printing stuff where I simply want plain light theme.

@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 31, 2018

I start completely fresh overrides with createMuiTheme(), is that possible?

@andrispraulitis Yes, it is. You are in control of how the outer (parent) theme impact the inner (child) theme. This example was made for you: https://material-ui.com/customization/themes/#nesting-the-theme.

@andrispraulitis
Copy link

andrispraulitis commented Jan 31, 2018

Yes I think I got it now.

const defaultTheme = createMuiTheme()
const theme = outerTheme => defaultTheme

@oliviertassinari
Copy link
Member

@andrispraulitis It doesn't need to be a callback. It can be simple object.

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
Projects
None yet
Development

No branches or pull requests

5 participants