ssrClass
Renders a class attribute from a class value: the helper the compiler's server output calls for class, className and classList, with the same clsx rules as the client's className.
Renders a class attribute from a class value: the helper the compiler's server output calls for
class, className and classList, with the same clsx rules as the client's className.
Import#
ts
import { ssrClass } from "@shadow-js/web/server";
Signature#
ts
function ssrClass(value: unknown): string
Parameters#
| Name | Description |
|---|---|
value |
A string (used as is), or an array or object: non-empty strings, numbers other than 0 and NaN, nested arrays, and the keys of objects whose value is truthy. Accessors, also inside arrays and as object values, are called. null, undefined and false give no class. |
Returns#
Markup such as ' class="a b"' (HTML-escaped), or "" when there are no classes.
Throws#
- TypeError when an array contains itself, and
UNRECOGNIZED_INSERT_VALUEfor a symbol.
Examples#
ts
import { ssrClass } from "@shadow-js/web/server";
ssrClass(["card", { "card--active": true, hidden: false }]); // ' class="card card--active"'
ssrClass(null); // ""