Fragiola

API: components

ColorSwatch

A preview of a color, an image over the recipe's checkerboard, named by the app, in each framework.

Show a color: an img (the APG's img role, named) whose color is a CSS variable, drawn over a checkerboard by your styles so its transparency shows. It has no behaviour of its own: inside a ColorPicker it shows the picker's color, and inside a ColorSwatchPicker Item it is the option's content.

Theme color picker
Gallery

Behaviour

  • Color: color (a Color or a string); without one, an enclosing ColorPicker's color, else transparent black.
  • Name: yours (aria-label, aria-labelledby). Without one, the swatch is named by the color's CSS text ("rgb(51, 102, 153)"): data, not words, since an image must have a name. The library has no color names (English copy).
  • Drawing: --color-swatch-color (with its alpha) and --color-swatch-color-opaque; the checkerboard is your style: background: linear-gradient(var(--color-swatch-color), var(--color-swatch-color)), repeating-conic-gradient(#d4d4d8 0% 25%, #fff 0% 50%) 50% / 12px 12px.

Anatomy

partelementdata-primitives-partrole
ColorSwatchdivcolor-swatch-rootthe img

Usage

import { ColorSwatch } from "@fragiola/primitives-react/color-swatch";

<ColorSwatch color="#336699" aria-label="Ocean" />;

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. Angular declares aria-label and aria-labelledby as inputs, so it knows whether you named the swatch (bind them as [aria-label]).

ColorSwatch

proptypedefaultdescription
colorColor | stringthe picker's, else transparentthe color it shows
ariaLabel (angular)stringthe color's CSS textits name
ariaLabelledby (angular)stringthe element that names it

State and part attributes

partattributes
ColorSwatchrole="img", aria-label (the color's CSS text, unless you name it), --color-swatch-color, --color-swatch-color-opaque

Keyboard

None: a swatch is an image and takes no focus (inside a ColorSwatchPicker, its Item does).

Exports

entryexports
@fragiola/primitives-react/color-swatchColor, ColorSpace, ColorSwatch, ColorSwatchProps, ColorSwatchState, HsbColor, HslColor, RenderProp, RgbColor
@fragiola/primitives-vue/color-swatchColor, ColorSpace, ColorSwatch, ColorSwatchProps, ColorSwatchState, HsbColor, HslColor, RenderSlotProps, RgbColor
@fragiola/primitives-angular/color-swatchColor, ColorSpace, ColorSwatch, ColorSwatchState, HsbColor, HslColor, RgbColor