Esempi
Esempi concreti. Demo live.
Scegli un esempio e aprilo a schermo intero: anteprima live e sorgente, fianco a fianco.
Scegli un esempio e aprilo a schermo intero: anteprima live e sorgente, fianco a fianco.
Componi le classi in base alle condizioni: gli stili che arrivano dopo hanno la meglio.
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."), ) }