Repository navigation
Replies: 1 comment
|
As this is a UI library with forced corporate identity we don't need App-level theming extension |
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.
@fyrst/ui0.5.0 keeps component styles as atomiccva/svadefinitions. During the 0.5.0 work we also built the alternative, Panda config recipes, all the way through (commit39b99f0), measured both against 0.4.1, and then reverted tocva/sva(commit9d05491). This discussion records what we learned, so the decision can be revisited with data instead of from scratch.TL;DR. Config recipes give app-wide theming, readable class names, override precedence by cascade layer, and generated variants. They also rename every component class, need
staticCss, and come with a layering trap that caused two real regressions.cva/svakeeps today's class names and the 0.4.x mental model, at the cost of runtime style merging, some Panda warnings, hand-written variant scales, and no app-level extension point.1. The two models, as they apply to this repo
cva/sva(current, 0.5.0)styles.tswith a staticcva(one element) orsva(slots) definition.panda libpublishes the package; apps setdesignSystem: '@fyrst/ui'. Panda extracts everycva/svadefinition from the published JS and generates atomic classes for every variant (d_inline_flex,bg-c_primary,w_37%, …).css: CssMap<slots>.withCss(styles.raw(variants).slot, override)callscss(style, override), merging the objects so each property ends up with one class and the override wins.Config recipes (built in
39b99f0, reverted)fyButton,fyAlert, …) lived inpackages/preset/src/recipes/and were registered by a library-onlycomponentsPreset.panda libbundled it intodist/panda/preset.mjs, sodesignSystemapps received it. The token-only@fyrst/ui/design-presetstayed recipe-free.@fyrst/ui/recipes) and got class strings such asfy-button fy-button--size_md fy-button--color_primary.withCss(recipeClass, override)appendedcss(override). Recipe CSS sits in Panda'srecipeslayer and overrides inutilities, so the override wins by layer order without merging objects.2. What we measured
All numbers come from this repo at 0.4.1 / 0.5.0, a packed tarball installed into a minimal
designSystemconsumer, and the Nuxt playground.staticCssstaticCss, a packed consumer only got the default variant (.fy-badge,.fy-badge--size_md). WithstaticCss: { recipes: { fyBadge: ['*'] } }on the preset, every variant was generated.BadgeRootalready gets Progress'sw_37%. CSS output was 53,244 bytes both for "Badge only" and "import everything". SostaticCssdoes not grow app CSS today. It would block tree-shaking per component later.theme.extend.recipes.fyButton.variants.size.xlin the app's config was merged over the library's recipe (fy-button--size_xlgenerated). Panda logsdesign_system_artifact_conflictas a reminder. A new variant value is not in the component's prop types, so it is only usable through the app's own recipe call.basestyles in a lower sub-layer (@layer recipes { @layer base { … } }) than variants. (1) A variant beats anybasestate selector regardless of specificity: indeterminate Progress bars rendered at 0 px becausepercent_0beat[data-state="indeterminate"]. (2) For!importantthe order inverts: abase_focusborder beat thevalid=falseborder, so a focused invalid field showed the primary border instead of red. Both were only caught by a computed-style diff against 0.4.1, not by unit tests. We added a guard test for this.panda_call_unextractable, 9imported_recipe_raw_dynamic). Config recipes: 2.cva/svain 0.5.0: 14 (12imported_recipe_raw_dynamic, 2panda_call_unextractable). The remainingimported_recipe_raw_dynamicwarnings disappear when.raw()is called next to the definition (verified on Badge); not done yet, to keep one pattern.cssvalue is only generated when written ascss.raw({…}). A bare object literal compiles and type-checks but produces no CSS. The 0.4.x playground had several such no-op overrides.cva/svamust be static literals, so Progress keeps 101 hand-writtenpercentvariants, Loader 11 sizes, and Card 9 border widths. A preset runs as code, so recipes generated them withObject.fromEntries(Progressstyles.ts: ~600 → ~100 lines).3. Pros and cons
Config recipes
Pros
panda.config.ts(theme.extend.recipes.fyButton). Withcva/svathe only lever is a per-instancecssoverride or global CSS against atomic classes.utilitiesalways beatsrecipes, so overrides are a cheap class append. No style objects are merged at runtime per render..fy-button--size_mdand.fy-alert__rootwork as test selectors, in devtools, and as hooks for consumer CSS. Atomic names say nothing about which component they belong to.FyButtonVariantProps) from Panda's codegen.Cons
basesub-layer trap. Variants silently outrankbasestate selectors, andbase!importantsilently outranks variants. Both bit us. Every new recipe has to respect this; a guard test helps but does not catch everything (it checks for overlaps, not for intent).staticCssis mandatory for a design system whose variants come from props. That emits every variant into every app forever and closes the door on per-component tree-shaking.fy*prefix). An app recipe with the same key merges into the library's.cva/svaPros
utilitieslayer; no hidden sub-layers. The 0.4.1 behavior (focus/hover on invalid fields, indeterminate Progress) holds with no special cases.styles.tssits next to the component that uses it.panda lib/designSystemsince 0.3.0, including the stale-buildinfo re-extraction fallback.Cons
cssoverride on every instance, or global CSS against atomic classes.withCssmust merge style objects (css(style, override)); appending a class would leave two competing atomic classes and let stylesheet order decide. This costs a little at runtime and must not be "simplified" (a test guards it).imported_recipe_raw_dynamicwarnings (12) unless.raw()moves into helpers next to each definition.4. Side-by-side
cva/svafy-button--size_md(semantic)bg-c_primary,w_37%(atomic)theme.extend.recipes.*css, or global CSS)css(style, override))staticCssstaticCssbasesub-layer (2 regressions found)5. Options
cva/sva(current). Optional follow-ups: move.raw()into helpers in eachstyles.tsto drop the 12 warnings; add adata-part/ stable class hook for tests if needed.39b99f0implementation exists and passes the full test suite plus the visual diff). Ship it with the guard test for the layering trap, the migration notes for class names, and a measured CSS size comparison.cva/sva, and expose config recipes only for the few components apps most want to theme globally (Button, Field controls, Card). Two patterns in one codebase is the cost.6. Questions for maintainers and consumers
cssoverrides enough?staticCss(required by config recipes) works against it.Reference commits on branch
ccr-51512907-w98cka:39b99f0(config recipes),9d05491(back tocva/sva, current). Background:changelog/2026-10-31-0.5.0-overrides-and-cleanup.md.All reactions