/// import { Cell, computed, NAME, recipe, UI } from "commontools"; import Counter from "../counter.tsx"; import Note from "../notes/note.tsx"; // Simple random ID generator (crypto.randomUUID not available in pattern env) const generateId = () => `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 11)}`; type Input = Record; type Result = { counterAValue: number; counterBValue: number; counterCValue: number; }; export default recipe( "ct-picker demo", (_) => { // Create counter instances - these are OpaqueRefs to recipe results const counterA = Counter({ value: 10 }); const counterB = Note({ content: "This is item B (a Note)", noteId: generateId(), }); const counterC = Counter({ value: 30 }); const selectedIndex = Cell.of(0); const items = [counterA, counterB, counterC]; const selection = computed(() => items[selectedIndex.get()]); return { [NAME]: "ct-picker demo", [UI]: (

ct-picker Component Demo

{ selectedIndex.set(Math.max(0, selectedIndex.get() - 1)); }} > Prev { selectedIndex.set( Math.min(items.length - 1, selectedIndex.get() + 1), ); }} > Next
{selection}
{/* The cast is because OpaqueCell does not satisfy CellLike, but... it is */}
), counterAValue: counterA.value, counterBValue: 0, // Note doesn't have .value counterCValue: counterC.value, }; }, );