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.

[Theming] Allow component specific global theme overrides

See original GitHub issue

There seems to be a need to override global styles per component due to design language differences and variations. Per component global overrides should be on a theme or the ThemeProvider level.

Current Behavior

Currently, in order to override styles on a specific component across the whole application, you’d need to create and use a customized component that passes needed overrides to the BaseUI component.

Potential Solutions

  1. Let the styledfunction accept a third argument, that is a per component style override hook. A POC can be found here. Some cons here:
    • Component overrides would be css declaration blocks or functions that return a css declaration block in order to support dynamic styles. As opposed to the theme that contains style values only and no css declarations.
  2. Have optional component specific style values in the theme obj. POC. Cons:
    • The styled components code get’s messy

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:17 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
airhornscommented, Feb 22, 2021

Did you fine folks make any decisions around this? It would be super great to get for those of us who want to make themes that do fancier stuff!!

1reaction
tolgaouzcommented, Mar 18, 2021

Looks good conceptually to me - I like having an HOC like that. Not sure what this part is about tho:

 // Note the second param "ref" provided by React.forwardRef.
  // We can pass it along to withOverrides as a regular prop, e.g. "forwardedRef"
  // And it can then be attached to the Component.
  return React.forwardRef((props, ref) => {
    return <LogProps {...props} forwardedRef={ref} />;
  });

Sorry, my bad! I was just thinking about the concept while preparing this code snippet so I just took some parts of it from the official docs, forgot to replace the names! 😅 Just fixed it.

Then maybe I can create a PR with a better explanation of everything after running tests and making sure this works

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global Styling with Material-UI Theme Overrides and Props
Learn how to use global CSS overrides and default props in a theme to customize all instances of a Material-UI component in a...
Read more >
Material-UI Customization Part 2, Global Overrides for Theme
In this video, we go over how to override Material-UI component styling at a global level. The Material-UI documentation refers to the ...
Read more >
Material UI in React #3 - Styles - adding global theme and ...
0:12 - Intro 0:12 ; 3:10 - Reusable button component 3:10 ; 4:39 - Overriding styles using SX props 4:39 ; 5:59 -...
Read more >
Theming - Material UI - MUI
If you wish to customize the theme, you need to use the ThemeProvider component in order to inject a theme into your application....
Read more >
Material-UI React: Global theme override for Paper component
You can also use your CssBaseline component if you're already using it for global reset...all depends ...
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