|
| 1 | +--- |
| 2 | +name: robomous-component-development |
| 3 | +description: Builds or changes a component of @robomous/ui-core, from requirement to a verified, documented, exported part. Covers deciding whether a new component is needed at all, choosing its foundation (reuse, compose, native HTML, Radix/Base UI/cmdk/vaul, UI SDK, custom), anatomy and data-slot, the public API, semantic tokens, accessible interaction, behaviour tests, the docs page and demos, and the verification commands. Use whenever a task in this repository adds a component, a part, a prop or a variant, or changes how a component behaves or looks. |
| 4 | +--- |
| 5 | + |
| 6 | +# Build a Robomous component |
| 7 | + |
| 8 | +Work through the steps in order. Each one links to the document that owns the rule. Read the |
| 9 | +linked section the first time you meet it; this file does not repeat it. Repository-wide rules are |
| 10 | +in [AGENTS.md](../../../AGENTS.md). |
| 11 | + |
| 12 | +## 1. Pin down the requirement |
| 13 | + |
| 14 | +- Restate the contract in a few lines: what the reader does, what they see, which states exist. |
| 15 | +- Find the GitHub issue. If there is none, or the task grows past it, say so and update or open |
| 16 | + one before you build. If you cannot read it, say so in your report and work from the task as |
| 17 | + given. |
| 18 | +- Name the APG pattern it follows, if it is interactive: <https://www.w3.org/WAI/ARIA/apg/patterns/>. |
| 19 | + |
| 20 | +## 2. Look for what already exists |
| 21 | + |
| 22 | +- Read `docs/generated/llms.txt`, then the reference of every component that sounds close |
| 23 | + (`docs/generated/components/<slug>.md`), including its *When not to use* and *Related*. |
| 24 | +- A prop or variant on an existing component beats a new component. A new component that |
| 25 | + duplicates one is a defect. |
| 26 | + |
| 27 | +## 3. Decide whether composition is enough |
| 28 | + |
| 29 | +Compose existing Robomous components when they cover the behaviour: SplitButton is Button, |
| 30 | +ButtonGroup and DropdownMenu. See [references/examples.md](references/examples.md). |
| 31 | + |
| 32 | +## 4. Choose the foundation |
| 33 | + |
| 34 | +Take the first rung of [ADR 0001, section 1](../../../docs/adr/0001-ui-sdk-adoption.md#1-the-order-in-which-a-component-chooses-its-foundation) |
| 35 | +that meets the contract: native HTML, then Radix, Base UI, cmdk or vaul, which are already |
| 36 | +installed and wrapped here. A component from the shadcn registry starts with |
| 37 | +`yes n | pnpm dlx shadcn@latest add <name> --yes`. Never reinstall an existing one. What the CLI |
| 38 | +writes is a draft: read the diff, check that the files it offered to overwrite are unchanged, run |
| 39 | +`pnpm format`, and adapt it in the steps below. |
| 40 | + |
| 41 | +## 5. UI SDK only when the ADR allows it |
| 42 | + |
| 43 | +Only when no primitive provides the behaviour ([ADR 0001, section 2](../../../docs/adr/0001-ui-sdk-adoption.md#2-when-ui-sdk-is-used)). |
| 44 | +Then use the `ui-sdk` skill, under the overrides in [AGENTS.md, *Agent skills*](../../../AGENTS.md#agent-skills). |
| 45 | +Interaction logic goes in `src/behaviors/<name>.ts`, presentation in `src/components/<name>.tsx`. |
| 46 | +Report the measurements in [ADR 0001, section 6](../../../docs/adr/0001-ui-sdk-adoption.md#6-how-adoption-is-judged). |
| 47 | + |
| 48 | +## 6. Define the anatomy |
| 49 | + |
| 50 | +- One file, `src/components/<name>.tsx`. One exported function per part, named |
| 51 | + `<Component><Part>`. |
| 52 | +- Every part renders a `data-slot` (`<name>`, `<name>-<part>`) and merges `className` last |
| 53 | + through `cn`. A part with no classes of its own, like Collapsible's, passes `className` through |
| 54 | + untouched. |
| 55 | +- Write the composition tree you will put on the docs page now. It keeps the parts honest. |
| 56 | + |
| 57 | +## 7. Define the public API |
| 58 | + |
| 59 | +- Match sibling components. Use the `variant` and `size` names that exist, and the |
| 60 | + controlled/uncontrolled pairs `value`/`defaultValue`/`onValueChange` and |
| 61 | + `open`/`defaultOpen`/`onOpenChange`. |
| 62 | +- Variants are a `cva` object with `defaultVariants`, and the variant function is exported. |
| 63 | +- Give every prop of your own a JSDoc comment, and the part one saying what it is for. Both feed |
| 64 | + the API tables and the agent docs. |
| 65 | +- The API table lists only props the part declares in its own type, and inherited props it gives |
| 66 | + a default in the destructuring (`ratio = 1`). A part that spreads everything documents nothing: |
| 67 | + declare or default the props a reader needs to see. |
| 68 | +- Spread the rest onto the element, typed from `React.ComponentProps<…>` or the primitive's props. |
| 69 | + An icon-only control requires its accessible name, as SplitButton requires `menuLabel`. |
| 70 | + |
| 71 | +## 8. Paint with roles |
| 72 | + |
| 73 | +Colour only through role utilities ([DESIGN, *Tokens*](../../../docs/DESIGN.md#tokens)). Write states |
| 74 | +with shadcn's variants, never the attribute a library emits |
| 75 | +([DESIGN, *State attributes*](../../../docs/DESIGN.md#state-attributes)). Check |
| 76 | +[DESIGN, *Status vocabulary*](../../../docs/DESIGN.md#status-vocabulary), |
| 77 | +[*Action hierarchy*](../../../docs/DESIGN.md#action-hierarchy) and |
| 78 | +[*Motion*](../../../docs/DESIGN.md#motion). Both themes must work through roles alone. |
| 79 | + |
| 80 | +## 9. Make it accessible |
| 81 | + |
| 82 | +Native semantics first, then the primitive's. Keyboard parity with the pointer, focus that stays |
| 83 | +visible and returns where it came from, names on every control, and state the component announces |
| 84 | +itself ([DESIGN, *Accessibility*](../../../docs/DESIGN.md#accessibility)). A `<button>` renders |
| 85 | +`type="button"` unless asked. |
| 86 | + |
| 87 | +## 10. Test the behaviour |
| 88 | + |
| 89 | +`tests/components/<name>.test.tsx`, or the file its group already uses. Query by role and name, and |
| 90 | +assert what a screen would lose: roles, names, `aria-*`, focus, and the outcome of every key and |
| 91 | +click the pattern defines. Cover both controlled and uncontrolled use. Never pin class strings |
| 92 | +([CONTRIBUTING, *Tests*](../../../docs/CONTRIBUTING.md#tests)). |
| 93 | + |
| 94 | +## 11. Document it |
| 95 | + |
| 96 | +- Export each part by name from `src/index.ts`, beside its group. |
| 97 | +- Add the page `examples/catalog/src/content/components/<name>.mdx`, with frontmatter `title`, |
| 98 | + `description`, `related`, `builtOn`, `whenToUse` and `whenNotToUse`. The last two are plain |
| 99 | + strings of one or two sentences, and `whenNotToUse` names the component to use instead. |
| 100 | +- Add demos in `examples/catalog/src/demos/<name>/`, one story per file: an overview, each variant |
| 101 | + and state, and a composition. |
| 102 | +- Add the slug to a group in `examples/catalog/src/lib/groups.ts`, and a row in |
| 103 | + `docs/components/README.md` (the component table; the root README has none). |
| 104 | +- A new component changes the component count written in prose. Find it with |
| 105 | + `grep -rniE "fifty-[a-z]+|[0-9]+ (react )?components" README.md src/index.ts docs/DESIGN.md docs/components examples/catalog/src/content`. |
| 106 | + Leave dated records (ADRs, baselines) as they are. |
| 107 | +- Copy the page's structure from a sibling (Usage, Composition, Examples, Guidelines, |
| 108 | + Accessibility). Only `Preview`, `Callout`, `Guidelines` and `Keyboard` may appear outside code |
| 109 | + fences. |
| 110 | + |
| 111 | +## 12. Verify |
| 112 | + |
| 113 | +Run, in this order, and fix before moving on. `docs:agents` comes before `pnpm test`, because |
| 114 | +the tests check that `docs/generated/` is current: |
| 115 | + |
| 116 | +``` |
| 117 | +pnpm format:check && pnpm lint |
| 118 | +pnpm build && pnpm docs:agents |
| 119 | +pnpm test && pnpm docs:check |
| 120 | +pnpm test:package # when exports, dependencies or styles.css changed |
| 121 | +``` |
| 122 | + |
| 123 | +Commit `docs/generated/`. Then walk [references/checklist.md](references/checklist.md) before you |
| 124 | +call the work done, and say in the PR which items do not apply and why. If you cannot open a |
| 125 | +browser for the light and dark check, say so instead of ticking it. |
0 commit comments