refract v0.1 · beta
Core concepts / Responsive

Responsive

Any property or recipe can carry a responsive list. refract lowers each entry to an @media override — on the :root variable for token properties, or on the class for recipes.

Breakpoints are named (xs … xl); each entry picks one with a min or max query. The emitted media unit (px / em / rem) is a build-time config, so authoring stays unit-agnostic.

breakpoints.ts
// declare the named scale once, on the theme
breakpoints: {
  xs: 0, sm: 576, md: 768, lg: 1024, xl: 1440,
}

Then any property or recipe references those names in a responsive entry:

spacing.ts
spacing: {
  base: 8, variants: { xl: 28 },
  responsive: [
    { breakpoint: "sm", query: "min", target: "xl", base: 40 },
  ],
}

// lowers to →  @media (min-width: 576px) { :root { --…-spacing-xl: 40px } }

Worked example

A recipe that changes its background above a breakpoint — authored, then exactly what the CSS adapter emits:

authored
solid.brand: {
  background: "brand", color: "brand.text",
  responsive: [{ breakpoint: "md", query: "min", background: "accent" }],
}
emitted
.dt-colors-solid-brand { background: var(--dt-colors-brand); color: var(--dt-colors-brand-text); }
@media (min-width: 768px) {
  .dt-colors-solid-brand { background: var(--dt-colors-accent); }
}

Rules & edge cases

  • Property vs recipe. A property's responsive lowers to a :root variable override (@media { :root { --… } }); a recipe's lowers to a class override, as above. Same authoring, two lowerings.
  • Query kind. Each entry is min, max, or exact — commit to mobile-first (min) or desktop-first (max) deliberately.
  • Source order is cascade order. Entries emit after the base in author order; at equal specificity the later rule wins, so order breakpoints so the intended one lands last.
  • Composes with the other axes. A responsive entry may also carry a state (→ @media { .cls:hover { … } }); container queries are a separate axis.
  • Unknown breakpoint is a build error — declare it in breakpoints first.
Every property subsystem and every recipe accepts responsive. The emitted unit (px/em/rem) is the media config. See Container queries for the container axis and States for combining with states.

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.