-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cli): static style extraction #714
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/sumup-oss/circuit-ui/830ac4wv0 |
Codecov Report
@@ Coverage Diff @@
## canary #714 +/- ##
==========================================
- Coverage 93.68% 93.64% -0.04%
==========================================
Files 131 132 +1
Lines 2280 2283 +3
Branches 643 644 +1
==========================================
+ Hits 2136 2138 +2
- Misses 119 120 +1
Partials 25 25
|
feature/static-style-extraction
feature/static-style-extraction
This way, we can use the classnames to style the static HTML examples. feature/static-style-extraction
DocGen for TS uses a slightly different format. feature/static-style-extraction
feature/static-style-extraction feature/static-style-extraction
feature/static-style-extraction
feature/static-style-extraction
feature/static-style-extraction
feature/static-style-extraction
7e91405
to
f8f3335
Compare
@robinmetral and I decided that static style extraction isn't the right approach to support non-React projects. It's brittle, doesn't have a nice API, and we lose out on important accessibility features that are baked into the React components. We haven't decided on a better alternative yet. One idea is to migrate Circuit UI to a framework agnostic stack (e.g. web components or Svelte). |
Follow-up to #477. Closes #479.
Purpose
There are some web projects at SumUp that can't or don't use React. They need to implement all styles from scratch and need to be updated separately. We can solve this by extracting the styles from the React components as static CSS.
This was an experimental feature in v1. The migration to TypeScript as part of v2 broke the extraction script. This is a re-implementation with the goal of making the feature production-ready.
Approach and changes
babel-plugin-react-docgen-typescript
to extract prop type information from the components. This information is used to render every variation of a component and capture the corresponding styles.Technical implementation
yarn circuit-ui static-styles
command which validates the provided options and then spawns a child process.@babel/node
to generate the static CSS. The indirect call through@babel/node
is necessary since the Emotion Babel preset is required to properly extract the styles and their classnames.How to use
After installing
@sumup/circuit-ui
into their project, users can use the Circuit UI CLI to generate a custom stylesheet. Below is an overview of the available options:Future improvements
The CLI could be moved to a separate package (perhaps as part of #703?). This would have the following benefits:
@babel/node
,prettier
,yargs
, andcross-spawn
could be removed from the component library's prod dependencies.react
,react-dom
,@emotion/core
,@emotion/cache
,@sumup/design-tokens
could be added to prod dependencies (instead of peer), so we could run the CLI without installing it first:npx @sumup/circuit-cli static-styles --help
.There should be better documentation for the available classnames. We might be able to build a Storybook addon similar to Storybook's PropsTable to extract and display them.
Definition of done