PHPackages                             derweili/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. derweili/cva-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

derweili/cva-php
================

PHP clone of class-variance-authority (CVA)

0.1.0(11mo ago)02MITPHPPHP ^8.1CI passing

Since Jun 12Pushed 11mo agoCompare

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

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

cva-php
=======

[](#cva-php)

A PHP clone of the [class-variance-authority (CVA)](https://github.com/joe-bell/cva) utility, inspired by the original npm package. This package provides utility functions for composing CSS class names based on variants, similar to the original JavaScript/TypeScript version.

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

[](#installation)

```
composer require derweili/cva-php
```

Usage
-----

[](#usage)

### 1. `Clsx::cx` — Class Name Combiner

[](#1-clsxcx--class-name-combiner)

Combine class names, arrays, and objects into a single string, ignoring falsy values (like `null`, `false`, `0`, empty string, etc.).

```
use CvaPhp\Clsx;

// Simple usage
$class = Clsx::cx('foo', null, 'bar', ['baz', false, 'qux']);
// $class === 'foo bar baz qux'

// With associative arrays (object syntax)
$class = Clsx::cx(['foo' => true, 'bar' => false, 'baz' => true]);
// $class === 'foo baz'
```

### 2. `Cva::cva` — Class Variance Authority

[](#2-cvacva--class-variance-authority)

Create a function that generates class names based on variants and options.

```
use CvaPhp\Cva;

$button = Cva::cva('button', [
    'variants' => [
        'intent' => [
            'primary' => 'button--primary',
            'secondary' => 'button--secondary',
        ],
        'size' => [
            'small' => 'button--small',
            'large' => 'button--large',
        ],
    ],
    'compoundVariants' => [
        [
            'intent' => 'primary',
            'size' => 'large',
            'class' => 'button--primary-large',
        ],
    ],
    'defaultVariants' => [
        'intent' => 'primary',
        'size' => 'small',
    ],
]);

// Usage:
echo $button(); // "button button--primary button--small"
echo $button(['intent' => 'secondary']); // "button button--secondary button--small"
echo $button(['size' => 'large']); // "button button--primary button--large button--primary-large"
echo $button(['class' => 'my-custom-class']); // "button button--primary button--small my-custom-class"
```

Running Tests
-------------

[](#running-tests)

```
composer test
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance51

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

340d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/079abd70664f8a20d627a9996ac8e38193c9dabc3ac3b7b929ebf90b4f2da488?d=identicon)[derweili](/maintainers/derweili)

---

Top Contributors

[![derweili](https://avatars.githubusercontent.com/u/6911678?v=4)](https://github.com/derweili "derweili (15 commits)")

---

Tags

phputilitycsscvaclass-variance-authority

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[tailwindphp/tailwindphp

A full port of TailwindCSS 4.x to PHP

171.7k1](/packages/tailwindphp-tailwindphp)

PHPackages © 2026

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