import { Default, handler, ifElse, NAME, pattern, UI, Writable, } from "commonfabric"; interface CheckboxDemoInput { simpleEnabled: Writable>; trackedEnabled: Writable>; } export interface CheckboxDemoOutput extends CheckboxDemoInput {} // Handler for checkbox changes - only needed when you want additional logic // Defined at module scope as required by the pattern system const toggleWithLogging = handler< { detail: { checked: boolean } }, { enabled: Writable } >( ({ detail }, { enabled }) => { const newValue = detail?.checked ?? false; enabled.set(newValue); // Additional side effects console.log("Checkbox toggled to:", newValue); }, ); export default pattern( ({ simpleEnabled, trackedEnabled }) => { return { [NAME]: "Checkbox Demo", [UI]: (

cf-checkbox Bidirectional Binding Demo

Simple Bidirectional Binding (Preferred)

Using $checked alone - no handler needed! The cell automatically updates.

Enable Simple Feature

{ifElse( simpleEnabled, "✓ Feature is enabled!", "⚠ Feature is disabled", )}

With Handler for Additional Logic

Use a handler when you need to run additional code (logging, validation, side effects)

Enable Tracked Feature

Value: {ifElse(trackedEnabled, "✓ Enabled", "⚠ Disabled")}

(Check console for logging)

Key Takeaway

$checked automatically updates the Writable{" "} - you don't need a handler unless you want to add extra logic beyond just updating the value.

), simpleEnabled, trackedEnabled, }; }, );