Fragiola

API: components

ColorField

A color typed as hex (or any CSS color text), or one channel typed as a number, committed on Enter and blur, in each framework.

Type a color: a text input that reads hex, rgb(), hsl() or hsb() and writes the value back as hex, or, with channel, one channel as a number (an APG spinbutton). The typed text is free until Enter or a blur commits it. It works in a native <form> and a Field.

HSL color editor
Gallery

Behaviour

  • Value: a Color, a string or null (empty); onValueChange reports a commit or a step, never the typing.
  • Hex mode (no channel): the text is the value's hex. A commit parses the text (any text parseColor reads): a color becomes the value, an empty text gives null, anything else goes back to the value's text. ArrowUp / ArrowDown add or subtract 1 to the color as a 24-bit number.
  • Channel mode (channel): a spinbutton with the channel's value, its text from Intl ("120°", "50%"). A commit parses the number in the locale (with or without its unit), clamps it and sets the channel; the APG spinbutton keys step it.
  • Forms: a hidden input submits the hex (channel mode: the channel's number), required when the field is.

Anatomy

partelementdata-primitives-partrole
Rootdivcolor-field-rootholds the value and the text
Inputinputcolor-field-inputa textbox, or a spinbutton with channel
(hidden input)inputcolor-field-hidden-inputwhat the form submits and validates

Usage

import { ColorField } from "@fragiola/primitives-react/color-field";

<label htmlFor="brand">Brand color</label>
<ColorField.Root id="brand" name="brand" defaultValue="#336699">
    <ColorField.Input />
</ColorField.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 | string | nullthe color, controlled
defaultValueColor | string | nullnullthe initial color, uncontrolled
onValueChange(value: Color | null, details: { reason }) => voida commit (keyboard, input-blur, input-clear) or a step (keyboard)
channelColorChannelthe channel it edits; none: the whole color as hex
colorSpace"rgb" | "hsl" | "hsb"the value's, else the channel'swith channel, the space it edits it in
localestringthe runtime'sthe locale of the channel's text
namestringthe hidden input's form name (a Field's wins)
idstringgeneratedthe Input's id
disabledbooleanfalsedisables the Input
readOnlybooleanfalsethe text cannot change
requiredbooleanfalsethe hidden input is required

Input

No props of its own; name it with a <label for>, aria-label or a Field's Label.

State and part attributes

partattributes
Rootdata-disabled, data-readonly, data-required, data-channel; in a Field, the field's states
Inputid, type="text", autocomplete="off", spellcheck="false", aria-required, aria-readonly; with channel: role="spinbutton", inputmode="decimal", aria-valuenow, aria-valuemin, aria-valuemax, aria-valuetext
hidden inputvisually hidden, aria-hidden="true", tabindex="-1", name, value, required, disabled

Keyboard

keyaction
Entercommits the typed text
ArrowUp / ArrowDownhex: ± 1 on the 24-bit number; channel: ± one step (Shift: the large step)
Page Up / Page Downchannel: ± the large step
Home / Endchannel: its min / max (hex: the caret)

Exports

entryexports
@fragiola/primitives-react/color-fieldChangeDetails, ChangeReason, Color, ColorChannel, ColorField, ColorFieldInputProps, ColorFieldRootProps, ColorFieldState, ColorSpace, HsbColor, HslColor, RenderProp, RgbColor
@fragiola/primitives-vue/color-fieldChangeDetails, ChangeReason, Color, ColorChannel, ColorField, ColorFieldRootEmits, ColorFieldRootProps, ColorFieldState, ColorSpace, HsbColor, HslColor, RenderSlotProps, RgbColor
@fragiola/primitives-angular/color-fieldChangeDetails, ChangeReason, Color, ColorChannel, ColorFieldInput, ColorFieldRoot, ColorFieldState, ColorSpace, HsbColor, HslColor, RgbColor, ValueChangeEvent