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.

[RFC] Restructure the keys inside the theme by component name

See original GitHub issue

Summary

This RFC proposes slightly different structure to the theme, by moving the components as first key, and nesting the existing keys (overrides, props and variants - will be added with https://github.com/mui-org/material-ui/pull/21648) inside. As we are doing this breaking change, we may even consider renaming the existing keys based on this https://github.com/mui-org/material-ui/issues/21012#issuecomment-629161024 to cssOverrides and defaultProps.

Changes

Current:

const theme = createMuiTheme({
  overrides: {
    MuiButton: {
      root: {
        fontSize: 20,
      },
    },
  },
  props: {
    MuiButton: {
      disableFocusRipple: true,
    },
  },
  variants: {
    MuiButton: [
      {
        props: { variant: 'dashed' },
        styles: { border: '2px dashed grey' },
      }
    ],
  },
});

Proposed:

const theme = createMuiTheme({
  components: {
    MuiButton: {
      cssOverrides: {
        root: {
          fontSize: 20,
        },
      },
      defaultProps: {
        disableFocusRipple: true,
      },
      variants: [
        {
          props: { variant: 'dashed' },
          styles: { border: '2px dashed grey' },
        },
      ],
    },
  },
});

Motivation

Think component first.

With the proposed definition all theme definitions related to one component can be easily discovered and defined together. It’s also interesting if later on, developers have a concern about tree-shaking and want to move the configuration from the theme singleton to wrapper components they import.

Drawbacks

Other than the change being breaking, I don’t see any other drawback with the proposed restructuring.

Prio-arts

Same approach in

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:11
  • Comments:21 (20 by maintainers)

github_iconTop GitHub Comments

5reactions
ryancogswellcommented, Jul 25, 2020

If we were to unify the terminology, I think I prefer cssOverrides and css rather than styleOverrides and styles. I like how cssOverrides ties more clearly to the CSS portion of the API documentation. styles makes me think of inline styles which might not give quite the right mental model – I assume the CSS for a variant will support media queries and pseudo classes (just like you can do within one of the rules of the cssOverrides). I think the styles name might provide an impression that it wouldn’t support those aspects (since they aren’t supported by inline styles).

2reactions
ryancogswellcommented, Jul 25, 2020

I think the overall structure change is nice, but I think it is important to add a function to ease migration such as createMuiThemeFromV4Structure that would take care of reorganizing the props and overrides portion of the passed in theme as necessary. Then developers could import that instead of createMuiTheme if they want to put off reorganizing their theme to the new structure.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[RFC] Restructure the keys inside the theme by component ...
This RFC proposes slightly different structure to the theme, by moving the components as first key, and nesting the existing keys ( overrides...
Read more >
Olivier Tassinari on Twitter: "Should we restructure the theme ...
Summary This RFC proposes slightly different structure to the theme, by moving the components as first key, and nesting the existing keys (overrides,...
Read more >
How to use Themes in styled-components - DEV Community ‍ ‍
Inside the theme object, we can access any of the keys such as the colors object and reference a specific color (i.e persianGreen...
Read more >
SAP GUI for Windows 7.70: New Features & Lifecycle ...
Removed features in SAP GUI for Windows 7.70. This time we haven't removed any visual theme, but have just cleaned-up the theme selection...
Read more >
Network Working Group C. Bormann Internet-Draft Universität ...
respective tag is imputed to all keys in the map that are byte strings. The values in the map are not considered specially...
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