Badge
Style-agnostic badge component using CSS custom properties.
Preview
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
| Name | Type | Required | Default |
|---|---|---|---|
| text | str | required | — |
| variant | str | default | |
| css_prefix | str | — | |
| attrs | dict | — | |
| slot_content | str | — |
Slots
slot_content
Source & styles
| File | Path | Notes |
|---|---|---|
| template | djust_theming/components/badge.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 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. |
| css | djust_theming/scaffold.css | Defines 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. |
| css | djust_components/components.css | Defines 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. |
| css | djust_theming/performance.css | Defines 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>