Beispiele
Praxisnahe Beispiele. Live-Demos.
Öffne ein Beispiel im Vollbild: Live-Vorschau und Quellcode liegen nebeneinander.
Öffne ein Beispiel im Vollbild: Live-Vorschau und Quellcode liegen nebeneinander.
css() liefert die Klassen, cx() übernimmt kleine bedingte Änderungen.
css() creates the base class. cx() adds the selected class only when state changes.
import 'nuclo' const { css, cx } = createCss({ colors: { primary: "#ff3f00", border: "#e5e7eb", text: "#1f2937", }, }) const baseButton = css({ px: 14, py: 9, rounded: 6, border: "1px solid", borderColor: "border", color: "text", cursor: "pointer", }) const selectedButton = css({ bg: "primary", color: "white", borderColor: "primary", }) let selected = false export function StyledButton() { return div( p( code("css()"), " creates the base class. ", code("cx()"), " adds the selected class only when state changes.", ), button( // cx() joins the classes that are truthy () => cx(baseButton, selected ? selectedButton : null), () => selected ? "Selected" : "Select", { onClick: () => { selected = !selected; update() } }, ), ) }