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.

Usage

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 classNames, even though we don’t need them. And this also means that we cannot use inline styles, e.g. material-ui

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:56
  • Comments:36 (24 by maintainers)

github_iconTop GitHub Comments

24reactions
benjycuicommented, Apr 7, 2017

This feature is low-priority, even if we accept it.

17reactions
neekeycommented, Jul 17, 2017

Another proposal, can we use rem instead of px in the next version? the hard coded px is anti-design for theming. For example, in the current theming system, variables does not comply with each other well if you change the font-size-base to a big value due to the hard coded button height:

image

you can try it here

Read more comments on GitHub >

github_iconTop 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 >

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