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

ct-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 Cell{" "} - you don't need a handler unless you want to add extra logic beyond just updating the value.

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