示例
实用示例,实时演示。
挑一个示例全屏打开,运行效果和源码并排呈现。
挑一个示例全屏打开,运行效果和源码并排呈现。
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() } }, ), ) }