Skip to content

pantoken-root / design/swatches/src / toSwatches

Funksjon: toSwatches() ​

toSwatches(tokens, mode?): Swatch[]

Eksperimentell

Reduser ein token-IR til ei flat liste med fargeprøvar: løyse referansar, velje ein modus, behold berre tokener som har verdi som ein heksadesimalfarge (ikon og ikkje-farge-tokener blir forkasta).

Parametrar ​

tokens ​

skrivbeskytta Token[]

IR-en (til dømes frå @pantoken/tokens).

mode? ​

Mode = "light"

Kva fargemodus som skal løysast (standard "light").

Returnerer ​

Swatch[]

Lista over prøvefargar, namngjeven etter token (utan --instui--prefiks).

Døme ​

Reduser token-IR til prøvefargar for lysmodus

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

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

Mørk modus

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

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