sp-color-wheel

Examples API

Attributes and Properties #

Property Attribute Type Default Description
autofocus autofocus boolean false When this control is rendered, focus it automatically
color color ColorValue
dir dir 'ltr' | 'rtl' 'ltr'
disabled disabled boolean false Disable this control. It will not receive focus or events
focused focused boolean false
label label string 'hue'
step step number 1
tabIndex tabIndex number The tab index to apply to this control. See general documentation about the tabindex HTML property
value value number

Slots #

Name Description
gradient a custom gradient visually outlining the available color values

Events #

Name Type Description
change Event An alteration to the value of the Color Wheel has been committed by the user.
input Event The value of the Color Wheel has changed.

CSS Custom Properties #

Name Default
--spectrum-colorarea-border-color var(--spectrum-alias-border-color-translucent)
--spectrum-colorhandle-size var(--spectrum-global-dimension-size-200)
--spectrum-colorwheel-border-color var(--spectrum-alias-border-color-translucent)
--spectrum-colorwheel-border-color-disabled var(--spectrum-alias-track-color-disabled)
--spectrum-colorwheel-border-size var(--spectrum-alias-border-size-thin)
--spectrum-colorwheel-fill-color-disabled var(--spectrum-alias-track-color-disabled)
--spectrum-colorwheel-height var(--spectrum-global-dimension-size-2400)
--spectrum-colorwheel-width var(--spectrum-global-dimension-size-2400)

Description #

An <sp-color-wheel> lets users visually change an individual channel of a color on a circular track.

Usage #

See it on NPM! How big is this package in your project? Try it on webcomponents.dev

yarn add @spectrum-web-components/color-wheel

Import the side effectful registration of <sp-color-wheel> via:

import '@spectrum-web-components/color-wheel/sp-color-wheel.js';

When looking to leverage the ColorWheel base class as a type and/or for extension purposes, do so via:

import { ColorWheel } from '@spectrum-web-components/color-wheel';

Color Formatting #

When using the color elements, use el.color to access the color property, which should manage itself in the color format supplied. If you supply a color in rgb() format, el.color should return the color in rgb() format, as well.

The current color formats supported are as follows:

  • Hex3, Hex4, Hex6, Hex8
  • HSV, HSVA
  • HSL, HSLA
  • RGB, RGBA
  • Strings (eg "red", "blue")

Please note for the following formats: HSV, HSVA, HSL, HSLA When using the HSL or HSV formats, and a color's value (in HSV) is set to 0, or its luminosity (in HSL) is set to 0 or 1, the hue and saturation values may not be preserved by the element's color property. This is detailed in the TinyColor documentation. Seperately, the element's value property is directly managed by the hue as represented in the interface.

Example #

<sp-color-wheel></sp-color-wheel>

Disabled #

A color wheel in a disabled state shows that an input exists, but is not available in that circumstance. This can be used to maintain layout continuity and communicate that the wheel may become available later.

<sp-color-wheel disabled></sp-color-wheel>

Variants #

Sized #

An <sp-color-wheel>’s size can be customized appropriately for its context. By default, the size is size-2400 (192 px on desktop, 240 px on mobile).

<sp-color-wheel style="width: 300px; height: 300px;"></sp-color-wheel>