Replace a Core component
Use a component replacement only when an integration must intentionally own a Core component identity.Decide whether to replace
Most components should not use replaces. Give a new component its own name and let apps choose it explicitly. Replace Core only when your component must become the default for one Core identity everywhere the integration is active.
Use it when
- Your component intentionally serves the same role as one specific Core component.
- Every app that loads the integration should get your component from unqualified component detail,
component --list, search,swizzle <Name>, and issue routing. - You have tested both the replacement and explicit access to the original Core component.
Do not use it when
- Your component is an alternative, variant, wrapper, or product-specific extension. Give it a unique name instead.
- You only need to resolve an accidental name collision.
- You want the replacement in only one screen or workflow. Replacement applies across the app wherever the integration is active.
Set the replacement
components/AcmeSideNav.doc.mjs
javascript/** @type {import('@astryxdesign/cli/authoring').ComponentDoc} */export default {type: 'component',name: 'AcmeSideNav',displayName: 'Acme Side Nav',replaces: 'SideNav',import: '@acme/astryx-widgets/components/AcmeSideNav',usage: {description: 'Product navigation for Acme apps.'},props: [],};
| Field | Type | Required | Description |
|---|---|---|---|
| replaces | string | no | Integration components only: the exact name of the Core ComponentDoc this component takes over for unqualified lookup, so every app that loads the integration gets it from component detail, component lists, search, swizzle <Name>, and issue routing; swizzle --list keeps listing Core names. The Core original stays reachable with --package @astryxdesign/core. It takes effect only when the package's peer range starts at the release that applies it, "@astryxdesign/cli": ">=0.6.7" or later; without such a range the component keeps its own name and doctor integration components warns. Set it only to intentionally own a Core identity; give an alternative or variant its own name instead. |
From ComponentDoc: astryx docs authoring component-doc
The replacement turns on only when your package declares the first CLI release that applies it. Add this to its package.json:
package.json
json{"peerDependencies": {"@astryxdesign/cli": ">=0.6.7"},"peerDependenciesMeta": {"@astryxdesign/cli": {"optional": true}}}
- Any
@astryxdesign/clirange that starts at that release or later turns it on, including the>=0.7.0that earlierintegration add themeandintegration add doc --parentwrote. - Without such a range, the component keeps its own name, the Core component stays selected (a component named like its target stays ambiguous by that bare name, as before), and
doctor integration componentswarns with the range to add. Apps that load such a package see no change. replacesnames the CoreComponentDocidentity, not its display label, import path, or a standalone hook.- Your component may keep a distinct name or use the same name as the target. A distinct name remains directly addressable on older CLIs that ignore
replaces. --package @astryxdesign/corealways selects the original Core component, and--packagewith your package selects your component by either name.- Replacing
SideNavreplaces only that name.SideNavItemand the otherSideNavparts stay Core components; document any parts your package provides under their own names. swizzle --listlists Core components, including the one you replace.swizzle SideNavcopies your component, andswizzle SideNav --package @astryxdesign/corecopies the original.
Check replacement resolution
bashnpx astryx doctor integration componentsnpx astryx component SideNavnpx astryx component AcmeSideNavnpx astryx component SideNav --package @astryxdesign/core
- Once the package declares the range, a missing target, invalid value, second replacement for one target in the same package, or a replacement named after a different Core component is an error. Without the range,
doctor integration componentsreports each of these as a warning. - When several integrations replace one target, explicit configuration beats the automatic pick. Among explicitly configured integrations, the later package wins and Doctor warns. Among autolinked integrations alone, the dependency listed later in
package.jsonwins and Doctor warns.