Fragiola

API: components

ColorSlider

One channel of a color chosen along a track drawn with its colors, following the APG's slider pattern, in each framework.

Choose one channel of a color along a track drawn with that channel's colors (WAI-ARIA APG slider). Its value is a color in rgb, hsl or hsb; the channel is the thumb's aria-valuenow, and its text ("120°", "50%") comes from Intl. It works in a native <form> and a Field.

HSL color editor
Gallery

Behaviour

  • Value: a Color or a string ("#336699", "hsl(210, 50%, 40%)"); changes report a Color in the slider's space: colorSpace, else the value's own when it has the channel, else the channel's own (red, green, blue: rgb; lightness: hsl; hue, saturation, brightness: hsb). Several sliders can share one value, each editing its channel.
  • Range: the channel's (hue 0–360, saturation, lightness and brightness 0–100, red, green and blue 0–255, alpha 0–1), its step and large step; values snap to the step.
  • Track: the interactive area. A press moves the thumb there (reason track-press), focuses it and drags it with pointer capture (drag, data-dragging). It sets --color-slider-track-background (a CSS linear-gradient of the channel), and the Thumb --color-slider-thumb-color; draw with them (background: var(--color-slider-track-background)).
  • Commit: onValueCommit once a drag ends, or after a key changed the value.
  • Label: names the Root and the Thumb (when it has no name of its own); a press on it focuses the Thumb. No channel name of its own: the library renders no text.
  • Output: an output for the Thumb showing the channel's text, or the content you give it.
  • RTL: a horizontal slider runs right to left, the arrows swap and the gradient runs to left.
  • Forms: a hidden input submits the color as hex (#rrggbb, or #rrggbbaa below full alpha), whatever the channel.

Anatomy

partelementdata-primitives-partrole
Rootdivcolor-slider-rootthe group; holds the value
Labeldivcolor-slider-labelnames the Root and the Thumb
Outputoutputcolor-slider-outputthe channel's text
Trackdivcolor-slider-trackthe interactive area and the gradient
Thumbdivcolor-slider-thumbthe slider
(hidden input)input type="hidden"color-slider-inputthe color as hex, what the form submits

Usage

import { ColorSlider } from "@fragiola/primitives-react/color-slider";

<ColorSlider.Root channel="hue" value={color} onValueChange={setColor} name="color">
    <ColorSlider.Label>Hue</ColorSlider.Label>
    <ColorSlider.Track>
        <ColorSlider.Thumb />
    </ColorSlider.Track>
    <ColorSlider.Output />
</ColorSlider.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"#000000"the initial color, uncontrolled
onValueChange(value: Color, details: { reason }) => voidevery change (keyboard, track-press, drag), the color in the slider's space
onValueCommit(value: Color, details) => voidonce a drag ends, or after a key
channelColorChannelthe channel it edits (required)
colorSpace"rgb" | "hsl" | "hsb"the value's, else the channel'sthe space it edits the channel in
orientation"horizontal" | "vertical""horizontal"the axis
disabledbooleanfalseignores the pointer and the keys
namestringthe form name of the hidden input (a Field's wins)
localestringthe runtime'sthe locale of the channel's text (a BCP 47 tag)

Label

proptypedefaultdescription
idstringgeneratedthe id the Root's and the Thumb's aria-labelledby point at

Output

No props of its own. Its children replace the channel's text.

Track

No props of its own.

Thumb

proptypedefaultdescription
idstringgeneratedthe thumb's id, the Output's for

State and part attributes

partattributes
Rootrole="group", aria-labelledby, data-orientation, data-channel, data-disabled, data-dragging; in a Field, the field's states
Label, Outputdata-orientation, data-channel, data-disabled; the Output for and aria-live="off"
Trackdata-orientation, data-channel, data-disabled, data-dragging; structural style position: relative, touch-action: none, --color-slider-track-background
Thumbrole="slider", id, tabindex="0", aria-valuenow, aria-valuemin, aria-valuemax, aria-valuetext, aria-orientation, aria-labelledby, aria-disabled, data-orientation, data-channel, data-disabled, data-dragging; structural style placing it, --color-slider-thumb-color

Keyboard

keyaction
ArrowRight, ArrowUp+ one step (ArrowLeft in RTL)
ArrowLeft, ArrowDown− one step (ArrowRight in RTL)
Page Up / Page Down, Shift+Arrow± the large step
Home / Endthe channel's min / max

Exports

entryexports
@fragiola/primitives-react/color-sliderChangeDetails, ChangeReason, Color, ColorChannel, ColorSlider, ColorSliderLabelProps, ColorSliderOutputProps, ColorSliderRootProps, ColorSliderState, ColorSliderThumbProps, ColorSpace, HsbColor, HslColor, RenderProp, RgbColor
@fragiola/primitives-vue/color-sliderChangeDetails, ChangeReason, Color, ColorChannel, ColorSlider, ColorSliderLabelProps, ColorSliderRootEmits, ColorSliderRootProps, ColorSliderState, ColorSliderThumbProps, ColorSpace, HsbColor, HslColor, RenderSlotProps, RgbColor
@fragiola/primitives-angular/color-sliderChangeDetails, ChangeReason, Color, ColorChannel, ColorSliderLabel, ColorSliderOutput, ColorSliderRoot, ColorSliderState, ColorSliderThumb, ColorSliderTrack, ColorSpace, HsbColor, HslColor, RgbColor, ValueChangeEvent