Skip to main content

Web2PrintColorAttributeController

You get this controller when useAttribute(...) resolves a Web2Print color attribute. A color attribute stores a single chosen color and exposes the default color plus any color palettes configured for the swatch picker.

import { useAttribute } from "@expivi/product-configurator";

const attribute = useAttribute(configurator, attributeCid);

Setting a color and loading palettes

Set the color with setValue(...). Seed the picker from the default color and any configured palettes.

const start = attribute.configuredValue?.value.color ?? attribute.defaultColor;

const swatches = await attribute.fetchPaletteColors();

attribute.setValue("#ff0000");

API

settings: ColorPrintSettings | null | undefined

The raw color-print settings object.

defaultColor: string

The best default display color from settings (default_color_rgba, then default_color.display_color), normalized to a leading #, falling back to #000000.

defaultCustomColor: string | null

The default custom RGBA color when default_color_rgba is configured (normalized to a leading #), otherwise null.

configuredValue: Web2PrintColorConfiguredValue | undefined

The first configured color value, if present. The chosen color is at configuredValue.value.color.

fetchPaletteColors(): Promise<PaletteColor[]>

Loads colors from every palette listed in the color settings (color_palettes).

setValue(color) stores the color string as { color }. For all other members, see the Common Attribute API.