diff --git a/docs/common/COMPONENTS.md b/docs/common/COMPONENTS.md index 76c16a7e7..e1abe44c3 100644 --- a/docs/common/COMPONENTS.md +++ b/docs/common/COMPONENTS.md @@ -6,7 +6,7 @@ A styled button component matching the regular `button` API. Pass a handler to t type InputSchema = { count: Cell }; type OutputSchema = { count: Cell }; -const MyRecipe = recipe("MyRecipe", ({ count }) => { +const MyRecipe = recipe(({ count }) => { const handleClick = handler }>((_event, { count }) => { count.set(count.get() + 1); }); @@ -22,7 +22,7 @@ Notice how handlers are bound to the cell from the input schema _in_ the VDOM de (For even more detail, see `HANDLERS.md`) -# Bidirectional Binding with $ Prefix +## Bidirectional Binding with $ Prefix Many CommonTools components support **bidirectional binding** through the `$` prefix. This powerful feature automatically updates cells when users interact with components, eliminating the need for explicit onChange handlers in most cases. @@ -96,6 +96,7 @@ const toggle = handler<{detail: {checked: boolean}}, {item: Cell}>( ``` The bidirectional binding version is: + - **Simpler**: No handler definition needed - **Less code**: One line instead of five - **More maintainable**: Less surface area for bugs @@ -123,7 +124,7 @@ const toggle = handler( one-directional binding. Note that the actual name for the `onChange` handler may be different depending -on the component being used. For example, uses `onct-change`. +on the component being used. For example, `` uses `onct-change`. Consult the component for details. ### Validation Example @@ -152,7 +153,7 @@ const validatedValue = derive(rawInput, (value) => { This approach separates concerns: bidirectional binding handles the UI sync, while derive handles validation logic. -# Styling: String vs Object Syntax +## Styling: String vs Object Syntax Different element types accept different style syntax in CommonTools JSX. This is a common source of TypeScript errors. @@ -242,7 +243,7 @@ CommonTools custom elements (`common-hstack`, `common-vstack`, `ct-card`, etc.) ``` -# ct-input +## ct-input The `ct-input` component demonstrates bidirectional binding perfectly: @@ -250,7 +251,7 @@ The `ct-input` component demonstrates bidirectional binding perfectly: type InputSchema = { value: Cell }; type OutputSchema = { value: Cell }; -const MyRecipe = recipe("MyRecipe", ({ value }) => { +const MyRecipe = recipe(({ value }: InputSchema) => { // Option 1: Bidirectional binding (simplest) const simpleInput = ; @@ -275,7 +276,7 @@ const MyRecipe = recipe("MyRecipe", ({ value }) => { Both inputs update the cell, but the second one logs changes. Use the simple bidirectional binding unless you need the extra logic. -# ct-select +## ct-select The `ct-select` component creates a dropdown selector. **Important:** It uses an `items` attribute with an array of `{ label, value }` objects, **not** HTML `