PHPackages                             missionx-co/cva-php - 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. missionx-co/cva-php

ActiveLibrary

missionx-co/cva-php
===================

Class Variance Authority implementation in PHP

1.2.0(11mo ago)11.8k↓31.8%MITPHPPHP ^8.3

Since Jun 2Pushed 11mo agoCompare

[ Source](https://github.com/missionx-co/cva-php)[ Packagist](https://packagist.org/packages/missionx-co/cva-php)[ Docs](https://github.com/mission-x/cva-php)[ RSS](/packages/missionx-co-cva-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (8)Used By (0)

Class Variance Authority for PHP
================================

[](#class-variance-authority-for-php)

Class Variance Authority implementation in PHP.

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

[](#installation)

```
composer require missionx-co/cva-php
```

Usage
-----

[](#usage)

### Basic Example

[](#basic-example)

```
use MissionX\ClassVariantAuthority\ClassVariantAuthority;
use MissionX\ClassVariantAuthority\Option;

// Create a button component with variants
$button = ClassVariantAuthority::parse([
    'base' => 'text-sm px-3 py-2 rounded-md',
    'variants' => [
        'color' => [
            'primary' => 'bg-blue-500 text-white',
            'secondary' => 'bg-gray-200 text-gray-800',
            'danger' => 'bg-red-500 text-white',
        ],
        'size' => [
            'sm' => 'px-2 py-1 text-xs',
            'md' => 'px-3 py-2 text-sm',
            'lg' => 'px-4 py-3 text-base',
        ],
    ],
    'compound_variants' => [
        [
            'color' => 'primary',
            'size' => 'lg',
            'class' => 'font-bold',
        ],
    ],
    'default_variants' => [
        'size' => 'md',
        'color' => 'primary',
    ],
]);

// Use the component
echo $button(); // "text-sm px-3 py-2 rounded-md bg-blue-500 text-white"
echo $button(['size' => 'lg']); // "text-sm px-4 py-3 rounded-md bg-blue-500 text-white text-base font-bold"
echo $button(['color' => 'secondary']); // "text-sm px-3 py-2 rounded-md bg-gray-200 text-gray-800"
```

### Builder API

[](#builder-api)

You can also use the builder API to create components:

```
use MissionX\ClassVariantAuthority\ClassVariantAuthority;
use MissionX\ClassVariantAuthority\CompoundVariants;
use MissionX\ClassVariantAuthority\Variant;
use MissionX\ClassVariantAuthority\Option;

$button = ClassVariantAuthority::make()
    ->setBase('text-sm px-3 py-2 rounded-md')
    ->addVariant(
        Variant::make('color')
            ->add('primary', 'bg-blue-500 text-white')
            ->add('secondary', 'bg-gray-200 text-gray-800')
            ->add('danger', 'bg-red-500 text-white')
    )
    ->addVariant(
        Variant::make('size')
            ->add('sm', 'px-2 py-1 text-xs')
            ->add('md', 'px-3 py-2 text-sm')
            ->add('lg', 'px-4 py-3 text-base')
    )
    ->addCompoundVariants(
        CompoundVariants::make()
            ->where('color', 'primary')
            ->where('size', 'lg')
            ->setClasses('font-bold')
    )
    ->setDefaultVariants([
        'size' => 'md',
        'color' => 'primary',
    ]);

// Use the component
echo $button(['color' => 'danger', 'size' => 'sm']);
```

Features
--------

[](#features)

- Type-safe variant definitions
- Compound variants for complex combinations
- Default variants
- Automatic class merging using [TailwindMerge](https://github.com/gehrisandro/tailwind-merge-php)
- Fluent builder API

Configuration
-------------

[](#configuration)

You can pass configuration to the underlying TailwindMerge package using the `withConfig` method:

```
use MissionX\ClassVariantAuthority\Config;

$config = new Config();
$config->tailwindMergeConfig = [
    // TailwindMerge configuration
];

// Add cache for better performance
$config->cache = new YourCacheImplementation();

// Create instance with config
$button = ClassVariantAuthority::withConfig($config)
    ->setBase('text-base')
    // Add variants...
    ;

// Or add config to existing instance
$button = ClassVariantAuthority::make()
    ->setBase('text-base')
    ->setConfig($config);
```

Credits
-------

[](#credits)

- Original JavaScript package: [class-variance-authority](https://www.npmjs.com/package/class-variance-authority)
- Created by [Mohammed Manssour](https://github.com/mohammedmanssour)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance51

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

7

Last Release

349d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/aeb75f35979097845cce704062910a6a8c85bc0a7b49b081df7350a4f20023fc?d=identicon)[manssour.mohammed](/maintainers/manssour.mohammed)

---

Top Contributors

[![mohammedmanssour](https://avatars.githubusercontent.com/u/19733629?v=4)](https://github.com/mohammedmanssour "mohammedmanssour (12 commits)")

---

Tags

Mission Xcva-php

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/missionx-co-cva-php/health.svg)

```
[![Health](https://phpackages.com/badges/missionx-co-cva-php/health.svg)](https://phpackages.com/packages/missionx-co-cva-php)
```

###  Alternatives

[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[tobimori/kirby-tailwind-merge

Tailwind Merge for Kirby CMS

276.3k](/packages/tobimori-kirby-tailwind-merge)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
