Alert

Alert component for contextual feedback messages.

template 1 required 10 optional 4 slots 1 a11y rule

Preview

variant
dismissible
Default
This is a default alert message.
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'
        self.message = 'This is a default alert message.'
        self.title = 'Default'
my_template.html
django
{% load theme_components %}
{% theme_alert variant=variant message=message title=title %}

Props

NameTypeRequiredDefaultDescription
messagestrrequired—Alert text content
titleOptional[str]——
variantstrdefaultColor variant (info, success, warning, danger)
dismissibleboolFalseWhether the alert can be dismissed
rolestralert—
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 25, 41, 45, 50, 55, 69, 81, 87, 93. 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 636, 648, 658. 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 --destructive-text --foreground --info --info-text --radius --success --success-text --warning --warning-text
Template source — alert.html
django
<div class="{{ css_prefix }}alert {{ css_prefix }}alert-{{ variant }} {% if attrs.class %}{{ attrs.class }}{% endif %}"
     {% if role == "status" %}role="status"{% elif role == "log" %}role="log"{% else %}role="alert"{% endif %}
     {% 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>