twigphp / Twig

Twig, the flexible, fast, and secure template language for PHP
https://twig.symfony.com/
BSD 3-Clause "New" or "Revised" License
8.18k stars 1.25k forks source link

[HTML Extra] html_cva - Unknown argument "default_variants" #4373

Closed setineos closed 1 month ago

setineos commented 1 month ago

With the following code I have the error below: Unknown argument "default_variants" for function "html_cva(base, variants, compound_variants, default_variant)".

{% set color = 'red' %}
{% set size = 'lg' %}

{% set alert = html_cva(
    base='alert ',
    variants={
        color: {
            blue: 'bg-blue',
            red: 'bg-red',
            green: 'bg-green',
        },
        size: {
            sm: 'text-sm',
            md: 'text-md',
            lg: 'text-lg',
        },
        rounded: {
            sm: 'rounded-sm',
            md: 'rounded-md',
            lg: 'rounded-lg',
        }
    },
    defaultVariants={
        rounded: 'md',
    }
) %}

<div class="{{ alert.apply({color, size}) }}">
    ...
</div>
jdreesen commented 1 month ago

Because the parameter is named $defaultVariant (without the s).

stof commented 1 month ago

As said in the error message, the argument is name default_variant

setineos commented 1 month ago

On https://cva.style/docs/getting-started/variants and https://ui.shadcn.com/docs/components/button , defaultVariants with an "s" is used though :).

stof commented 1 month ago

Those are not docs about Twig. This is the doc about a JS library (and I don't know why they decided to use a plural name for a setting containing a single variant)