Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Consider Different CSS-in-JS Solution #50

Closed
0xcaff opened this issue Jul 28, 2018 · 4 comments · Fixed by #52
Closed

Consider Different CSS-in-JS Solution #50

0xcaff opened this issue Jul 28, 2018 · 4 comments · Fixed by #52
Projects

Comments

@0xcaff
Copy link
Member

0xcaff commented Jul 28, 2018

Currently CSS Modules are used. There are some issues with it:

  1. The primary reason we ejected was for CSS modules support. If our dependency on css modules can be removed, we can un-eject, simplifying the codebase. (See Un-Eject #14)

  2. React has shown that tightly coupling view and logic (HTML and JS) isn't necessary a bad thing when done right. Currently with CSS Modules, styles aren't tightly coupled with components. We take the costs of decoupling while reaping none of the benefits. An example of the costs are link styling which isn't connected and consistent across the application.

  3. Global styles are hard.

  4. className injection is gross.

There are a number of new ways to write CSS in React apps:

  • emotion
  • styled
  • styled-jsx
  • glamor (no one uses this any more)
  • Aphrodite (wordy)
  • radium (not a fan of syntax)
  • reactcss (no one uses this anymore)

I think the most widely understood, marketed and used tool is styled but emotion is a strong runner-up which is probably better but has a weaker ecosystem.

@0xcaff 0xcaff added this to In Progress in Release Jul 28, 2018
@0xcaff
Copy link
Member Author

0xcaff commented Jul 28, 2018

So, I'm trying styled now and it doesn't have the best typescript story.

In order to type the theme object with typescript, you need to re-export the module with the theme generic parameter added. This means that imports turn into import styled from '../../styled-components' from import styled from 'styled-components'.

Typing input props is a bit strange. The following doesn't work.

image

The types are enforced at call-sites but not available in the template function parameter unless explicitly typed. This is a major annoyance. styled-components/styled-components#565 (comment) Fixing was previously blocked on microsoft/TypeScript#11947 but that is now fixed. The typings look correct, but I can't get this to work in typescript 2.9. It seems to be cause by styled-components/styled-components#1697

Actually it does work, the auto-complete is just really bad.

@0xcaff
Copy link
Member Author

0xcaff commented Jul 29, 2018

I've converted over a few higher-level components to use styled components. I'm going to look at converting some of the interactive lower-level components to styled components.

@0xcaff
Copy link
Member Author

0xcaff commented Jul 30, 2018

Emotion seems pretty good if not better. The webstorm and vscode plugins work for both emotion and styled. Emotion has a few api differences:

@0xcaff
Copy link
Member Author

0xcaff commented Aug 1, 2018

Everything except for the partially implemented dropdown menu has been converted to styled components. Just need to figure out the theme situtation, investigate removing extra stuff (css modules, style-lint) and merge.

@0xcaff 0xcaff moved this from In Progress to Testing in Release Aug 2, 2018
@0xcaff 0xcaff closed this as completed in #52 Aug 3, 2018
@0xcaff 0xcaff moved this from Testing to Done in Release Aug 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Release
  
Done
Development

Successfully merging a pull request may close this issue.

1 participant