Skip to main content

Search rules

Search all UI Guides rules by name, category, or source

designComposition Patterns

Explicit Variants Over Boolean Props

SHOULD

SHOULD: Model mutually-exclusive styles as one enumerated variant prop, not isPrimary/isGhost/isLarge booleans that allow illegal combinations and multiply with every new style. Keep booleans only for orthogonal toggles (disabled, loading, fullWidth). Maps cleanly onto CVA.

Model mutually-exclusive styles as one enumerated variant prop, not a pile of isPrimary/isGhost/isLarge booleans

// good
<Button variant="ghost" size="sm" />
// bad
<Button isGhost isSmall isPrimary />

Bad

Good

Why it matters

Three boolean style props already encode eight states, most of them nonsense — `isPrimary` and `isGhost` both true has no meaning, yet the type permits it and some branch has to guess. An enumerated prop, `variant: "primary" | "secondary" | "ghost"`, makes exactly the valid states representable and the illegal ones unspellable, which is the whole point of a type.

It also maps one-to-one onto class-variance-authority, the engine shadcn/ui uses to attach classes per variant, so the API and the styling share one source of truth. Keep booleans for genuinely independent, orthogonal toggles (`disabled`, `loading`, `fullWidth`) — the test is whether two of them being true at once is meaningful. If it is not, they are really one variant wearing several names.

Built by Gleb Stroganov, design engineer at Evil Martians.

The rules come from other people's skills and guidelines — Vercel, Rauno Freiberg, @Ibelick, impeccable, Emil Kowalski, Tailwind, RAMS — each one credited on the Sources page. The work here is extraction and wiring: every rule is pulled into one corpus, given a good and a bad example you can operate, a MUST/SHOULD/NEVER rule an agent can paste, and a link back to where it came from.