Hook useClassNames(classNames, block, element, modifier)
Combine class names and an optional static class name
This hook implements useStaticClassName
to generate static class names.
Parameters
- classNames
- Type:
(string | undefined)[]
- Type:
- block
- Type:
string | undefined
- Type:
- element
- Type:
string | undefined
- Type:
- modifier
- Type:
string | string[] | undefined
- Type:
Returns
- Type:
string
Example
tsx
import { useClassNames } from "@prozilla-os/core";
import styles from "./Example.module.css";
export function Example() {
return <div className={useClassNames([styles.Example], "Example")}>
<h1 className={useClassNames([styles.Text, styles.Title], "Example", "Title")}>
This is a title
</h1>
<p className={useClassNames([], "Example", "Paragraph", "Special")}>
This is a special paragraph
</p>
</div>;
}
Result
html
<div class="ProzillaOS-Example _Example_1xkyl_17">
<h1 class="ProzillaOS-Example__Title _Text_ls3ab_1 _Title_1ur5p_149">This is a title</h1>
<p class="ProzillaOS-Example__Paragraph--Special">This is a special paragraph</p>
</div>