Lurker News

Comments (104) 33 threads

Earlier comments
secoif5 replies#
These components look and work great, but unfortunately are a real headache to retheme unless you want to pull in a sass/less toolchain in addition to what you're currently using. This is a pain in the ass if you already have your theme variables set up in one compiles-to-CSS language.

There is a standard for CSS variables and a very functional subset of their functionality can be compiled for older browsers at build time: http://cssnext.io, yet as far as I can tell, all of these component frameworks impose some other nonstandard compiles-to-CSS language or one of many possible APIs for writing inline styles.
Inline styles seem to be a trend at the moment but I can only assume the people driving this movement haven't had the experience of working with 3rd party components (which you may or may not have the source for) and needing to alter something the designers didn't expose and simply having no simple options because the damn inline style can't be overridden even by !important. Now you've got to fork whole the f'ing component, possibly multiple, each of which potentially coming with yet another different compiles-to-CSS toolchain all because you wanted to add a single line of CSS.
Admittedly, antd doesn't use inline styles si the above doesn't apply here, but having to maintain a custom builder for antd in order to change some fonts and a few colors was a frustrating experience. Not sure what a good solution is until CSS variables get more browser adoption, but it'd be great if we could collectively start standardizing on standards.

Illniyar2 replies#
SCSS (and to a lesser degree LESS) are basically industry standard now, if you are using react, you are almost certainly using one of the two preprocessors.

I don't think your complaint is relevant here, especially since you provide no solution.
It bothers me that this reply is at the top of the comments.

prashnts1 reply#
The argument about inline styles is valid, in my opinion. I've had to fork and keep updating from upstream several react components for the exact same reason.
Illniyar#
But it's not relevant to the article, since as they don't use inline styles.
griffinmichl1 reply#
I don't really see much of a need for preprocessors w/ css modules, post css, css in js, etc. It seems like preprocessors are becoming less popular, not more.
mxstbr3 replies#
Theming is on of the big reasons we saw the need to make styled-components[0] (new lib to style React apps and component libraries)

I'm one of the maintainers of ElementalUI, and Glen Maddern, the styled-components co-creator, one of the creators of CSS Modules. One of the biggest downsides of CSS Modules (and, by extension, every other styles in JavaScript library right now) is that theming is simply impossible. Building third-party component libraries is hard enough, but providing an easy-to-theme API wasn't a solved problem in the React world. Nobody has done it properly, and there is no agreed-upon way of doing this!
styled-components has built-in theming support[1] to solve this exact problem. (note: this is CSS-in-JS, not inline styles[2], so overriding is easy as pie too[3]) We're rebuilding ElementalUI with it right now and the next versions of react-toolbox and Belle will be built with it as well.
We also have ReactNative support, which nobody else has done before. Just because you're writing a universal React app with a third-party component library shouldn't mean switching between three or four different APIs to style your app. With styled-components, you can just use styled-components no matter what you're styling!
(If you're reading this, I'd love to have a chat with the Antd people about maybe moving to styled-components! You can reach me on Twitter at @mxstbr, just ping me there!)

  [0]: https://styled-components.com
  [1]: https://github.com/styled-components/styled-components#theming
  [2]: mxstbr.blog/2016/11/inline-styles-vs-css-in-js
  [3]: https://github.com/styled-components/styled-components#overriding-component-styles
Zalastax1 reply#
A big issue I see with CSS-in-JS at this moment is server-side-rendering and caching. You started working on a babel-transform for extracting static styles but seem to have changed your mind about actually extracting that to a css-file[1]. Requiring a JS-parser to apply the styles is the wrong approach but might be a stepping stone as it's probably an easier problem to solve. Separating JS and CSS should improve performance somewhat as the browsers can run the scripting and styling engine separately. In the end I'd like a transformation that creates one CSS-file per JS-file so that common chunks can be combined by webpack, gaining high cache hit percentage on sites that uses reloads. Transformations should also be applied to the JS so that SSR doesn't have to calculate styles each time.

[1]: https://github.com/styled-components/styled-components/issue...

mxstbr1 reply#
Would you mind chiming into that issue with what you imagine? I hadn't thought about caching yet, that's a good use-case for a separate CSS file!

We also almost have a proper server-side rendering API[0], in case you haven't seen that PR before. Should be released very soon!
[0]: https://github.com/styled-components/styled-components/pull/...

Continue this thread — 1 reply

just-boris1 reply#
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
   }
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
mxstbr2 replies#
We're currently writing some documentation specifically pertaining to theming third-party component libraries, which you can read the WIP of here: https://github.com/styled-components/styled-components-exper...

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:

    import { ThemeProvider } from 'antd';




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? :-)

Continue this thread — 2 replies

mlsarecmg#
It is not a headache to retheme them. It is pretty easy, the easiest i've seen in a UI kit. You have style and classname overrides in place, scoped css classnames and LESS.

If you use a CSS react-lib like React-CSJS, styling this is easy as pie.

Lazare#
I agreed that it's been an unsolved problem, but I've been looking at 'styled-components' and I think it may be the answer.

At least on paper, it solved the issues you raise. Time will tell I suppose.

mstijak1 reply#
Theming is a difficult problem. Each component has a couple of visual properties which may depend on the state (hover, focus, error, internal variable). Having a separate variable for each visual property would be a nightmare.

I'm currently working on themes for a similar framework. It's still in early stage but you can see it here: http://cx.codaxy.com/v/master/themes/

crudbug2 replies#
Today, I was thinking about this problem.

You can separate component Style into - BASE + States classes.
classnames[0] can used to use multiple classes, the classes can be activated using component state. This provides a viable solution for Structure & Style.
[0] https://github.com/JedWatson/classnames

mxstbr#
This is useful for structuring components internally, but sadly doesn't help solve the theming issue at all :-(

What you want from theming is a global skin. You want users of your component library to be able to say "I want all of my buttons to be red" without having to wrap the component or pass a prop to every component. (simplified example)
Doing so just with class names is very very hard. It's what we've done for ElementalUI (together with Less), but it just doesn't work – it's a pita for users!

mstijak#
This exact approach is used for Cx components.
sidi1 reply#
I fail to understand this criticism. React Components expose a class hierarchy which can be namespaced well by their designers (if Antd isn't already doing this). Extending / theming with your specific CSS pre-processor is then pretty straightforward.
secoif#
Doing it this way requires overriding every single built-in rule that uses the property you're trying to override… including states like :hover, :before, :disabled, :disabled and :hover, etc which can be easy to miss.

I've had some success with simple find & replace preprocessor but this gets complicated if the CSS uses colour manipulation functions e.g. color: color(var(--color-base) tint(50%)), then you're basically going to be re-implementing their whole stylesheet again.
Also, good luck making sure everything still works if and when the components are updated.
Ideally, you alter theme variables in one place, rather than finding and overriding them everywhere they're applied.

datashovel#
I want to speak generally about new UI components, since this is the 2nd post in a week (about a new library of UI components) that reached front page (that I've seen) which are not addressing what I see as a fundamental issue that future UI libraries should address.

For mobile platforms specifically. Now on the surface you can say that UI libraries these days, more or less, will work similarly if not exactly the same across platforms. I would say for most "types" of components this will be true. But form input field behavior is different enough between mobile platforms that I'm questioning why we aren't moving quickly away from native HTML form input fields.
I totally get the argument for accessibility (probably a lot of accessibility platforms depend on these fields), but even accessibility standards such as ARIA, because of some of these inconsistencies, should be pushing toward this goal (decoupling the form input UI components from native HTML form input fields) I think.
Does anyone else here have a strong opinion one way or another as far as their experience building PWA's on mobile where they've encountered the differences between platforms (I'm specifically familiar with Android vs. iOS)? Do you find the differences to be easy to work around? I'm especially interested in feedback from folks who have required some relatively detailed behaviors, such as consistency in how input fields behave when "tabbing" to the next / previous field, or how the "input type='time'" fields behave differently in terms of when DOM events fire while setting time. Or how native keyboard behaviors / layouts are sufficiently different that you'd prefer to have a way to make the experience within your app more consistent?

aryehof#
I can only imagine. Nothing shows but a blank page when clicking a site link in my iPad.

Load more comments