Alert

Style-agnostic alert component using CSS custom properties.

template 1 required9 optional4 slots1 a11y rule

Preview

variant
dismissible
python
alert(variant='default', message='This is a default alert message.', title='Default')

Usage

views.py
python
from djust import LiveView


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.variant = 'default'
my_template.html
django
{% load theme_components %}
{% theme_alert variant=variant message='This is a default alert message.' title='Default' %}

Props

NameTypeRequiredDefault
messagestrrequired
titleOptional[str]
variantstrdefault
dismissibleboolFalse
css_prefixstr
attrsdict
slot_iconstr
slot_messagestr
slot_actionsstr
slot_dismissstr

Accessibility

RequirementElementAttributeValue
Alert container must have role=alertdivrolealert

Slots

slot_icon slot_message slot_actions slot_dismiss
Source & styles
FilePathNotes
templatedjust_theming/components/alert.htmlCopy it to the same path in your project, or per theme under djust_theming/themes/<theme>/components/.
cssdjust_theming/components.cssDefines 9 of this component's classes at line 16, 28, 32, 37, 42, 56, 62, 68, 74. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_components/components.cssDefines 5 of this component's classes at line 411, 413, 414, 424, 425. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_theming/scaffold.cssDefines 3 of this component's classes at line 634, 646, 656. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_theming/performance.cssDefines 1 of this component's classes at line 39. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
CSS variables
--background --border --destructive --foreground --radius --success --warning
Template source — alert.html
django
<div class="{{ css_prefix }}alert {{ css_prefix }}alert-{{ variant }} {% if attrs.class %}{{ attrs.class }}{% endif %}"
     role="alert"
     {% if attrs.id %}id="{{ attrs.id }}"{% endif %}>
    {% if slot_icon %}
    <div class="{{ css_prefix }}alert-icon">
        {{ slot_icon|safe }}
    </div>
    {% endif %}
    <div class="{{ css_prefix }}alert-content">
        {% if title %}
        <div class="{{ css_prefix }}alert-title">{{ title }}</div>
        {% endif %}
        {% if slot_message %}{{ slot_message|safe }}{% else %}<div class="{{ css_prefix }}alert-message">{{ message }}</div>{% endif %}
    </div>
    {% if slot_actions %}
    <div class="{{ css_prefix }}alert-actions">
        {{ slot_actions|safe }}
    </div>
    {% endif %}
    {% if dismissible %}
        {% if slot_dismiss %}
        {{ slot_dismiss|safe }}
        {% else %}
        <button class="{{ css_prefix }}alert-dismiss" onclick="this.parentElement.remove()" aria-label="Dismiss">
            <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <line x1="18" y1="6" x2="6" y2="18"></line>
                <line x1="6" y1="6" x2="18" y2="18"></line>
            </svg>
        </button>
        {% endif %}
    {% endif %}
</div>