Color Picker
Color picker with swatches component.
Preview
Arguments
color_picker(name='accent', event='set_color', value='#3b82f6', label='Accent', swatches=['#3b82f6', '#10b981', '#f59e0b', '#ef4444'])
Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import ColorPicker
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = ColorPicker(name='accent', event='set_color', value='#3b82f6', label='Accent', swatches=['#3b82f6', '#10b981', '#f59e0b', '#ef4444'])
@event_handler()
def set_color(self, value, **kwargs):
self.component.value = valuemy_template.html
django
{{ component }}Events this component sends to the view: set_color.
Parameters
| Name | Type | Default |
|---|---|---|
| name | str | '' |
| value | str | '#3B82F6' |
| event | str — renames the event | '' |
| label | str | '' |
| swatches | list | None | None |
| custom_class | str | '' |
| **kwargs | — passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.color_picker | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 9 of this component's classes at line 458, 500, 502, 763, 764, 765, 766, 768, 769. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_theming/scaffold.css | Defines 3 of this component's classes at line 418, 437, 444. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |
| css | djust_theming/components.css | Defines 2 of this component's classes at line 1045, 1378. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |