Alert

A notification component that displays important messages with an icon, title, and description.

Loading...
<div class="grid w-full max-w-xl items-start gap-4">
    <twig:Alert>
        <twig:ux:icon name="tabler:circle-check" class="h-4 w-4" />
        <twig:Alert:Title>Success! Your changes have been saved</twig:Alert:Title>
        <twig:Alert:Description>
            This is an alert with icon, title and description.
        </twig:Alert:Description>
    </twig:Alert>
    <twig:Alert>
        <twig:ux:icon name="tabler:trash" class="h-4 w-4" />
        <twig:Alert:Title>
            This Alert has a title and an icon. No description.
        </twig:Alert:Title>
    </twig:Alert>
    <twig:Alert variant="destructive">
        <twig:ux:icon name="tabler:alert-circle" class="h-4 w-4" />
        <twig:Alert:Title>Unable to process your payment.</twig:Alert:Title>
        <twig:Alert:Description>
            <p>Please verify your billing information and try again.</p>
            <ul class="list-inside list-disc text-sm">
                <li>Check your card details</li>
                <li>Ensure sufficient funds</li>
                <li>Verify billing address</li>
            </ul>
        </twig:Alert:Description>
    </twig:Alert>
</div>

Installation

bin/console ux:install alert --kit shadcn

That's it!

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

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

{# @prop variant 'default'|'destructive' The variant, default to `default` #}
{# @block content The default block #}
{%- props variant = 'default' -%}
{%- set style = html_cva(
    base: 'relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground',
    variants: {
        variant: {
            default: 'bg-background text-foreground',
            destructive: 'border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive',
        },
    },
) -%}

<div
    class="{{ style.apply({variant: variant}, attributes.render('class'))|tailwind_merge }}"
    role="alert"
    {{ attributes }}
>
    {%- block content %}{% endblock -%}
</div>
{# @block content The default block #}
<p
    class="{{ 'text-sm [&_p]:leading-relaxed ' ~ attributes.render('class')|tailwind_merge }}"
    {{ attributes }}
>
    {%- block content %}{% endblock -%}
</p>
{# @block content The default block #}
<h5
    class="{{ 'mb-1 font-medium leading-none tracking-tight ' ~ attributes.render('class')|tailwind_merge }}"
    {{ attributes }}
>
    {%- block content %}{% endblock -%}
</h5>

Happy coding!

Usage

<twig:Alert class="max-w-lg">
    <twig:ux:icon name="tabler:terminal" class="h-4 w-4" />
    <twig:Alert:Title>Heads up!</twig:Alert:Title>
    <twig:Alert:Description>
        You can add components to your app using the cli.
    </twig:Alert:Description>
</twig:Alert>

API Reference

Alert

Prop Type Description
variant 'default'|'destructive' The variant, default to default
Block Description
content The default block

Alert:Description

Block Description
content The default block

Alert:Title

Block Description
content The default block