Skip to content
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

Extract static styles #479

Closed
connor-baer opened this issue Sep 24, 2019 · 2 comments · Fixed by #477
Closed

Extract static styles #479

connor-baer opened this issue Sep 24, 2019 · 2 comments · Fixed by #477
Labels
📝 RFC Request for comment
Milestone

Comments

@connor-baer
Copy link
Member

Follow-up to #92 and #94.

Purpose

There are some frontend 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. This would be solved if we could somehow get the styles from the React components as plain CSS. This is exactly what static style extraction aims to achieve.

Requirements

  • Readable and intuitive class names ideally using BEM style
  • Small file size (exclude CSS for unused components)
  • Include global base styles
  • Hosted and versioned
  • Documentation with usage examples
  • Bonus: change the theme at runtime

Enabling constraints

Some of these requirements are only possible through enabling constraints:

  1. Every style block needs a unique, constant BEM style label
  2. Props with infinite possible values can't be directely interpolated in the CSS:
// This can't be statically extracted.
// 0 <= top <= ∞;
const styles = ({ top }) => css`
  label: component;
  position: absolute;
  top: ${top};
`;

// This is okay.
// spacing = kilo | mega | giga
const positionStyles = ({ theme, spacing }) => spacing && css`
  label: component--${spacing};
  position: absolute;
  top: ${theme.spacings[spacings]};
`;
  1. Components that rely on JavaScript (JS) for their functionality will need custom vanilla JS code to work. Circuit UI might provide code examples, but currently doesn't include or maintain these scripts.

Potential downsides

The above constraints limit some of the advantages that CSS-in-JS brings (e.g. dynamic style props). Changes to components will need to be tested in React and plain CSS.

@ilyanoskov
Copy link
Contributor

🎉 This issue has been resolved in version 1.2.2-canary.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ilyanoskov
Copy link
Contributor

🎉 This issue has been resolved in version 1.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📝 RFC Request for comment
Projects
None yet
2 participants