Skip to content

Compose class names reactively — returns a getter function for use with reactive class props.

function rcx(...args: (string | (() => string | false | null | undefined) | false | null | undefined)[]): () => string

Any positional argument can be a plain string, a falsy value (false / null / undefined), or a getter function returning string-or-falsy. Falsy values and falsy getter returns are skipped; remaining classes are space-joined.

div({ class: rcx("btn") })
const loading = signal(false);
div({
class: rcx("btn", () => loading.value && "btn-loading"),
})
const theme = signal<"light" | "dark">("light");
const size = signal<"sm" | "md" | "lg">("md");
div({
class: rcx(
() => `theme-${theme.value}`,
() => `size-${size.value}`,
),
})
const s = sheet({
item: { padding: "0.5rem" },
active: { background: "var(--color-accent-low)" },
});
const selected = signal(false);
li({
class: rcx(s.item, () => selected.value && s.active),
})
const variant = signal<"primary" | "secondary">("primary");
const loading = signal(false);
div({
class: rcx(
"btn",
() => variant.value === "primary" && "btn-primary",
() => variant.value === "secondary" && "btn-secondary",
() => loading.value && "btn-loading",
),
})

Docs current to v0.1.0-alpha.9 . All releases →