ThemeProvider
See original GitHub issueUsage
Change theme globally:
<ThemeProvider
theme={{
...
}}
>
<Button>Hello</Button>
</ThemeProvider>
Only override theme variables for specific element, and these variables will be merged with global vairables:
<Button theme={{ ... }}>Hello</Button>
Discussion
Implementation
This feature means that we need to introduce CSS-in-JS solution to antd
CSS-in-JS solutions: https://github.com/MicheleBertoli/css-in-js
- To implement ThemeProvider, we must choose a CSS-in-JS solution which can get JS variable dynamically.
- To make it easier to migrate to this CSS-in-JS solution, it must support:
- Pseudo class such as hover & focus style, because we don’t want to set these styles by events.
- Pseudo elements, for components like Icon & Calendar.
- CSS Selector Combinators such as
+
&>
, actually, we had used+
in Checkbox, etc. - Features like auto-prefixer will be better.
- Media query
CSS Selectors https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors
CSS Selectors are important to
antd
, because it can simplify JavaScript’s code
For compatibility, this CSS-in-JS solution should support server-side rendering, because SSR is an important feature of antd
.
Compatibility
Developers may use .ant-btn
to override antd
’s default style, so we need to reserve these className
s, even though we don’t need them. And this also means that we cannot use inline styles, e.g. material-ui
Issue Analytics
- State:
- Created 6 years ago
- Reactions:56
- Comments:36 (24 by maintainers)
Top Results From Across the Web
Advanced Usage - styled-components
styled-components has full theming support by exporting a <ThemeProvider> wrapper component. This component provides a theme to all React components ...
Read more >Theming - Material UI - MUI
ThemeProvider relies on the context feature of React to pass the theme down to ... ThemeProvider is a parent of the components you...
Read more >ThemeProvider - React UI
React UI uses the System UI theme specification with minor additions. The theme lets you control the overall design of your project with...
Read more >callstack/react-theme-provider: A set of utilities that ... - GitHub
@callstack/react-theme-provider is a set of utilities that help you create your own theming system in few easy steps. You can use it to...
Read more >How to Create Material UI Custom Theme #30 - YouTube
Material UI Theme Provider | Material UI Tutorial | How to Create ... theme in Material UI and How to use ThemeProvider in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This feature is low-priority, even if we accept it.
Another proposal, can we use
rem
instead ofpx
in the next version? the hard codedpx
is anti-design for theming. For example, in the current theming system, variables does not comply with each other well if you change thefont-size-base
to a big value due to the hard coded buttonheight
:you can try it here