PHP code example of derweili / cva-php

1. Go to this page and download the library: Download derweili/cva-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

derweili / cva-php example snippets


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'

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"
bash
composer