v0.0.2
Demos (demo panel, opens in a new tab)

Color field

A colour field that pairs a text box holding the #rrggbb value with the browser's colour picker.

zb:color-input zubazar/ui · free (MIT)

Basic usage

Basic usage: view
BLADE

The value box is the form's field; wire:model, name, required and the validation error go on it.

blade
<div class="space-y-4">
    <zb:color-input wire:model="urun_rengi" label="Product colour" hint="For example #c2410c" />
    <zb:color-input name="marka_rengi" label="Brand colour" value="#2563eb" />
</div>
PropValues
labelThe value box's label
value#rrggbb; without it the wire:model property's value

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
label—nullLabel; with the required attribute a * follows it
name—nullField name; without it the wire:model value
value—null#rrggbb; without it the wire:model property's value, else empty (the picker starts black)
hint—nullHelp text below while there is no error
input-class—nullThe value box's own classes
(attributes)— — class, style, x-show, wire:key… go on the whole field; wire:model, required, disabled, aria-*, data-* and events on the value box. disabled turns the picker off too

Developer notes

Events, hooks and details
  • The box and the picker follow each other: a colour picked fills the box and wire:model, x-model hear it; a value typed (#c2410c, #abc or c2410c) moves the picker.
  • Validate the value on the server too: regex:/^#[0-9a-fA-F]{6}$/.

Accessibility

Label
label is tied to the hex value box with <label for>; the picker is named "Label: colour picker". Both are reached with Tab.
Hint and error
hint or the validation error is tied to the value box with aria-describedby; with an error the box gets aria-invalid="true".
Without JavaScript
The value box is a plain text field: the colour is typed as #rrggbb and the form is sent. The picker is only a convenience.