refract v0.1 · beta
Core concepts / Variants & targets

Variants & targets

A property's variants become suffixed tokens (--…-dark, spacing-xl). In a responsive entry, variant: swaps a recipe to a sibling's base, and target: scopes the override to one specific step.

variants.ts
outline.brand: {
  color: "brand", borderColor: "brand",
  responsive: [
    { breakpoint: "lg", variant: "subtle" }, // adopt sibling ≥lg
  ],
}
// target: scope an override to ONE step
spacing.responsive: [{ breakpoint: "sm", target: "xl", base: 40 }]

variant — swap to a sibling

In a recipe responsive entry, variant makes the recipe adopt a sibling variant's declarations above the breakpoint.

authored
solid: {
  brand: { background: "brand", color: "brand.text",
    responsive: [{ breakpoint: "lg", query: "min", variant: "muted" }] },
  muted: { background: "brand.light", color: "brand.dark" },
}
emitted
/* ≥lg, solid.brand takes on solid.muted's declarations */
@media (min-width: 1024px) {
  .dt-colors-solid-brand { background: var(--dt-colors-brand-light); color: var(--dt-colors-brand-dark); }
}

target — scope to one token

In a property responsive entry, target scopes the override to a single variant token, leaving the base untouched.

authored
surface: {
  base: "#ffffff", variants: { raised: "#f5f5f5" },
  responsive: [{ breakpoint: "sm", query: "min", target: "raised", base: "#e9ecef" }],
}
emitted
:root { --dt-colors-surface: rgb(255, 255, 255); --dt-colors-surface-raised: rgb(245, 245, 245); }
@media (min-width: 576px) {
  :root { --dt-colors-surface-raised: #e9ecef; }   /* only the raised token */
}

Rules & edge cases

  • Opposite meanings. variant names a source to adopt (a whole sibling recipe); target names a destination to scope to (one token). Setting both on one entry is a build error.
  • variant is a recipe thing; target is a property thing. They live in different lowerings — a class swap vs a single-var override.
  • Variant tokens are always addressable. A property's variants emit as --…-<variant> alongside the base, whether or not any responsive entry touches them.
variant:target:
Names asource — a whole sibling recipe to adoptdestination — one token to scope a value to
Operates ona recipe (a class swap)a property (a single-var override)
Lowers toa different .dt-… class at the breakpointa --… var override inside a :root media block
Reach for it whena component should become a different variant at a breakpointone token needs a different value at a breakpoint
Both are authored inside a responsive entry — see Responsive. Variant naming follows Token paths & naming.

Live

Technical documentation for @theme-registry/refract · all output is compiled client-side by the real library (CSS adapter). The chrome is theme-aware; the render panes carry each preset's own world. · MIT licensed.