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

RFC: Expose interface for custom CSSObject declaration #2023

Closed
wants to merge 2 commits into from

Conversation

tpict
Copy link

@tpict tpict commented Sep 24, 2020

What:

Modifications to @emotion/serialize/types so that the user may specify a custom CSSObject declaration in preference to the default.

Why:

  • To allow users to constrain what styles may be applied at any leaf in their React tree
  • To allow users to opt-out of arbitrary CSS selectors etc

How:
The existing CSSObject is renamed to DefaultCSSObject. A new, empty interface named CustomCSSObject is added. Finally, a new type named CSSObject is exported that takes the value of CustomCSSObject is it's provided, otherwise DefaultCSSObject. Users can augment CustomCSSObject in their project to override the value of CSSObject globally. This shouldn't have any impact on users who don't provide their own declaration.

Checklist:

  • Documentation
  • Tests
  • Code complete
  • Changeset

I'm not sure if/how this can be tested without splitting dtslint into two stages, since declaring a CustomCSSObject anywhere changes the value globally. Feedback appreciated!

@changeset-bot
Copy link

changeset-bot bot commented Sep 24, 2020

🦋 Changeset detected

Latest commit: 5b691b6

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5b691b6:

Sandbox Source
Emotion Configuration

@Andarist
Copy link
Member

Please describe what issue this tries to solve.

@tpict
Copy link
Author

tpict commented Sep 24, 2020

The issue is the difficulty of enforcing design constraints in a large-scale React application where styles can be freely applied to any component. This change would allow design constraints to be enforced at compile time. For example, if my designer prescribes a palette of 12 colors only, any violations of that constraint could be reported in CI.

It would be useful even for ad-hoc styling. CSSType has certain limitations. The README describes how to work around missing properties, but missing values are a possibility too:

// this results in a TS2322 error
<div css={{ fontWeight: "var(--verybold)" }}>
  Hello world
</div>

Of course you can work around this on a case-by-case basis, but that gets pretty tiresome, and there's no autocomplete hint for values that are implicitly valid in your environment.

@Andarist Andarist closed this Nov 12, 2020
@Andarist Andarist deleted the branch emotion-js:next November 12, 2020 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants