Badge
A small element that displays status, counts, or labels with optional icons.
Loading...
<twig:Badge>Badge</twig:Badge>
Installation
Ensure the Symfony UX Toolkit is installed in your Symfony app:
$ composer require --dev symfony/ux-toolkit
Then, run the following command to install the component and its dependencies:
$ bin/console ux:install badge --kit shadcn
The UX Toolkit is not mandatory to install a component. You can install it manually by following the next steps:
- Copy the following file(s) into your Symfony app:
templates/components/Badge.html.twig{# @prop variant 'default'|'secondary'|'destructive'|'outline' The variant, default to `default` #} {# @block content The default block #} {%- props variant = 'default' -%} {%- set style = html_cva( base: 'inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2', variants: { variant: { default: 'border-transparent bg-primary text-primary-foreground', secondary: 'border-transparent bg-secondary text-secondary-foreground', destructive: 'border-transparent bg-destructive text-destructive-foreground', outline: 'text-foreground', }, }, ) -%} <div class="{{ style.apply({variant: variant}, attributes.render('class'))|tailwind_merge }}" {{ attributes }} > {%- block content %}{% endblock -%} </div>
- If necessary, install the following Composer dependencies:
$ composer require twig/extra-bundle twig/html-extra:^3.12.0 tales-from-a-dev/twig-tailwind-extra:^1.0.0
- And the most important, enjoy!
Usage
<twig:Badge>Badge</twig:Badge>
Examples
Default
Loading...
<twig:Badge>Badge</twig:Badge>
Secondary
Loading...
<twig:Badge variant="secondary"> Badge </twig:Badge>
Outline
Loading...
<twig:Badge variant="outline"> Badge </twig:Badge>
Destructive
Loading...
<twig:Badge variant="destructive"> Badge </twig:Badge>
With Icon
Loading...
<twig:Badge> <twig:ux:icon name="lucide:check" class="mr-1 h-3 w-3" /> Verified </twig:Badge>
API Reference
Badge
| Prop | Type | Description |
|---|---|---|
variant |
'default'|'secondary'|'destructive'|'outline' |
The variant, default to default |
| Block | Description |
|---|---|
content |
The default block |