Corex.ColorPicker
(Corex v0.1.0-alpha.33)
View Source
Phoenix implementation of Zag.js Color Picker.
Examples
Basic
<.color_picker
id="my-color-picker"
default_value="rgb(25, 9, 192, 0.9)"
label="Select Color (RGBA)"
presets={["#ff0000", "#00ff00", "#0000ff", "rgb(25, 9, 192, 0.9)"]}
class="color-picker"
/>Styling
Target elements via data attributes:
[data-scope="color-picker"][data-part="root"] {}
[data-scope="color-picker"][data-part="label"] {}
[data-scope="color-picker"][data-part="control"] {}
[data-scope="color-picker"][data-part="trigger"] {}
[data-scope="color-picker"][data-part="content"] {}
[data-scope="color-picker"][data-part="area"] {}
[data-scope="color-picker"][data-part="channel-slider"] {}
[data-scope="color-picker"][data-part="swatch-trigger"] {}Import the Corex design:
@import "../corex/main.css";
@import "../corex/tokens/themes/neo/light.css";
@import "../corex/components/color-picker.css";Events
on_value_change/on_value_change_end- when color changes (detail:%{valueAsString: string})on_value_change_client/on_value_change_end_client- client-only variantson_open_change- when open state changes (detail:%{open: boolean})on_open_change_client- client-only varianton_format_change- when format changes (detail:%{format: string})on_pointer_down_outside/on_focus_outside/on_interact_outside- when interacting outside
API Control
Use set_open, set_value, set_format for programmatic control.
Summary
API
Sets the color format from client-side. Returns a Phoenix.LiveView.JS command.
Format must be one of: "rgba", "hsla", "hsba", "hex".
Sets the color format from server-side.
Opens or closes the color picker from client-side. Returns a Phoenix.LiveView.JS command.
Opens or closes the color picker from server-side.
Sets the color value from client-side. Returns a Phoenix.LiveView.JS command.
Value can be any color string (e.g. "#ff0000", "rgba(255, 0, 0, 1)").
Sets the color value from server-side.
Components
Attributes
id(:string) - The id of the color picker.default_value(:string) - Initial color value (e.g. rgb(25, 9, 192, 0.9) or #ff0000). Defaults tonil.value(:string) - Controlled value when controlled is true. Defaults tonil.controlled(:boolean) - Whether value is controlled externally. Defaults tofalse.name(:string) - The name attribute for form submission. Defaults tonil.label(:string) - Label for the color picker trigger. Defaults to"Select Color".format(:string) - Defaults to"rgba". Must be one of"rgba","hsla","hsba", or"hex".default_format(:string) - Defaults tonil.Must be one ofnil,"rgba","hsla","hsba", or"hex".close_on_select(:boolean) - Defaults totrue.default_open(:boolean) - Defaults tofalse.open(:boolean) - Defaults tonil.open_auto_focus(:boolean) - Defaults totrue.disabled(:boolean) - Defaults tofalse.invalid(:boolean) - Defaults tofalse.read_only(:boolean) - Defaults tofalse.required(:boolean) - Defaults tofalse.dir(:string) - Defaults tonil.Must be one ofnil,"ltr", or"rtl".positioning(:map) - Defaults to%Corex.Positioning{hide_when_detached: true, strategy: "fixed", placement: "bottom", gutter: 8, shift: 0, overflow_padding: 0, arrow_padding: 4, flip: true, slide: true, overlap: false, same_width: true, fit_viewport: false}.presets(:list) - Defaults to["#ff0000", "#00ff00", "#0000ff"].class(:string) - Defaults tonil.on_value_change(:string) - Defaults tonil.on_value_change_client(:string) - Defaults tonil.on_value_change_end(:string) - Defaults tonil.on_value_change_end_client(:string) - Defaults tonil.on_open_change(:string) - Defaults tonil.on_open_change_client(:string) - Defaults tonil.on_format_change(:string) - Defaults tonil.on_pointer_down_outside(:string) - Defaults tonil.on_focus_outside(:string) - Defaults tonil.on_interact_outside(:string) - Defaults tonil.translation(Corex.ColorPicker.Translation) - Override translatable strings. Defaults tonil.- Global attributes are accepted.
API
Sets the color format from client-side. Returns a Phoenix.LiveView.JS command.
Format must be one of: "rgba", "hsla", "hsba", "hex".
Sets the color format from server-side.
Opens or closes the color picker from client-side. Returns a Phoenix.LiveView.JS command.
Opens or closes the color picker from server-side.
Sets the color value from client-side. Returns a Phoenix.LiveView.JS command.
Value can be any color string (e.g. "#ff0000", "rgba(255, 0, 0, 1)").
Sets the color value from server-side.