Badge

Style-agnostic badge component using CSS custom properties.

template 1 required 4 optional 1 slot 0 a11y rules

Preview

variant
Default
python
badge(variant='default', text='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.text = 'Default'
my_template.html
django
{% load theme_components %}
{% theme_badge variant=variant text=text %}

Props

NameTypeRequiredDefaultDescription
textstrrequired——
variantstrdefaultColor variant (default, success, info, warning, danger, muted)
css_prefixstr——
attrsdict——
slot_contentstr——

Accessibility

No additional accessibility rules are declared for this component. Keep its required semantic elements and labels when supplying the context.

Slots

slot_content
Source & styles
FilePathNotes
templatedjust_theming/components/badge.htmlCopy it to the same path in your project, or per theme under djust_theming/themes/<theme>/components/.
cssdjust_theming/components.cssDefines 6 of this component's classes at line 103, 115, 120, 125, 130, 135. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_theming/scaffold.cssDefines 4 of this component's classes at line 572, 587, 597, 602. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
cssdjust_components/components.cssDefines 3 of this component's classes at line 143, 146, 149. 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 38. Override those rules, or the custom properties they read, in a stylesheet loaded after it.
CSS variables
--border --destructive --destructive-foreground --foreground --primary --primary-foreground --radius --secondary --secondary-foreground --success --success-foreground --warning --warning-foreground
Template source — badge.html
django
<span class="{{ css_prefix }}badge {{ css_prefix }}badge-{{ variant }} {% if attrs.class %}{{ attrs.class }}{% endif %}"
      {% if attrs.id %}id="{{ attrs.id }}"{% endif %}>
    {% if slot_content %}{{ slot_content|safe }}{% else %}{{ text }}{% endif %}
</span>