|
|
|
|
|
by just-boris
3497 days ago
|
|
Hello! I've been using Antd components for the last year in some my project. All components are also available here[0] as single modules for better reusability and customization. Currently, I have solved all my theming goals with Plain CSS. For each component, that I'd like to customize I created a wrapper import Slider from 'rc-slider';
function StyledSlider(props) {
return <Slider className="my-slider" {...props} />
}
Then in CSS .my-slider .rc-slider-track {
background: #FFDF66;
}
(This is a very simplified example, just shows the way).I have read about styled-components, but I don't understand how it would help me with theming. I don't think that rewriting every component from LESS to styled-components to make possible to use ThemeProvider will be an option because it doesn't give you any benefits comparing with customization guide[1], that also gives you good enough way to override defaults. [0]: https://github.com/react-component/
[1]: https://ant.design/docs/react/customize-theme
|
|
The TL;DR is that this customization guide will suddenly become really easy. Antd can specify a default theme and users can override the parts of the default theme they want!
All the user has to do is pass a single prop to the ThemeProvier and override what they want:
On top of that different parts of your app can have different themes. Making your sidebar dark but your main component light is not an issue – just wrap them in two ThemeProviders with different themes: It's also all dynamic, meaning you can let the users of your app provide custom themes for your app and it'll automatically apply.Compare that with the current customization guide, not only do users have to use webpack, they also have to use specific plugins just to make customization of third-party components work! It's also all global, which means styling the sidebar dark and the main area light is impossible since it's all just Less variables applied at build time. This also makes it very hard to have user supplied themes.
Does that make it clear enough how using styled-components would help with theming? :-)