Skip to content

pantoken / design/swatches/src / toSwatches

Funktion: toSwatches()

toSwatches(tokens, mode?): Swatch[]

Experimentell

Reducera en token-IR till en platt lista med färgprover: lös referenser, välj ett läge, behåll endast tokens vars värde är en hex-färg (ikoner och icke-färgade tokens tas bort).

Parametrar

tokens

skrivskyddad Token[]

IR:n (t.ex. från @pantoken/tokens).

mode?

Mode = "light"

Vilket färgläge som ska lösas (standard "light").

Returnerar

Swatch[]

Listan med prover, namngiven efter token (utan prefixet --instui-).

Exempel

Reducera token-IR till färgprover för ljust läge

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

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

Mörkt läge

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

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