port-base-ui-component
Port one Base UI component into effect/ui/kit as an unstyled view function or headless component. Use when asked to add a kit component that Base UI has, such as Switch, Toggle, Tabs or Dialog.
Port a Base UI component into the kit
One run ports one component. If the port needs another kit component that doesn't exist yet, such as a Popover, stop and open a separate issue for it. When the missing piece only backs an optional feature, leave it out and document any resulting limitation in the kit's own terms.
Read references/conventions.md before step 3.
Switch (packages/effect/src/ui/kit/Switch.ts and
packages/effect/test/ui/kit/Switch.test.ts) is the worked example of a view
function. For a headless component,
ai-docs/src/90_ui/03_headless/10_drawing-a-headless-component.ts and
ai-docs/src/90_ui/fixtures/kit/Listbox.ts show the core API, and the
conventions say where the kit wraps it.
Checklist
Work top to bottom. Put the notes from steps 1 to 3 in the PR description.
-
Read Base UI. Fetch
https://base-ui.com/react/components/<name>.md(the.mdpage has the full API tables) and the source underpackages/react/src/<name>/in https://github.com/mui/base-ui. Note:- the parts (anatomy) and the element each one renders
- the props, and which are controlled,
default*or React-only (className,style,render, refs) - the state, and the data attributes on each part
- the keyboard interaction, and whether a native element gives it
(
useButtonwithnative) or a key handler does - the ARIA roles and attributes, and which element carries each
- the contexts it reads (
Field,Form,Direction): each is a dependency for the scope rule above
-
Read Foldkit. Look for
packages/ui/src/<name>/on thecodex/layers-and-submodelsbranch of https://github.com/foldkit/foldkit. If it exists, note where it differs from Base UI and why. It is the closest reference for the same ideas without React. -
Decide the shape, using the conventions:
- view function, headless component, or (rarely) a component with slots. Count the state Base UI keeps that the port puts off
- one element returned as a builder with chained
.children(...), or several arranged inview - the parts, the tag each accepts, and the attributes and events each owns
- each part's arguments, and the markup a part adds and where it goes
- the props, and the events:
on<Event>options for a view function,<Name>Eventsfor a component - for a component, the Model, which holds only interaction state the consumer never stores
- for a component, its
restore:falsewhen the Model depends on a Command anupdatestarted or on DOM state such as hover, focus or a measurement, a function that clears those fields when the rest should come back after Back, or left out. A measurement that scroll restoration needs may stay: seeai-docs/src/90_ui/05_state/70_history-restore.ts - the message and event names: past-tense facts for messages, and for
each event the report/request test in
ai-docs/src/90_ui/01_basics/20_naming.ts - the Base UI features you leave out, and why
-
Implement
packages/effect/src/ui/kit/<Name>.ts, unstyled, and addexport * from "./<Name>.ts"topackages/effect/src/ui/kit/index.tsin alphabetical order, with the JSDoc block the other entries have. That file is written by hand: don't runpnpm codegenfor it. -
Test in
packages/effect/test/ui/kit/<Name>.test.ts. Test a view function withScene.makeand a small consumer component that calls it, and call it directly with aView.makeHelperhelper for its attributes and markup (a non-interactive view function already covered directly needs noScene, as inSeparator.test.ts). Test a headless component withScene.makeand a stand-in view for rendered interaction,Story.partsfor a part on its own, andStory.makeforupdateand Command tests. Behaviour that needs a real DOM, such as a mount that measures or moves focus, goes in<Name>Document.test.tsunder// @vitest-environment happy-dom, with the helpers inpackages/effect/test/ui/kit/utils/document.ts. Cover, in as few tests as you can:- each interaction sends the right message or emits the right event
- disabled and read-only, each in its own test: what each suppresses is in the "State" section of the conventions
- the ARIA and data attributes for each state, on every part that has them
- the keyboard: fire
keydownfor the keys the component handles. For keys a native element handles, assert that a part rejects another tag - the markup a part function adds, such as the form field
- precedence: on each part, a consumer value for every attribute the part owns loses, both when the part sets it and when the state leaves it absent, while the consumer's class and other attributes stay. For a view function's part, that holds for a value chained after the part too
- for a view function, an element that already handles an event fails the render if any option reserves that event, in every state, whether the handler was set before the call or chained after it. Check that the consumer's handler stays when no option reserves the event
Add
packages/effect/typetest/ui/kit/<Name>.tst.tsfor each part: the builder it returns, the inferred message type and requirements, and the tags it rejects. Then break the code (for example, drop the disabled guard, or theundefineda part writes for an absent state) and check that a test fails. -
Document and check.
- Keep upstream research and links in this skill and the PR. In kit
code, comments and JSDoc, describe the kit's own behavior without
naming the upstream project. Check that this search returns no
matches:
git grep -inE 'base[[:space:]_./-]*ui|@mui/base' -- packages/effect/src/ui/kit/<Name>.ts packages/effect/test/ui/kit/<Name>*.test.ts packages/effect/typetest/ui/kit/<Name>.tst.ts. - Write the module JSDoc in the shape the conventions give, following
the
jsdocsskill. The one example goes in a fence opened withts import.meta.vitest, so it runs as a doctest. A component's example renders it withHtmlServer.renderToHtmland throws unless the HTML shows one thing, such as the consumer's class next to the part's role, and a utility's example throws unless a result is the one expected. - Add
@since,@categoryand@stability unstableto every public declaration, as the rest of the kit has. - Name the parts argument after the component in the JSDoc and the tests, as the "Call shape" section of the conventions says.
- Add a changeset with the
changesetsskill. The kit is@stability unstable, so a new component is"effect": patch. - Run each of these from the repository root, with
nix develop -c:pnpm lint-fix,pnpm check,pnpm test --run packages/effect/test/ui/kit/<Name>.test.ts(and theDocumenttest),pnpm test-types packages/effect/typetest/ui/kit/<Name>.tst.ts,pnpm doctest --run packages/effect/src/ui/kit/<Name>.ts,pnpm jsdocs --checkandpnpm circular. Never run barepnpm testorpnpm doctest, which start watch mode.
- Keep upstream research and links in this skill and the PR. In kit
code, comments and JSDoc, describe the kit's own behavior without
naming the upstream project. Check that this search returns no
matches: