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'my_template.html
django
{% load theme_components %}
{% theme_button variant=variant size='md' text='Primary' %}Props
| Name | Type | Required | Default |
|---|---|---|---|
| text | str | required | — |
| variant | str | primary | |
| size | str | md | |
| css_prefix | str | — | |
| attrs | dict | — | |
| slot_icon | str | — | |
| slot_content | str | — | |
| slot_loading | str | — |
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 131, 155, 161, 167, 174, 183, 192, 201, 211. 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 430, 433, 435, 439, 445, 447, 449, 450. 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 --radius --ring --secondary --secondary-foreground
Template source — button.html
django
<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 %}>
{% if slot_loading %}{{ slot_loading|safe }}{% else %}{% if slot_icon %}{{ slot_icon|safe }} {% endif %}{% if slot_content %}{{ slot_content|safe }}{% else %}{{ text }}{% endif %}{% endif %}
</button>