Skip to content

feat(class-variance): class-variance authority with slot support, and conflict-aware merging#2105

Open
iamdadmin wants to merge 8 commits intotempestphp:3.xfrom
iamdadmin:3.x-class-variance
Open

feat(class-variance): class-variance authority with slot support, and conflict-aware merging#2105
iamdadmin wants to merge 8 commits intotempestphp:3.xfrom
iamdadmin:3.x-class-variance

Conversation

@iamdadmin
Copy link
Copy Markdown
Contributor

@iamdadmin iamdadmin commented Apr 4, 2026

tempest/class-variance - a PHP package for building component CSS class strings with variants, compound variants, slot support, and conflict-aware merging. Heavily inspired by CVA and Tailwind-Variants, but with the ability to extend and support other CSS frameworks also.

Two flavours:

  • cv() — separator-based merging, framework-agnostic CSS, somewhat limited by default but can be extended to support other frameworks.
  • tv() — builds on cv() with Tailwind-aware merging, aiming to provide the same outcomes as tailwind-merge.

Main features

  • Implements syntax similar to that of CVA and Tailwind-Variants, supporting slot, variants, compoundVariants and defaultVariants,
  • Note: internally, it assumes 'base' to be the default slot, as per Tailwind-Variants,
  • Can be extended to support additional frameworks in the future (contribs welcome),
  • Can be installed standalone, although recommended to at least use with tempest/discovery,
  • initialize once, use many, the tailwind config is quite large and other frameworks likely will be also, so this way it's not initialized many, many times throughout the application,
  • Supports custom configs for Tailwind again inspired by Tailwind-Variants, supporting prefixes, separators, and you can both merge and overwrite the Tailwind config through custom configs.

Why this? / Notes

This is the biggest bit of work I've done; it's based on a fork I put together over here but attempting to fully adopt Tempest paradigms for integration.

Previously discussed with innocenzi in the discord about whether this would be welcome as a contrib ... so I hope you like it and I'm happy to work on any and all feedback and suggestions.

Acknowledgements / license

All code that went into this from my original fork was released under the MIT license (not much in the end, but it was a rough basis). CVA and Tailwind-Variants are both JS-sphere packages and no actual code was taken from these, not even as a pseudo-conversion to PHP. It's a ground-up implementation of similar syntax, which delivers similar outcomes, and is separate code entirely, however this package could not exist without their work, and the work of their inspirations. There's also an import from a MIT-licensed tailwind-merge package, with acknowledgements in the comments therein.

(If suited, I can put together a detailed ACKNOWLEDGEMENTS.md for this package specifically?)

@iamdadmin iamdadmin changed the title feat(class-variance): CSS class strings with variants, compound variants, slot support, and conflict-aware merging feat(class-variance): CSS class-variance authority with slot support, and conflict-aware merging Apr 4, 2026
@iamdadmin iamdadmin changed the title feat(class-variance): CSS class-variance authority with slot support, and conflict-aware merging feat(class-variance): class-variance authority with slot support, and conflict-aware merging Apr 4, 2026
@iamdadmin
Copy link
Copy Markdown
Contributor Author

The failing test is a CI issue, it couldn't pull redis image so didn't complete. If someone could re-run just that single one that'd be great.

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.

1 participant