Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Danilo-Araujo-Silva/2ce11fd0540dcc7eb3ad3e67fd75d02a to your computer and use it in GitHub Desktop.
Save Danilo-Araujo-Silva/2ce11fd0540dcc7eb3ad3e67fd75d02a to your computer and use it in GitHub Desktop.

Revisions

  1. Danilo-Araujo-Silva revised this gist Mar 3, 2019. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion Overriding Material UI styles with Styled Components.md
    Original file line number Diff line number Diff line change
    @@ -48,9 +48,13 @@ For example, to override the AppBar (https://material-ui-next.com/api/app-bar/)

    # Fourth method (use a custom classname generator)

    You can control the classenames that will be generated by MaterialUI.
    Maybe it will require a little more effort but it can also bring more flexibility.

    Please see these sections of the documentation:
    - https://material-ui.com/customization/css-in-js/#css-injection-order
    - https://material-ui.com/customization/css-in-js/#global-css
    - https://material-ui.com/customization/css-in-js/#creategenerateclassname-options-class-name-generator
    - https://material-ui.com/customization/css-in-js/#css-injection-order

    `/path/to/the/theme/provider/ThemeProvider.js`:
    ```js
  2. Danilo-Araujo-Silva revised this gist Mar 3, 2019. 1 changed file with 25 additions and 1 deletion.
    26 changes: 25 additions & 1 deletion Overriding Material UI styles with Styled Components.md
    Original file line number Diff line number Diff line change
    @@ -52,6 +52,7 @@ Please see these sections of the documentation:
    - https://material-ui.com/customization/css-in-js/#css-injection-order
    - https://material-ui.com/customization/css-in-js/#global-css

    `/path/to/the/theme/provider/ThemeProvider.js`:
    ```js
    import React from "react"
    import MuiThemeProvider from "material-ui/styles/MuiThemeProvider"
    @@ -70,7 +71,7 @@ const ClassNameGenerator = (p) =>
    {p.children}
    </JssProvider>

    export class MyComponent {
    export class ThemeProvider {

    render() {
    return (
    @@ -82,4 +83,27 @@ export class MyComponent {
    )
    }
    }
    ```

    `/path/to/the/root/component/Root.js`
    ```js
    import React from "react"
    import {Provider} from "react-redux"

    import {ThemeProvider} from "/path/to/the/theme/provider/ThemeProvider"
    import {Router} from "/path/to/your/router/definitions/Router"
    import {reduxStore} from "/path/to/your/redux/store"

    export class Root {

    render() {
    return (
    <Provider store={reduxStore}>
    <ThemeProvider>
    <Router />
    </ThemeProvider>
    </Provider>
    )
    }
    }
    ```
  3. Danilo-Araujo-Silva revised this gist Mar 3, 2019. 1 changed file with 14 additions and 14 deletions.
    28 changes: 14 additions & 14 deletions Overriding Material UI styles with Styled Components.md
    Original file line number Diff line number Diff line change
    @@ -61,25 +61,25 @@ import JssProvider from "react-jss/lib/JssProvider"
    import {yourTheme} from "/path/to/your/theme"

    const generateClassName = createGenerateClassName({
    dangerouslyUseGlobalCSS: true,
    productionPrefix: 'mui',
    dangerouslyUseGlobalCSS: true,
    productionPrefix: 'mui',
    })

    const ClassNameGenerator = (p) =>
    <JssProvider generateClassName={generateClassName} {...p}>
    {p.children}
    </JssProvider>
    <JssProvider generateClassName={generateClassName} {...p}>
    {p.children}
    </JssProvider>

    export class MyComponent {

    render() {
    return (
    <ClassNameGenerator>
    <MuiThemeProvider theme={yourTheme}>
    {this.props.children}
    </MuiThemeProvider>
    </ClassNameGenerator>
    )
    }
    render() {
    return (
    <ClassNameGenerator>
    <MuiThemeProvider theme={yourTheme}>
    {this.props.children}
    </MuiThemeProvider>
    </ClassNameGenerator>
    )
    }
    }
    ```
  4. Danilo-Araujo-Silva revised this gist Mar 3, 2019. 1 changed file with 38 additions and 0 deletions.
    38 changes: 38 additions & 0 deletions Overriding Material UI styles with Styled Components.md
    Original file line number Diff line number Diff line change
    @@ -44,4 +44,42 @@ For example, to override the AppBar (https://material-ui-next.com/api/app-bar/)
    z-index: 1500;
    }
    `
    ```

    # Fourth method (use a custom classname generator)

    Please see these sections of the documentation:
    - https://material-ui.com/customization/css-in-js/#css-injection-order
    - https://material-ui.com/customization/css-in-js/#global-css

    ```js
    import React from "react"
    import MuiThemeProvider from "material-ui/styles/MuiThemeProvider"
    import {createGenerateClassName} from "material-ui/styles"
    import JssProvider from "react-jss/lib/JssProvider"

    import {yourTheme} from "/path/to/your/theme"

    const generateClassName = createGenerateClassName({
    dangerouslyUseGlobalCSS: true,
    productionPrefix: 'mui',
    })

    const ClassNameGenerator = (p) =>
    <JssProvider generateClassName={generateClassName} {...p}>
    {p.children}
    </JssProvider>

    export class MyComponent {

    render() {
    return (
    <ClassNameGenerator>
    <MuiThemeProvider theme={yourTheme}>
    {this.props.children}
    </MuiThemeProvider>
    </ClassNameGenerator>
    )
    }
    }
    ```
  5. Danilo-Araujo-Silva renamed this gist Mar 3, 2019. 1 changed file with 0 additions and 0 deletions.
  6. Danilo-Araujo-Silva revised this gist Mar 3, 2019. 1 changed file with 23 additions and 4 deletions.
    27 changes: 23 additions & 4 deletions Overriding Material UI styles with Styled Components
    Original file line number Diff line number Diff line change
    @@ -1,28 +1,47 @@
    For example, to override the AppBar (https://material-ui-next.com/api/app-bar/) root class we can do the following:

    First method (override Material UI classnames):
    # First method (override Material UI classnames):

    1 - Add the property classes in the AppBar component:

    ```js
    <AppBar classes={{root: 'my-root-class'}}
    ```

    2 - Override the styles with the styled components:

    ```js
    styled(AppBar)`
    &.my-root-class {
    z-index: 1500;
    }
    `
    ```

    # Second method (force specificity):

    Second method (force specificity):
    ```js
    styled(AppBar)`
    && {
    z-index: 1500;
    }
    `
    ```

    # Third method (use a custom classname):

    Third method (use a custom classname):
    1 - Add the classname in the classname property:

    ```js
    <AppBar className={`my-class ${this.props.otherClassesFromPropertiesIfNeeded}`}
    ```

    2 - Override the styles with the styled components:

    ```js
    styled(AppBar)`
    &.my-class {
    z-index: 1500;
    }
    `
    `
    ```
  7. Danilo-Araujo-Silva revised this gist May 6, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Overriding Material UI styles with Styled Components
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ Second method (force specificity):

    Third method (use a custom classname):
    1 - Add the classname in the classname property:
    <AppBar className={`my-class ${this.props.otherClassesFromPropertiesWithNeeded}`}
    <AppBar className={`my-class ${this.props.otherClassesFromPropertiesIfNeeded}`}
    2 - Override the styles with the styled components:
    styled(AppBar)`
    &.my-class {
  8. Danilo-Araujo-Silva revised this gist Jan 11, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Overriding Material UI styles with Styled Components
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ Second method (force specificity):

    Third method (use a custom classname):
    1 - Add the classname in the classname property:
    <AppBar className={`my-class ${this.props.className}`}
    <AppBar className={`my-class ${this.props.otherClassesFromPropertiesWithNeeded}`}
    2 - Override the styles with the styled components:
    styled(AppBar)`
    &.my-class {
  9. Danilo-Araujo-Silva revised this gist Jan 10, 2018. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions Overriding Material UI styles with Styled Components
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,6 @@
    For example, to override the AppBar (https://material-ui-next.com/api/app-bar/) root class we can do the following:

    First method (override Material UI classnames):

    1 - Add the property classes in the AppBar component:
    <AppBar classes={{root: 'my-root-class'}}
    2 - Override the styles with the styled components:
    @@ -12,7 +11,6 @@ First method (override Material UI classnames):
    `

    Second method (force specificity):

    styled(AppBar)`
    && {
    z-index: 1500;
  10. Danilo-Araujo-Silva revised this gist Jan 10, 2018. 1 changed file with 17 additions and 17 deletions.
    34 changes: 17 additions & 17 deletions Overriding Material UI styles with Styled Components
    Original file line number Diff line number Diff line change
    @@ -3,28 +3,28 @@ For example, to override the AppBar (https://material-ui-next.com/api/app-bar/)
    First method (override Material UI classnames):

    1 - Add the property classes in the AppBar component:
    <AppBar classes={{root: 'my-root-class'}}
    <AppBar classes={{root: 'my-root-class'}}
    2 - Override the styles with the styled components:
    styled(AppBar)`
    &.my-root-class {
    z-index: 1500;
    }
    `
    styled(AppBar)`
    &.my-root-class {
    z-index: 1500;
    }
    `

    Second method (force specificity):

    styled(AppBar)`
    && {
    z-index: 1500;
    }
    `
    styled(AppBar)`
    && {
    z-index: 1500;
    }
    `

    Third method (use a custom classname):
    1 - Add the classname in the classname property:
    <AppBar className={`my-class ${this.props.className}`}
    <AppBar className={`my-class ${this.props.className}`}
    2 - Override the styles with the styled components:
    styled(AppBar)`
    &.my-class {
    z-index: 1500;
    }
    `
    styled(AppBar)`
    &.my-class {
    z-index: 1500;
    }
    `
  11. Danilo-Araujo-Silva revised this gist Jan 10, 2018. No changes.
  12. Danilo-Araujo-Silva revised this gist Jan 10, 2018. No changes.
  13. Danilo-Araujo-Silva revised this gist Jan 10, 2018. No changes.
  14. Danilo-Araujo-Silva revised this gist Jan 10, 2018. 1 changed file with 30 additions and 1 deletion.
    31 changes: 30 additions & 1 deletion Overriding Material UI styles with Styled Components
    Original file line number Diff line number Diff line change
    @@ -1 +1,30 @@
    For example, to override the AppBar (https://material-ui-next.com/api/app-bar/) root
    For example, to override the AppBar (https://material-ui-next.com/api/app-bar/) root class we can do the following:

    First method (override Material UI classnames):

    1 - Add the property classes in the AppBar component:
    <AppBar classes={{root: 'my-root-class'}}
    2 - Override the styles with the styled components:
    styled(AppBar)`
    &.my-root-class {
    z-index: 1500;
    }
    `

    Second method (force specificity):

    styled(AppBar)`
    && {
    z-index: 1500;
    }
    `

    Third method (use a custom classname):
    1 - Add the classname in the classname property:
    <AppBar className={`my-class ${this.props.className}`}
    2 - Override the styles with the styled components:
    styled(AppBar)`
    &.my-class {
    z-index: 1500;
    }
    `
  15. Danilo-Araujo-Silva created this gist Jan 10, 2018.
    1 change: 1 addition & 0 deletions Overriding Material UI styles with Styled Components
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    For example, to override the AppBar (https://material-ui-next.com/api/app-bar/) root