Examples
Practical examples. Live demos.
Pick an example to open it full screen, with the live preview and its source side by side.
Pick an example to open it full screen, with the live preview and its source side by side.
Compose classes conditionally. Later styles win.
import 'nuclo' // A theme: named colors (and screens) that css() accepts as values const { css, cx } = createCss({ colors: { primary: "#ff3f00", surface: "#fafafa", border: "#d4d4d4", text: "#222222", muted: "#737373", }, screens: { sm: "(min-width: 520px)", }, }) 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 Button() { return div( css({ col: true, gap: 10, items: "center" }), button( // cx() joins the classes that are truthy, so the selected style // is added on top of the base one only while selected is true () => cx(baseButton, selected ? selectedButton : null), () => selected ? "Selected" : "Select", { onClick: () => { selected = !selected; update() } }, ), span(css({ color: "muted", text: 12 }), "cx() adds the selected class."), ) }