derweili/cva-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

derweili/cva-php

最新稳定版本:0.1.0

Composer 安装命令:

composer require derweili/cva-php

包简介

PHP clone of class-variance-authority (CVA)

README 文档

README

A PHP clone of the class-variance-authority (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

composer require derweili/cva-php

Usage

1. Clsx::cx — 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

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

composer test

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-12