Dojo NG is being built in the open, one section at a time — follow along on Heptapod.

API REFERENCE · FORM CONTROLS

<dj-color-picker>

An inline color picker.

It has a saturation and brightness area, a hue slider, an optional opacity slider (alpha), a text field, and optional swatches.

Try it in the playground

@dojo-ng/color-picker · v0.1.1

npm install @dojo-ng/color-picker

import "@dojo-ng/color-picker";

Value and format

  • value is a color string in the format you choose: hex, rgb, or hsl.
  • The internal model is HSV plus alpha. After you change format, reading value returns the new representation.
  • Alpha appears in the output only when the color is translucent or alpha is on.
  • Named CSS colors, such as rebeccapurple, are not parsed.
  • dj-change ({ value }) fires on every change the user makes, including during a drag. There is no separate input event.

Forms

  • The picker is form-associated. It submits the formatted color string under name.

Swatches

  • swatches is an array of color strings or { value, label } objects.

Dropdowns

  • There is no built-in trigger button or popup. Put the picker in a dj-popup to make a dropdown.

Properties

PropertyAttributeTypeDefault
format format "hex""rgb""hsl" "hex"
alpha alpha reflected boolean false
swatches Property only Swatch[] []
label label string None
name name reflected string None
disabled disabled reflected boolean false
get get string None

Events

EventDescription
dj-change{ value }

CSS parts

Style these with dj-color-picker::part(name).

areathumbhuealphainputswatchesswatchpickerlabel

CSS custom properties

PropertyDefaultDescription
--dj-color-picker-width240pxOverall width of the inline panel.

Methods

checkValidity(): booleanreportValidity(): boolean

Types

The types that the properties above use, as they are declared in the source.

Swatch

export type Swatch = string | { value: string; label?: string };