Toast

Style-agnostic toast notification component using CSS custom properties.

template 1 required7 optional2 slots2 a11y rules

Preview

variant
This is a success toast notification.
python
toast(variant='success', message='This is a success toast notification.')

Usage

views.py
python
from djust import LiveView


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

    def mount(self, request, **kwargs):
        self.variant = 'success'
my_template.html
django
{% load theme_components %}
{% theme_toast variant=variant message='This is a success toast notification.' %}

Props

NameTypeRequiredDefault
messagestrrequired
variantstrinfo
positionstrtop-right
durationint5000
css_prefixstr
attrsdict
slot_messagestr
slot_actionsstr

Accessibility

RequirementElementAttributeValue
Toast must have role=statusdivrolestatus
Toast must have aria-live=politedivaria-livepolite

Slots

slot_message slot_actions
Source & styles
FilePathNotes
templatedjust_theming/components/toast.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 812, 826, 846, 850, 861, 876, 882, 888, 894. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_components/components.cssDefines 7 of this component's classes at line 99, 100, 101, 102, 103, 109, 110. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_theming/print.cssDefines 1 of this component's classes at line 18. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_theming/scaffold.cssDefines 1 of this component's classes at line 774. 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 — toast.html
django
<div class="{{ css_prefix }}toast {{ css_prefix }}toast-{{ variant }} {{ css_prefix }}toast-{{ position }} {% if attrs.class %}{{ attrs.class }}{% endif %}"
     role="status"
     aria-live="polite"
     data-theme-toast
     data-duration="{{ duration }}"
     {% if attrs.id %}id="{{ attrs.id }}"{% endif %}>
    <div class="{{ css_prefix }}toast-content">
        {% if slot_message %}{{ slot_message|safe }}{% else %}<div class="{{ css_prefix }}toast-message">{{ message }}</div>{% endif %}
    </div>
    {% if slot_actions %}
    <div class="{{ css_prefix }}toast-actions">
        {{ slot_actions|safe }}
    </div>
    {% endif %}
    <button class="{{ css_prefix }}toast-close" onclick="this.parentElement.remove()" aria-label="Dismiss">
        <svg width="14" height="14" 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>
</div>