Badge

Style-agnostic badge component using CSS custom properties.

template 1 required4 optional1 slot0 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'
my_template.html
django
{% load theme_components %}
{% theme_badge variant=variant text='Default' %}

Props

NameTypeRequiredDefault
textstrrequired
variantstrdefault
css_prefixstr
attrsdict
slot_contentstr

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 84, 96, 101, 106, 111, 116. 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 570, 585, 595, 600. 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>