PHPackages                             feature-ninja/cva - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. feature-ninja/cva

ActiveLibrary

feature-ninja/cva
=================

Class variance authority implementation in php

0.3.1(9mo ago)1815.0k↑47.1%1[2 PRs](https://github.com/feature-ninja/cva/pulls)3MITPHPPHP ^8.2CI passing

Since Nov 17Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/feature-ninja/cva)[ Packagist](https://packagist.org/packages/feature-ninja/cva)[ Docs](https://github.com/feature-ninja/cva)[ GitHub Sponsors](https://github.com/feature-ninja)[ RSS](/packages/feature-ninja-cva/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (7)Used By (3)

cva
===

[](#cva)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2de932f832e493620c80cdba6caced12bf1975fb10132129200e3887b0d2565a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666561747572652d6e696e6a612f6376612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/feature-ninja/cva)[![Tests](https://camo.githubusercontent.com/499ce2eb176432a346cfca835b704e50157f0d7fe473f3e1ff60923ee34ddd20/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f666561747572652d6e696e6a612f6376612f72756e2d706870756e69742e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/feature-ninja/cva/actions/workflows/run-phpunit.yml)[![Total Downloads](https://camo.githubusercontent.com/99d6c4d7eaf4da95ea3e85110eac86fc0aa74ed98461fef4b879de98bbfa4bbe/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666561747572652d6e696e6a612f6376612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/feature-ninja/cva)

[Class Variance Authority](https://github.com/joe-bell/cva) implementation in PHP

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require feature-ninja/cva
```

Usage
-----

[](#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',
        ],
    ],
);
```

```
