feat: Support for external CSS preprecessors #991
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This tiny PR* adds support for external CSS preprocessors. Specifically, it allows devs to define a preprocessor function via their config, which will be called before Stitches walks through a style object.
Basically, this gives devs the power of utils, but everywhere, including when other devs (or consumers of your design system) use native CSS props instead of your custom utils.
Rationale
Utils are awesome, but you can only get that power through use of the util — if a consumer of your design system uses standard CSS properties, you have no way to add value there.
Sample Use Case
I'm creating a design system that is insanely easy to localize, including for RTL languages. If a dev creates a style of
borderRadius: 0 $4 $4 0
, we can easily understand that this element has rounded top-right and bottom-right corners; that makes it easy to translate this to a RTL layout asborderRadius: $4 0 0 $4
.While this could be done with a custom util, the issue is that if a consumer of my design system uses the standard CSS prop
borderRadius
, I lose the ability to auto-translate directional styles for them.Having an interface to the CSS objects before they get processed gives me the ability to translate all LTR directional styles into RTL directional styles, automagically.
Proposed Interface
Simple as can be. This PR includes a passthrough default function, in case a user doesn't define one.
*—I'd be happy to add some tests, and even write up some draft documentation, but didn't want to commit that time until I heard that the core team was willing to accept this feature.