الأمثلة
أمثلة عملية، وعروض حيّة.
اختر مثالًا لتفتحه بملء الشاشة: المعاينة الحية وكوده المصدري جنبًا إلى جنب.
اختر مثالًا لتفتحه بملء الشاشة: المعاينة الحية وكوده المصدري جنبًا إلى جنب.
css() تنشئ الـ classes، و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() } }, ), ) }