Anatomy and icon assets
Anatomy definitions give each machine part a stable name and a shared styling hook. The anatomy-icons package adds visual maps of those parts for documentation and design review. Together they connect machine output, styled component props, and the visual language used by framework examples. See the parent page Public API foundations and the related pages Component machines and Framework integrations.
Public API role
The anatomy layer is a small public contract between a machine and its consumers. A machine names the parts of its UI, the connection layer applies the matching attributes, and a framework adapter turns those attributes into element props. This lets consumers style a component without depending on its internal state logic.
Stable part contract
An anatomy part has a source name, a data-scope value for the component, and a data-part value for the named region. The contract also provides a selector for styling both the element itself and a matching descendant. The public machine entry point exports the anatomy so consumers can use the same names as the connection layer.
The contract is typed from the declared part names. This makes part names available to prop composition and gives consumers a shared vocabulary for roots, controls, items, content, and other component regions. The names describe structure, not state; state remains exposed through separate data attributes and API values.
References: packages/…/create-anatomy.ts• L1-17 packages/…/accordion.anatomy.ts• L1-4 packages/…/index.ts• L1-3
Naming transformations
Anatomy source names can use the naming style that fits TypeScript. The generated DOM contract uses kebab case for the scope and part values. For example, hoverCard and toggleButton become hover-card and toggle-button. This keeps selectors and attributes consistent across framework adapters.
The anatomy builder removes duplicate names before it creates the final part map. It can also add parts, omit parts, or rename the component scope when a related component needs a controlled variation. These operations preserve the same contract shape while allowing composition.
References: packages/…/create-anatomy.ts• L19-53 packages/…/create-anatomy.test.ts• L20-32 packages/…/create-anatomy.test.ts• L35-55 packages/…/create-anatomy.test.ts• L57-125
Anatomy definitions
Each machine keeps its anatomy beside the machine API. The definition lists the structural parts, while the built part map supplies the attributes used by the connection layer. A consumer therefore receives names that remain aligned with the props produced for each rendered element.
Machine part maps
The machine-specific anatomy is the source of truth for structural names. A simple component can declare a short list, while a compound component can expose parts such as an input, list, item, label, trigger, and positioner. The same map is then spread into the props for those elements.
This relationship makes styling independent from the framework wrapper. React, Solid, Vue, and other adapters can normalize the same part attributes for their own element model while keeping the scope and part values unchanged. See Framework integrations for the adapter boundary.
References: packages/…/accordion.anatomy.ts• L1-4 packages/…/combobox.anatomy.ts• L1-19 packages/…/accordion.connect.ts• L40-106
Styling and prop composition
Connection methods combine anatomy attributes with behavior, state, and accessibility props. The anatomy attributes identify the element for styling, while nearby props describe its role, current state, relationships, and event behavior. Consumers can compose these results with their framework-specific prop helpers without rebuilding the part contract.
The result is a layered boundary: the machine owns behavior, the connection layer owns the complete element contract, and the styling system targets stable scope-and-part selectors. A change to a part name can therefore affect both visual rules and any consumer that composes props by that name.
References: packages/…/accordion.connect.ts• L40-75 packages/…/accordion.connect.ts• L78-107 packages/…/create-anatomy.ts• L31-45
Icon package
@zag-js/anatomy-icons is a visual asset package for anatomy documentation. It exposes React SVG components that show the main regions of supported components. The package does not replace a machine or define its behavior; it gives engineers and readers a quick visual model of the part structure.
Component icon registry
The package exports a registry named allComponents and a typed getComponent lookup. Registry keys use component IDs such as accordion, combobox, and date-picker. The key type makes the supported visual set explicit for consumers that select an icon by component name.
The documentation site uses the registry to resolve an Anatomy element from an ID. If an ID has no registered icon, the site reports that no anatomy is available instead of rendering a missing component. This makes registry membership part of the documentation integration contract.
References: packages/…/index.ts• L46-98 packages/…/index.ts• L1-4 website/…/mdx-components.tsx• L246-262
Accent and palette model
Each icon accepts an accent color and turns it into a fixed palette for the SVG artwork. The palette gives the illustration a consistent set of fills and strokes while allowing the documentation site or another consumer to choose the main accent. SVG props remain available, so the icon can take normal sizing and presentation props.
The shared palette and gradient helpers are visual tools. They do not alter anatomy names or machine state. Their role is to keep the icon set coherent when the same component is shown in different documentation views.
References: packages/…/create-component.tsx• L4-15 packages/…/create-palette.ts• L5-24 packages/…/create-gradient.ts• L3-10
Anatomy visualization flow
The anatomy path turns a machine’s named structure into framework-ready props, while the icon path turns the same component concept into a visual guide for documentation. These paths meet at the component name and remain separate in responsibility.
The following diagram shows how structural names reach styled elements and how component IDs reach visual anatomy diagrams.
flowchart LR
A[Machine anatomy definition] --> B[Built scope and part attributes]
B --> C[Connection API prop composition]
C --> D[Framework adapter normalization]
D --> E[Rendered component elements]
E --> F[CSS selectors and visual states]
G[Component ID] --> H[Anatomy icon registry]
H --> I[React SVG anatomy icon]
I --> J[Documentation anatomy view]
A part-name change must stay aligned across the anatomy definition, the connection methods that apply its attributes, and the styles or examples that target the resulting DOM contract. An icon update changes the visual guide only, but a registry key change can stop a documentation view from resolving.
References: packages/…/accordion.anatomy.ts• L1-4 packages/…/accordion.connect.ts• L40-106 packages/…/index.ts• L46-98 website/…/mdx-components.tsx• L246-262
Change checklist
When these files or sections are changed, remember to consider these:
- A scope or part rename changes
data-scopeordata-partvalues. Check connection props, consumer selectors, and any anatomy examples that use the old contract. - A new machine part must be added to the machine anatomy before a connection method can expose it. Keep the exported anatomy and the rendered prop path aligned.
- A new icon requires a component module and a registry entry. The registry key must match the component ID used by documentation.
- A palette index change affects every SVG that uses that index. Review the whole icon set rather than only the helper that creates the palette.
- A change to the icon registry changes
ComponentAnatomyNameand lookup behavior. Check documentation IDs that resolve icons by name.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A part is renamed in an anatomy definition but not in the connection layer or consumer styles | The element loses its expected style hook or a composed prop path targets a missing part | Treat the anatomy definition and the connection methods as one contract. Check both sides of the rename. |
A component ID is missing from allComponents | The documentation anatomy view shows that no anatomy is available for the ID | Add the icon module and registry entry together. Keep the key equal to the documented component ID. |
| A component icon uses an invalid or unsupported accent color | Palette creation or SVG rendering can produce an unusable visual asset | Pass a valid color value through the icon boundary and review the rendered result. |
The .parts(...) builder is called again after parts are set | Anatomy creation throws instead of extending the existing definition | Use extendWith(...) for added names. Use the builder once for the initial part list. |
Key files
| File | Why to read it |
|---|---|
| packages/…/create-anatomy.ts | Defines the shared scope, part, selector, and composition contract. |
| packages/…/create-anatomy.test.ts | Shows the supported naming, de-duplication, extension, omission, and rename behavior. |
| packages/…/accordion.anatomy.ts | Gives a small example of a machine declaring its public parts. |
| packages/…/combobox.anatomy.ts | Shows how a larger component exposes several related regions. |
| packages/…/accordion.connect.ts | Shows how part attributes join behavior and accessibility props. |
| packages/…/index.ts | Defines the icon registry and the component-name type used by consumers. |
| packages/…/create-component.tsx | Defines the common React SVG boundary and accent-color input. |
| packages/…/create-palette.ts | Defines the shared visual palette used by anatomy icons. |
| website/…/mdx-components.tsx | Shows how documentation resolves and renders an anatomy icon by component ID. |