Local CSS vars optimization within recipe #1199
yumin-chen
started this conversation in
Ideas
Replies: 1 comment
-
I had this need and it was satisfied with Virtual Color |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Feature Request
Automatic Recipe Optimizer
I would like to suggest a feature that would automatically optimize local CSS variables declared within Panda recipes. Currently, I can declare CSS variables within a variant, such as
colorScheme
, and use them in other variants. However, this sometimes leads to unused variables in the final CSS output, depending on the combination of variants I choose.Problem Statement/Justification
For example, in the recipe below, some CSS variables are only used in the
subtle
look, but not in thesolid
look. If I select thecolorScheme
to beblue
and thelook
to besolid
, I would end up with some redundant variables. Such as the example below,--color-a2
is not used by solid, and--color-a3
is not used by subtle, and they should not used in the final CSS output. Those CSS variables are being surfaced on the client side in the users' browser consuming RAM.One way to solve this problem is to use
compoundVariants
to define the combinations of variants that use specific CSS variables, and remove them from the other variants. However, this can be very verbose and result in numerous combinations for this use case. It results in very ugly and unreadable code (at least in this case, we're seeing a large number of declarations needed to achieve very small optimization).On a separate note, if we could support hashing for local CSS variable names, that'd be perfect!
Real World Example
Below recipe is for a Badge component, it has all local CSS variables (colors) declared within
colorScheme
variant, and those CSS variables are then being used in other variants. If we were to usecompoundVariants
in order to clean up unused CSS variables, it would result in 12 different permutations.Proposed Solution or API
We could have a preprocessor to parse the recipe and track all local CSS variables declared within the recipe, and iterates over the variants looking for any corresponding CSS variables usage, and automatically generate the corresponding
compoundVariants
fromvariants
.Alternatives
No response
Additional Information
No response
Beta Was this translation helpful? Give feedback.
All reactions