Alert
Style-agnostic alert component using CSS custom properties.
Preview
Default
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
| Name | Type | Required | Default |
|---|---|---|---|
| message | str | required | — |
| title | Optional[str] | — | |
| variant | str | default | |
| dismissible | bool | False | |
| css_prefix | str | — | |
| attrs | dict | — | |
| slot_icon | str | — | |
| slot_message | str | — | |
| slot_actions | str | — | |
| slot_dismiss | str | — |
Accessibility
| Requirement | Element | Attribute | Value |
|---|---|---|---|
| Alert container must have role=alert | div | role | alert |
Slots
slot_icon slot_message slot_actions slot_dismiss
Source & styles
| File | Path | Notes |
|---|---|---|
| template | djust_theming/components/alert.html | Copy it to the same path in your project, or per theme under djust_theming/themes/<theme>/components/. |
| css | djust_theming/components.css | Defines 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. |
| css | djust_components/components.css | Defines 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. |
| css | djust_theming/scaffold.css | Defines 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. |
| css | djust_theming/performance.css | Defines 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>