qat

Styling

Scoped styles

A .qx file may have one <style>: its rules apply to the file's own elements only (an attribute is added to them and to the rules' last selectors), :global(…) escapes the scoping, keyframes are renamed, and CSS nesting works.

.qx10 linesOpen in the playground
// badge.qx
export default function Badge({ text, tone }) {
  return <span class="badge" class:tone={tone}>{text}</span>
}

<style>
.badge { padding: 0 4px; border-radius: 4px; }
.tone-info { background: var(--info); }
.tone-warn { background: var(--warn); }
</style>

In .tsx, a sibling stylesheet imported with import './badge.css' with { scope: 'component' } is scoped the same way; a plain import './x.css' is global.

Directives

  • class="a b" and class={expr}; class:name={on} toggles one class.
  • Variants: class:size={value} with a string sets size-<value> (replacing the previous one); any other truthy value (true, a number) sets the bare size (class:size={2} is size, not size-2: pass String(n)); null, undefined, false, 0 and '' set none.
  • style:color={c} sets one property; style={{ color, marginTop: '4px' }} and style="…" work too. A value is set as it is, with no unit added: marginTop: 4 sets nothing (the browser refuses a length without a unit), so write '4px'. Unitless properties (opacity, zIndex, lineHeight, flexGrow) take numbers. All of them set styles through the CSSOM, never as an inline style attribute, so a strict Content-Security-Policy (style-src without 'unsafe-inline') allows them.

Checked at compile time

qatjs check (and the editor) checks styles against what actually exists — the file's <style>, the project's global stylesheets, and Tailwind's utilities when the project uses Tailwind. A stylesheet is global when anything on the page loads it (CSS is not scoped): those index.html links, and every plain CSS import anywhere in the import graph of its module scripts — a component's own import './card.css' included — with the @imports inside them, relative or from a package (@import '@qatjs/ui/theme/tokens.css'):

diagnostic when
QX-CLASS-UNKNOWN (error) a static class (class="…", class:name) no stylesheet defines — with the nearest existing name as a fix-it. Every static class needs a rule somewhere: a class used only as a hook (a test's selector, class="remove") is reported too. Lint key class-unknown ("warn" or "off"), or give the hook a data- attribute instead
QX-CSS-UNUSED (warning) a <style> rule no element of the file can match; production builds drop it (mark it /* keep */, or use :global())
QX-TOKEN-UNKNOWN (warning) a var(--token) declared nowhere in the file or the project's CSS (Tailwind's theme included) — in a <style>, and in the project's own .css files (a var(--x, fallback) needs no declaration). Lint key token-unknown
QX-VARIANT-UNSTYLED (warning) class:size={value} where value has a string-union type written in the file (state<'s' | 'l'>) and a member has no .size-<member> rule. A prop's type is not followed yet: class:tone={tone} with tone: 'info' | 'warn' is not checked
QX-UI-FOCUS-REMOVED (error) a rule of the project's .css files takes the focus outline away (outline: none, 0, transparent) and nothing puts a ring back: neither the rule (box-shadow, a new outline) nor the selector's :focus/:focus-visible/:focus-within rule. Where the ring is drawn elsewhere, say so in the rule: /* qat-ignore QX-UI-FOCUS-REMOVED — why */. Lint key ui-focus-removed

Dynamic class={…} expressions are not checked, except that the string literals they can produce count as used for QX-CSS-UNUSED.

In the editor, class names complete inside class="…" and class:, tokens after var(-- in <style>, and hovering a class shows the rules that define it.