Checkbox

A form control that allows the user to toggle between checked and unchecked states.

Loading...
<div class="flex items-center space-x-2">
    <twig:Checkbox id="terms" />
    <label for="terms" class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70">
        Accept terms and conditions
    </label>
</div>

Installation

Ensure the Symfony UX Toolkit is installed in your Symfony app:

composer require --dev symfony/ux-toolkit

Then, install the recipe and its dependencies by running:

bin/console ux:install Checkbox --kit shadcn

That's it!

Install the following Composer dependencies:

composer require tales-from-a-dev/twig-tailwind-extra:^1.0.0

Copy the following file(s) into your Symfony app:

<input
    type="checkbox"
    class="{{ 'peer size-4 inline-block align-middle accent-primary ' ~ attributes.render('class')|tailwind_merge }}"
    {{ attributes }}
>

Happy coding!

Usage

<div class="flex items-center space-x-2">
    <twig:Checkbox id="terms" />
    <label for="terms" class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70">
        Accept terms and conditions
    </label>
</div>

Examples

Default

Loading...
<div class="flex items-center space-x-2">
    <twig:Checkbox id="terms" />
    <label for="terms" class="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70">
        Accept terms and conditions
    </label>
</div>

With Label Component

Loading...
<div class="flex items-center space-x-2">
    <twig:Checkbox id="terms" />
    <twig:Label for="terms">Accept terms and conditions</twig:Label>
</div>

Disabled

Loading...
<div class="flex items-center space-x-2">
    <twig:Checkbox id="terms" disabled />
    <twig:Label for="terms">Accept terms and conditions</twig:Label>
</div>