vewe / classvariance
Vewe ClassVariance, an all-PHP combined implementation of Class Variance Authority, twMerge, and Tailwind-Variants
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/vewe/classvariance
Requires
- php: 8.4.* || 8.5.*
Requires (Dev)
- carthage-software/mago: ^1
- phpunit/phpunit: ^12.0
This package is auto-updated.
Last update: 2026-02-08 09:15:22 UTC
README
About
Aiming to be an all-PHP combined implementation of Class Variance Authority, twMerge, and Tailwind-Variants.
Supporting the current version of PHP, less one, as a minimum requirement, to keep the package freshly maintained and utilising the latest features of PHP.
Version Strategy
Based on semantic versioning, with the following constraints
- 1.x.x releases support PHP8.4, PHP8.5
- 2.x.x releases support PHP8.5, PHP8.6
- 3.x.x releases support PHP8.6, PHP-Next (tbc)
Major point releases may introduce breaking changes, which will be in the release notes.
Minor point releases should be non-breaking changes and fixes.
Installation
You can install the package via composer:
composer require vewe/classvariance
Usage
Cv, with slots, akin to Tailwind-Variants
use Vewe\ClassVariance\Cv; $button = Cv::new( ['font-semibold', 'border', 'rounded'], [ 'variants' => [ 'intent' => [ 'primary' => ['bg-blue-500', 'text-white', 'border-transparent', 'hover:bg-blue-600'], 'secondary' => 'bg-white text-gray-800 border-gray-400 hover:bg-gray-100', ], 'size' => [ 'small' => ['text-sm', 'py-1', 'px-2'], 'medium' => 'text-base py-2 px-4', ], ], 'compoundVariants' => [ [ 'intent' => 'primary', 'size' => 'medium', 'class' => 'uppercase', ], ], 'defaultVariants' => [ 'intent' => 'primary', 'size' => 'medium', ], ], );
<button class="<?= $button(); ?>">Submit</button> <button class="<?= $button(['intent' => 'secondary', 'size' => 'small']); ?>">Submit</button>
Cv utility, without slots
use Vewe\ClassVariance\Cv; $button = Cv::new( ['font-semibold', 'border', 'rounded'], [ 'variants' => [ 'intent' => [ 'primary' => ['bg-blue-500', 'text-white', 'border-transparent', 'hover:bg-blue-600'], 'secondary' => 'bg-white text-gray-800 border-gray-400 hover:bg-gray-100', ], 'size' => [ 'small' => ['text-sm', 'py-1', 'px-2'], 'medium' => 'text-base py-2 px-4', ], ], 'compoundVariants' => [ [ 'intent' => 'primary', 'size' => 'medium', 'class' => 'uppercase', ], ], 'defaultVariants' => [ 'intent' => 'primary', 'size' => 'medium', ], ], );
<button class="<?= $button(); ?>">Submit</button> <button class="<?= $button(['intent' => 'secondary', 'size' => 'small']); ?>">Submit</button>
Testing
composer test
Acknowledgements
Thank you to the following, without whom this package would not exist.
- CVA by Roj Vroemen and contributors
- Class Variance Authority by Joe Bell
- Tailwind-Variants by Junior Garcia @jrgarciadev, Tianen Pang @tianenpang and contributors
- Tailwind-merge by Romain Monteil which is based on Tailwind-merge-php by Sandro Gehri and contributors
License
The MIT License (MIT). Please see License File for more information.