Fragiola

API: components

ColorWheel

A color's hue chosen on a ring, an APG slider whose track is a circle, wrapping from 359° to 0°, in each framework.

Choose a color's hue by moving a thumb around a ring that shows every hue (an APG slider on a circle). The hue wraps around: from 359° on to 0°. Its value is a color in hsl or hsb.

HSL color editor
Gallery

Behaviour

  • Value: a Color or a string; changes report a Color in hsl or hsb (colorSpace, else the value's own, else hsb).
  • Ring: outerRadius and innerRadius (px) shape it; the Root is 2 × outerRadius square, 0° is at the top and the hue grows clockwise. The Track sets --color-wheel-track-background (a CSS conic-gradient), the Root --color-wheel-outer-radius and --color-wheel-inner-radius (mask the Track with them), the Thumb --color-wheel-thumb-color.
  • Pointer: a press on the ring moves the thumb to that angle (track-press), focuses it and drags it with pointer capture (drag); a press off the ring does nothing.
  • Keyboard: the arrows ± 1° (Shift, Page Up and Page Down: 15°), Home 0°, End 359°; the hue wraps.
  • Forms: a hidden input submits the color as hex.

Anatomy

partelementdata-primitives-partrole
Rootdivcolor-wheel-rootholds the value; the interactive square
Trackdivcolor-wheel-trackthe ring's gradient
Thumbdivcolor-wheel-thumbthe slider
(hidden input)input type="hidden"color-wheel-inputthe color as hex

Usage

import { ColorWheel } from "@fragiola/primitives-react/color-wheel";

<ColorWheel.Root value={color} onValueChange={setColor} outerRadius={100} innerRadius={76}>
    <ColorWheel.Track />
    <ColorWheel.Thumb aria-label="Hue" />
</ColorWheel.Root>;

Props

Every part also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. The names below are React's; Vue binds them the same way (v-model:value, @value-commit), and Angular as inputs and outputs ([(value)], (valueCommit)).

Root

proptypedefaultdescription
valueColor | stringthe color, controlled
defaultValueColor | string"hsl(0, 100%, 50%)"the initial color, uncontrolled
onValueChange(value: Color, details: { reason }) => voidevery change (keyboard, track-press, drag)
onValueCommit(value: Color, details) => voidonce a drag ends, or after a key
colorSpace"hsl" | "hsb"the value's, else hsbthe space of the hue
outerRadiusnumber100the ring's outer radius, in px
innerRadiusnumber75the ring's inner radius, in px
disabledbooleanfalseignores the pointer and the keys
namestringthe form name of the hidden input
localestringthe runtime'sthe locale of the hue's text

Track

No props of its own.

Thumb

No props of its own; name it with aria-label or aria-labelledby.

State and part attributes

partattributes
Rootdata-disabled, data-dragging; structural style position: relative, its size, touch-action: none, --color-wheel-outer-radius, --color-wheel-inner-radius
Trackdata-disabled, data-dragging; structural style position: absolute, inset: 0, --color-wheel-track-background
Thumbrole="slider", tabindex="0", aria-valuenow, aria-valuemin="0", aria-valuemax="360", aria-valuetext, aria-disabled, data-disabled, data-dragging; structural style placing it, --color-wheel-thumb-color

Keyboard

keyaction
ArrowRight, ArrowUp+ 1° (Shift: 15°), wrapping
ArrowLeft, ArrowDown− 1° (Shift: 15°), wrapping
Page Up / Page Down± 15°
Home / End0° / 359°

Exports

entryexports
@fragiola/primitives-react/color-wheelChangeDetails, ChangeReason, Color, ColorSpace, ColorWheel, ColorWheelRootProps, ColorWheelState, HsbColor, HslColor, RenderProp, RgbColor
@fragiola/primitives-vue/color-wheelChangeDetails, ChangeReason, Color, ColorSpace, ColorWheel, ColorWheelRootEmits, ColorWheelRootProps, ColorWheelState, HsbColor, HslColor, RenderSlotProps, RgbColor
@fragiola/primitives-angular/color-wheelChangeDetails, ChangeReason, Color, ColorSpace, ColorWheelRoot, ColorWheelState, ColorWheelThumb, ColorWheelTrack, HsbColor, HslColor, RgbColor, ValueChangeEvent