Color Picker

Color picker with swatches component.

python 7 params

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 = value
my_template.html
django
{{ component }}

Events this component sends to the view: set_color.

Parameters

NameTypeDefault
namestr''
valuestr'#3B82F6'
eventstr — renames the event''
labelstr''
swatcheslist | NoneNone
custom_classstr''
**kwargs— passed to `Component.__init__`: `id=` sets `component.id`, and any other keyword is kept as state
Source & styles
FilePathNotes
moduledjust.components.components.color_pickerSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 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.
cssdjust_theming/scaffold.cssDefines 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.
cssdjust_theming/components.cssDefines 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.