import { computed, NAME, pattern, UI, Writable } from "commonfabric"; import Counter from "../counter/counter.tsx"; import Note from "../notes/note.tsx"; type Input = Record; export type Result = { counterAValue: number; counterBValue: number; counterCValue: number; }; export default pattern( (_) => { // Create counter instances - these are OpaqueRefs to pattern results const counterA = Counter({ value: 10 }); const counterB = Note({ content: "This is item B (a Note)", }); const counterC = Counter({ value: 30 }); const selectedIndex = new Writable(0); const items = [counterA, counterB, counterC]; const selection = computed(() => items[selectedIndex.get()]); return { [NAME]: "cf-picker demo", [UI]: (

cf-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, }; }, );