Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(docsite): use resolved import path and per-component usage in registry (#2598)

Cindy Zhang927a387e6980
diff --git a/apps/docsite/scripts/generate-data.mjs b/apps/docsite/scripts/generate-data.mjs
index 0706b05e9f..b64dd8e245 100644
--- a/apps/docsite/scripts/generate-data.mjs
+++ b/apps/docsite/scripts/generate-data.mjs
@@ -185,6 +185,24 @@ function findDocFilesRecursive(dir) {
return results;
}
+/**
+ * Resolve the correct import path for a component given its package directory
+ * and the subdirectory it lives in. Checks the package.json "exports" field to
+ * find a matching subpath export (e.g. `@xds/core/Chat`).
+ *
+ * Falls back to the package name when no explicit export is found.
+ */
+function resolveImportPathForPkg(pkgDir, directory) {
+ const pkgJsonPath = path.join(REPO_ROOT, pkgDir, 'package.json');
+ if (!fs.existsSync(pkgJsonPath)) return null;
+ const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
+ if (pkg.exports && pkg.exports[`./${directory}`]) {
+ return `${pkg.name}/${directory}`;
+ }
+ // No matching export — fall back to package root
+ return pkg.name;
+}
+
// ── Package discovery ──────────────────────────────────────────────────
/**
@@ -303,7 +321,7 @@ async function generateComponentRegistry() {
const pkgJson = JSON.parse(fs.readFileSync(path.join(REPO_ROOT, dir, 'package.json'), 'utf-8'));
const allDocFiles = findDocFilesRecursive(srcDir);
if (allDocFiles.length > 0) {
- componentPackages.push({name: pkgJson.name, srcDir});
+ componentPackages.push({name: pkgJson.name, srcDir, dir});
}
}
@@ -370,6 +388,11 @@ async function generateComponentRegistry() {
// Sub-entries whose name differs from the doc name are
// sub-components — hide them from the overview page.
const isSubEntry = subName !== doc.name;
+ // Each sub-component may have its own usage; fall back to
+ // the parent doc's usage only when the sub doesn't define one.
+ const subUsage = sub.usage
+ ? sanitizeForJson(sub.usage)
+ : usage;
pendingSubComponents.push({
name: subName,
displayName: requireDisplayName(
@@ -378,6 +401,7 @@ async function generateComponentRegistry() {
),
moduleName: sub.name || subName,
directory: entry.name,
+ importPath: resolveImportPathForPkg(pkg.dir, entry.name),
group,
category,
isHiddenFromOverview: sub.isHiddenFromOverview ?? isHiddenFromOverview,
@@ -386,7 +410,7 @@ async function generateComponentRegistry() {
hidden,
parentDoc: doc.name,
props: Array.isArray(sub.props) ? sanitizeForJson(sub.props) : [],
- usage,
+ usage: subUsage,
theming,
params: null,
returns: null,
@@ -407,6 +431,7 @@ async function generateComponentRegistry() {
),
moduleName: name,
directory: entry.name,
+ importPath: resolveImportPathForPkg(pkg.dir, entry.name),
group,
category,
isHiddenFromOverview,
@@ -435,6 +460,7 @@ async function generateComponentRegistry() {
),
moduleName: name.startsWith('use') ? name : `XDS${name}`,
directory: entry.name,
+ importPath: resolveImportPathForPkg(pkg.dir, entry.name),
group,
category,
isHiddenFromOverview,
@@ -554,6 +580,8 @@ export interface ComponentEntry {
displayName: string;
moduleName: string;
directory: string;
+ /** Resolved import path, e.g. \`@xds/core/Chat\`. Derived from package.json exports. */
+ importPath: string | null;
group: string | null;
/** Functional category for the overview gallery (Actions, Inputs, etc.) */
category: string | null;
diff --git a/apps/docsite/src/components/component-detail/ComponentDetailClient.tsx b/apps/docsite/src/components/component-detail/ComponentDetailClient.tsx
index 3e01deada4..b145eb1295 100644
--- a/apps/docsite/src/components/component-detail/ComponentDetailClient.tsx
+++ b/apps/docsite/src/components/component-detail/ComponentDetailClient.tsx
@@ -49,7 +49,8 @@ function OverviewContent({
hasShowcase,
}: ComponentDetailClientProps & {hasShowcase: boolean}) {
const isHook = comp.params != null;
- const importPath = `import {${comp.moduleName}} from '${pkg}/${comp.directory}'`;
+ const importFrom = comp.importPath ?? `${pkg}/${comp.directory}`;
+ const importPath = `import {${comp.moduleName}} from '${importFrom}'`;
return (
<XDSVStack gap={8}>
diff --git a/packages/core/src/Chat/Chat.doc.mjs b/packages/core/src/Chat/Chat.doc.mjs
index 02200ec681..be05a93a8b 100644
--- a/packages/core/src/Chat/Chat.doc.mjs
+++ b/packages/core/src/Chat/Chat.doc.mjs
@@ -273,6 +273,23 @@ const chatLayoutComponent = {
name: 'XDSChatLayout',
displayName: 'Chat Layout',
description: 'Layout shell for full chat interfaces. Messages flow in normal page flow, composer is fixed to the bottom with a frosted glass dock. Adapts density (compact/balanced/spacious) automatically via container width observation. Includes built-in auto-scroll, a "New messages" scroll-to-bottom button, and a frosted glass blur layer behind the composer. By default the layout root is the scroll container; pass scrollRef to delegate scrolling to a parent element or the document body.',
+ usage: {
+ description: 'XDSChatLayout is the layout shell for full-page chat interfaces. It renders messages in normal page flow and docks the composer to the bottom with a frosted glass blur layer. Density adapts automatically via container width observation. Use it to wrap XDSChatMessageList and XDSChatComposer for a complete chat experience with built-in auto-scroll and a scroll-to-bottom button.',
+ bestPractices: [
+ { guidance: true, description: 'Pass XDSChatMessageList as children and XDSChatComposer as the composer prop for a complete chat interface.' },
+ { guidance: true, description: 'Provide an emptyState so new conversations show a prompt instead of a blank screen.' },
+ { guidance: true, description: 'Use scrollRef when the chat is embedded in a page where a parent element handles scrolling.' },
+ { guidance: false, description: 'Don\'t apply a fixed height on the layout — let it fill its container with flex: 1.' },
+ { guidance: false, description: 'Don\'t render multiple ChatLayout instances in the same scroll container — each expects to own its scroll context.' },
+ ],
+ anatomy: [
+ { name: 'Message area', required: true, description: 'Scrollable region for messages. Renders children (typically XDSChatMessageList) in a flex column that pushes content to the bottom when the list is short.' },
+ { name: 'Frosted glass dock', required: true, description: 'Sticky or fixed container at the bottom with a backdrop-blur layer. Houses the scroll button and composer.' },
+ { name: 'Scroll-to-bottom button', required: false, description: 'Appears when the user scrolls up or new messages arrive. Defaults to XDSChatLayoutScrollButton; pass null to hide or a custom element to override.' },
+ { name: 'Composer', required: true, description: 'The input area for sending messages, typically XDSChatComposer. Docked at the bottom inside the frosted glass layer.' },
+ { name: 'Empty state', required: false, description: 'Centered placeholder shown when no messages exist. Use XDSEmptyState for a consistent look.' },
+ ],
+ },
props: [
{name: 'children', type: 'ReactNode', description: 'Message content — typically XDSChatMessageList. Flows naturally in the page and scrolls with the container.', required: true},
{name: 'composer', type: 'ReactNode', description: 'Composer element — typically XDSChatComposer. Fixed to the bottom with a frosted glass dock.', required: true,