Skip to content

pantoken-root / design/swatches/src / toSwatches

Funksjon: toSwatches() ​

toSwatches(tokens, mode?): Swatch[]

Eksperimentell

Reduser en token IR til en flat liste med fargeprøver: løs referanser, velg en modus, behold bare tokener hvis verdi er en heksadesimalfarge (ikoner og ikke-farge-tokener fjernes).

Parametere ​

tokens ​

skrivbeskyttet Token[]

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

mode? ​

Mode = "light"

Hvilken fargemodus som skal løses (standard "light").

Returnerer ​

Swatch[]

Listen over fargeprøver, navngitt etter token (uten --instui--prefikset).

Eksempler ​

Reduser token IR til fargeprøver 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");