예제
실용적인 예제와 라이브 데모.
예제를 선택하면 라이브 미리보기와 소스 코드를 나란히 표시하는 전체 화면이 열립니다.
예제를 선택하면 라이브 미리보기와 소스 코드를 나란히 표시하는 전체 화면이 열립니다.
클래스는 css()로 만들고, 조건에 따라 살짝 달라지는 부분은 cx()로 다룹니다.
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() } }, ), ) }