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

NameTypeDefaultDescription
namestr''form field name
valuestr'#3B82F6'current hex color value
eventstr — renames the event''dj-click/dj-input event name
labelstr''label text
swatcheslist | NoneNonelist of hex color strings
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 481, 523, 525, 789, 790, 791, 792, 794, 795. 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, 438, 445. 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 1114, 1453. Override those rules, or the custom properties they read, in a stylesheet loaded after it.