Color Picker

Material Design 3 color picker web component (preset swatch grid + native color input).

  • 4.7 KB gzipped
  • @lit-material/color-picker 1.8.0
  • Renders on the server

Example

Install

npm install @lit-material/color-picker @lit-material/tokens
import "@lit-material/color-picker";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-color-picker>

Material Design 3-styled color picker — a swatch trigger that opens a popover (Popover API, the same popover="auto" foundation select/ date-picker/search use for their own popup surfaces) holding a preset color grid plus a native <input type="color"> for arbitrary values — leaning on the platform's own color picker rather than reimplementing a hue/saturation canvas from scratch.

Properties

PropertyAttributeTypeDefaultDescription
valuevaluestring""
labellabelstring""
namenamestring""
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
openopenbooleanfalse
formformstring | undefinednone
presetspresetsreadonly string[][ "#6750a4", "#625b71", "#7d5260", "#b3261e", "#006874", "#386a20", "#0061a4", "#984061", "#7c5800", "#1a1c18", ]

Events

EventDescription
changeFires when the committed color value changes via user interaction.

CSS parts

PartDescription
triggerThe button that shows the current color and opens the panel.
swatchThe color swatch inside the trigger.
labelThe label text next to the trigger swatch.
panelThe popover panel surface.
presetEach preset swatch button.
custom-inputThe native <input type="color">.
hex-inputThe text input mirroring the hex value.

Source on GitHub npm