WebAwesome Laminar LogoWebAwesome Laminar

Color Picker

Color pickers allow the user to select a color.

ColorPicker(_.label := "Select a color")()

This component works with standard <form> elements.

Examples

Labeled Swatches

Use swatchesProp to provide an array of colors with labels. Labels help users of screen readers identify each preset. Object arrays must be assigned as a JavaScript property; the swatches attribute still accepts a semicolon-separated string.

val swatches = js.Array(  js.Dynamic.literal(color = "#2563eb", label = "Ocean blue").asInstanceOf[ColorPicker.Swatch],  js.Dynamic.literal(color = "#16a34a", label = "Forest green").asInstanceOf[ColorPicker.Swatch],  js.Dynamic.literal(color = "#dc2626", label = "Brick red").asInstanceOf[ColorPicker.Swatch])ColorPicker(_.label := "Accent color", _.swatchesProp := swatches)()

Use placement to choose the preferred location of the popup. The popup can shift or flip to stay within the viewport.

ColorPicker(_.label := "Color", _.placement.bottomStart)()

Initial Value

Use the value attribute to set an initial value for the color picker.

ColorPicker(  _.value := "#4a90e2",  _.label := "Select a color")()

Opacity

Use the opacity attribute to enable the opacity slider. When this is enabled, the value will be displayed as HEXA, RGBA, HSLA, or HSVA based on format.

ColorPicker(  _.value   := "#f5a623ff",  _.opacity := true,  _.label   := "Select a color")()

Formats

Set the color picker's format with the format attribute. Valid options include hex, rgb, hsl, and hsv. Note that the color picker's input will accept any parsable format (including CSS color names) regardless of this option. To prevent users from toggling the format themselves, add the without-format-toggle attribute.

ColorPicker(  _.format.hex,  _.value := "#4a90e2",  _.label := "Pick a hex color")()ColorPicker(  _.format.rgb,  _.value := "rgb(80, 227, 194)",  _.label := "Pick an RGB color")()ColorPicker(  _.format.hsl,  _.value := "hsl(290, 87%, 47%)",  _.label := "Pick an HSL color")()ColorPicker(  _.format.hsv,  _.value := "hsv(55, 89%, 97%)",  _.label := "Pick an HSV color")()

Swatches

Use the swatches attribute to add convenient presets to the color picker. Any format the color picker can parse is acceptable (including CSS color names), but each value must be separated by a semicolon (;).

ColorPicker(  _.label := "Select a color",  _.swatches := "#d0021b; #f5a623; #f8e71c; #8b572a; #7ed321; #417505; #bd10e0; #9013fe; #4a90e2; #50e3c2; #b8e986; #000; #444; #888; #ccc; #fff;")()

Sizes

Use the size attribute to change the color picker's trigger size.

ColorPicker(  _.size.small,  _.label := "Select a color")()ColorPicker(  _.size.medium,  _.label := "Select a color")()ColorPicker(  _.size.large,  _.label := "Select a color")()

Disabled

The color picker can be rendered as disabled.

ColorPicker(  _.disabled := true,  _.label    := "Select a color")()

Hint

Add descriptive hint to a color picker with the hint attribute. For hints that contain HTML, use the hint slot instead.

ColorPicker(  _.label := "Select a color",  _.hint  := "Choose a color with appropriate contrast!")()

On this page