Skip to content

pantoken / design/swatches/src / toSwatches

Funktion: toSwatches()

toSwatches(tokens, mode?): Swatch[]

Eksperimentel

Reducér en token IR til en flad liste over farveprøver: løs referencer, vælg en tilstand, bevar kun tokens, hvis værdi er en hexfarve (ikoner og ikke-farve-tokens dropper).

Parametre

tokens

skrivbeskyttet Token[]

IR'en (f.eks. fra @pantoken/tokens).

mode?

Mode = "light"

Hvilken farvetilstand skal løses (standard "light").

Returnerer

Swatch[]

Prøvepaletten, navngivet efter token (uden --instui- præfiks).

Eksempler

Reducer token IR til light-mode prøver

ts
import { toSwatches } from "@pantoken/swatches";
import { tokens } from "@pantoken/tokens";

const swatches = toSwatches(tokens); // [{ name: "color-background-brand", hex: "#…" }, …]

Mørk tilstand

ts
import { toSwatches } from "@pantoken/swatches";
import { byTheme } from "@pantoken/tokens";

const swatches = toSwatches(byTheme("canvas"), "dark");