feature-ninja / cva
Class variance authority implementation in php
Fund package maintenance!
feature-ninja
Installs: 2 447
Dependents: 2
Suggesters: 0
Security: 0
Stars: 10
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^8.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.21.1
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.3.2
This package is auto-updated.
Last update: 2024-11-25 21:38:56 UTC
README
Class Variance Authority implementation in PHP
Installation
You can install the package via composer:
composer require feature-ninja/cva
Usage
use FeatureNinja\Cva\ClassVarianceAuthority; $button = ClassVarianceAuthority::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', ], ], ); # Or by using the cva helper function $button = fn\cva( ['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
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.