예제
실용적인 예제와 라이브 데모.
예제를 선택하면 라이브 미리보기와 소스 코드를 나란히 표시하는 전체 화면이 열립니다.
예제를 선택하면 라이브 미리보기와 소스 코드를 나란히 표시하는 전체 화면이 열립니다.
조건에 따라 클래스를 합칩니다. 나중에 온 스타일이 이깁니다.
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."), ) }