Button
Style-agnostic button component using CSS custom properties.
Preview
python
button(variant='primary', size='md', text='Primary')Usage
views.py
python
from djust import LiveView
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.variant = 'primary'
self.size = 'md'
self.text = 'Primary'my_template.html
django
{% load theme_components %}
{% theme_button variant=variant size=size text=text %}Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| text | str | required | — | — |
| variant | str | primary | Style variant (primary, secondary, danger, success, ghost, link, text) | |
| size | str | md | Size variant (sm, md, lg) | |
| tag | str | button | — | |
| href | Optional[str] | — | — | |
| extra_attrs | str | — | — | |
| css_prefix | str | — | — | |
| attrs | dict | — | — | |
| slot_icon | str | — | — | |
| slot_content | str | — | — | |
| slot_loading | str | — | — |
Accessibility
No additional accessibility rules are declared for this component. Keep its required semantic elements and labels when supplying the context.
Slots
slot_icon slot_content slot_loading
Source & styles
| File | Path | Notes |
|---|---|---|
| template | djust_theming/components/button.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 150, 175, 181, 187, 194, 203, 212, 221, 231. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_components/components.css | Defines 8 of this component's classes at line 432, 456, 458, 462, 468, 470, 472, 473. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_theming/scaffold.css | Defines 6 of this component's classes at line 279, 302, 307, 312, 324, 337. 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 36. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
CSS variables
--accent --accent-foreground --destructive --destructive-foreground --foreground --link --link-hover --primary --primary-foreground --primary-text --radius --ring --secondary --secondary-foreground
Template source — button.html
django
{% if tag == "a" %}
<a class="{{ css_prefix }}btn {{ css_prefix }}btn-{{ variant }} {{ css_prefix }}btn-{{ size }} {% if attrs.class %}{{ attrs.class }}{% endif %}"
{% if attrs.id %}id="{{ attrs.id }}"{% endif %}
{% if attrs.onclick %}onclick="{{ attrs.onclick }}"{% endif %}
{% if href %}href="{{ href }}"{% endif %}
{{ extra_attrs }}>
{% else %}
<button class="{{ css_prefix }}btn {{ css_prefix }}btn-{{ variant }} {{ css_prefix }}btn-{{ size }} {% if attrs.class %}{{ attrs.class }}{% endif %}"
{% if attrs.id %}id="{{ attrs.id }}"{% endif %}
{% if attrs.onclick %}onclick="{{ attrs.onclick }}"{% endif %}
{% if attrs.type %}type="{{ attrs.type }}"{% endif %}
{{ extra_attrs }}>
{% endif %}
{% if slot_loading %}{{ slot_loading|safe }}{% else %}{% if slot_icon %}{{ slot_icon|safe }} {% endif %}{% if slot_content %}{{ slot_content|safe }}{% else %}{{ text }}{% endif %}{% endif %}
{% if tag == "a" %}</a>{% else %}</button>{% endif %}