Skip to content

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

TypeScript

docs(lab): render DrawerHeader on the docsite (#7213)

Xinzi Zhouab8805fbd3d0
diff --git a/apps/docsite/src/__tests__/data-extraction.test.ts b/apps/docsite/src/__tests__/data-extraction.test.ts
index 697430881a..dae1aad7f4 100644
--- a/apps/docsite/src/__tests__/data-extraction.test.ts
+++ b/apps/docsite/src/__tests__/data-extraction.test.ts
@@ -16,6 +16,7 @@ import {fileURLToPath} from 'node:url';
import {describe, it, expect} from 'vitest';
import {docs as chatDocs} from '../../../../packages/core/src/Chat/Chat.doc.mjs';
import {docs as drawerDocs} from '../../../../packages/lab/src/Drawer/Drawer.doc.mjs';
+import {docs as drawerHeaderDocs} from '../../../../packages/lab/src/Drawer/DrawerHeader.doc.mjs';
import docsiteConfig from '../../astryx.config.mjs';
import {packages} from '../generated/packageRegistry';
import {
@@ -1228,6 +1229,25 @@ describe('exampleRegistry', () => {
);
});
+ it('gives DrawerHeader a visible showcase and projects its docs into example blocks', () => {
+ const headerBlocks = blocks.filter(
+ block => block.exampleFor === 'DrawerHeader',
+ );
+ const labels = drawerHeaderDocs.examples!.map(example => example.label);
+ expect(headerBlocks).toHaveLength(labels.length + 1);
+ expect(
+ headerBlocks.every(block => block.sourcePackage === '@astryxdesign/lab'),
+ ).toBe(true);
+
+ // Like DialogHeader, the page leads with a rendered header rather than an
+ // empty preview; every authored example also runs live.
+ expect(headerBlocks.filter(block => block.isShowcase)).toHaveLength(1);
+ expect(showcaseRegistry.DrawerHeader).toBeTypeOf('function');
+ expect(
+ exampleRegistry.DrawerHeader.map(example => example.name).sort(),
+ ).toEqual([...labels].sort());
+ });
+
it('Button has multiple examples', () => {
const buttonExamples = exampleRegistry['Button'];
expect(buttonExamples.length).toBeGreaterThanOrEqual(3);
diff --git a/internal/shadcn-registry/routes.lock.json b/internal/shadcn-registry/routes.lock.json
index 3c73fb92d8..3327c4d6ee 100644
--- a/internal/shadcn-registry/routes.lock.json
+++ b/internal/shadcn-registry/routes.lock.json
@@ -1990,6 +1990,16 @@
"path": "examples/divider/vertical",
"aliases": []
},
+ {
+ "name": "example-drawer-header-with-close-button",
+ "path": "examples/drawer-header/with-close-button",
+ "aliases": []
+ },
+ {
+ "name": "example-drawer-header-with-subtitle-and-end-content",
+ "path": "examples/drawer-header/with-subtitle-and-end-content",
+ "aliases": []
+ },
{
"name": "example-drawer-mobile-the-56px-page-reveal-default",
"path": "examples/drawer/mobile-the-56px-page-reveal-default",
@@ -4250,6 +4260,11 @@
"path": "showcases/divider/variants",
"aliases": []
},
+ {
+ "name": "showcase-drawer-header-default",
+ "path": "showcases/drawer-header/default",
+ "aliases": []
+ },
{
"name": "showcase-drawer-basic",
"path": "showcases/drawer/basic",
diff --git a/packages/lab/blocks/DrawerHeaderShowcase.doc.mjs b/packages/lab/blocks/DrawerHeaderShowcase.doc.mjs
new file mode 100644
index 0000000000..0ead01b2e0
--- /dev/null
+++ b/packages/lab/blocks/DrawerHeaderShowcase.doc.mjs
@@ -0,0 +1,15 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
+export default {
+ type: 'block',
+ name: 'DrawerHeader',
+ displayName: 'Drawer Header',
+ description:
+ 'DrawerHeader provides a structured header for drawers with slots for title, subtitle, close button, and optional start or end content.',
+ exampleFor: 'DrawerHeader',
+ isReady: true,
+ isShowcase: true,
+ aspectRatio: 16 / 9,
+ componentsUsed: ['DrawerHeader', 'Layout', 'LayoutContent', 'Text'],
+};
diff --git a/packages/lab/blocks/DrawerHeaderShowcase.tsx b/packages/lab/blocks/DrawerHeaderShowcase.tsx
new file mode 100644
index 0000000000..2da27e2813
--- /dev/null
+++ b/packages/lab/blocks/DrawerHeaderShowcase.tsx
@@ -0,0 +1,73 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+/**
+ * @input Static header content: title, subtitle, a no-op close handler, and a divider
+ * @output The DrawerHeader row at the top of a square-cornered, drawer-width panel, visible without opening an overlay
+ * @position Lab DrawerHeader's docsite showcase. Drawer has no inline mode
+ * like Dialog's isInline, so a plain panel stands in for the drawer; in an
+ * app, compose DrawerHeader in a Layout header slot inside a Drawer.
+ */
+
+import * as stylex from '@stylexjs/stylex';
+import {DrawerHeader} from '@astryxdesign/lab';
+import {
+ Layout,
+ LayoutContent,
+ overlayPaddingReset,
+} from '@astryxdesign/core/Layout';
+import {Text} from '@astryxdesign/core/Text';
+import {
+ borderVars,
+ colorVars,
+ spacingVars,
+} from '@astryxdesign/core/theme/tokens.stylex';
+
+const styles = stylex.create({
+ // A card-like panel with square corners, matching the drawer's own corners.
+ panel: {
+ width: 360,
+ maxWidth: '100%',
+ boxSizing: 'border-box',
+ backgroundColor: colorVars['--color-background-card'],
+ borderWidth: borderVars['--border-width'],
+ borderStyle: 'solid',
+ borderColor: colorVars['--color-border'],
+ borderRadius: 0,
+ },
+ body: {
+ padding: spacingVars['--spacing-4'],
+ backgroundColor: colorVars['--color-background-muted'],
+ borderRadius: 0,
+ },
+});
+
+export default function DrawerHeaderShowcase() {
+ return (
+ // Like the Drawer root, the panel is a padding boundary, so the Layout
+ // regions inset by their own --spacing-4 default: the drawer's inset.
+ <div {...stylex.props(styles.panel, overlayPaddingReset.reset)}>
+ <Layout
+ height="auto"
+ header={
+ <DrawerHeader
+ title="Host details"
+ subtitle="web-prod-04"
+ onOpenChange={() => {}}
+ hasDivider
+ />
+ }
+ content={
+ <LayoutContent>
+ <div {...stylex.props(styles.body)}>
+ <Text type="body" color="secondary">
+ Drawer body content goes here.
+ </Text>
+ </div>
+ </LayoutContent>
+ }
+ />
+ </div>
+ );
+}
diff --git a/packages/lab/blocks/DrawerHeaderSubtitleEndContent.doc.mjs b/packages/lab/blocks/DrawerHeaderSubtitleEndContent.doc.mjs
new file mode 100644
index 0000000000..415c6d7fab
--- /dev/null
+++ b/packages/lab/blocks/DrawerHeaderSubtitleEndContent.doc.mjs
@@ -0,0 +1,22 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
+export default {
+ type: 'block',
+ name: 'With subtitle and end content',
+ displayName: 'With subtitle and end content',
+ description:
+ 'Add a subtitle under the title and put a status, such as a Badge, in endContent. The close button stays at the end of the row.',
+ exampleFor: 'DrawerHeader',
+ isReady: true,
+ aspectRatio: 16 / 9,
+ componentsUsed: [
+ 'Drawer',
+ 'DrawerHeader',
+ 'Badge',
+ 'Button',
+ 'Layout',
+ 'LayoutContent',
+ 'Text',
+ ],
+};
diff --git a/packages/lab/blocks/DrawerHeaderSubtitleEndContent.tsx b/packages/lab/blocks/DrawerHeaderSubtitleEndContent.tsx
new file mode 100644
index 0000000000..e81ca6077f
--- /dev/null
+++ b/packages/lab/blocks/DrawerHeaderSubtitleEndContent.tsx
@@ -0,0 +1,49 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+/**
+ * @input Controlled open state for a modal Drawer
+ * @output A DrawerHeader with a subtitle, a status badge in its end slot, and a close button
+ * @position Copyable Lab DrawerHeader example
+ */
+
+import {useState} from 'react';
+import {Drawer, DrawerHeader} from '@astryxdesign/lab';
+import {Badge} from '@astryxdesign/core/Badge';
+import {Button} from '@astryxdesign/core/Button';
+import {Layout, LayoutContent} from '@astryxdesign/core/Layout';
+import {Text} from '@astryxdesign/core/Text';
+
+export default function DrawerHeaderSubtitleEndContent() {
+ const [isOpen, setIsOpen] = useState(false);
+
+ return (
+ <>
+ <Button label="Open host details" onClick={() => setIsOpen(true)} />
+ <Drawer
+ isOpen={isOpen}
+ onOpenChange={setIsOpen}
+ label="web-prod-04"
+ width={360}>
+ <Layout
+ header={
+ <DrawerHeader
+ title="web-prod-04"
+ subtitle="us-east-1"
+ endContent={<Badge label="Healthy" variant="success" />}
+ onOpenChange={setIsOpen}
+ />
+ }
+ content={
+ <LayoutContent>
+ <Text type="body">
+ All 6 instances are passing readiness checks.
+ </Text>
+ </LayoutContent>
+ }
+ />
+ </Drawer>
+ </>
+ );
+}
diff --git a/packages/lab/blocks/DrawerHeaderWithCloseButton.doc.mjs b/packages/lab/blocks/DrawerHeaderWithCloseButton.doc.mjs
new file mode 100644
index 0000000000..25518ff074
--- /dev/null
+++ b/packages/lab/blocks/DrawerHeaderWithCloseButton.doc.mjs
@@ -0,0 +1,21 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/** @type {import('@astryxdesign/cli/authoring').TemplateDoc} */
+export default {
+ type: 'block',
+ name: 'With close button',
+ displayName: 'With close button',
+ description:
+ 'Pass onOpenChange to render a close button that calls it with false. Drawer renders no close button of its own, so this is the usual visible way to close.',
+ exampleFor: 'DrawerHeader',
+ isReady: true,
+ aspectRatio: 16 / 9,
+ componentsUsed: [
+ 'Drawer',
+ 'DrawerHeader',
+ 'Button',
+ 'Layout',
+ 'LayoutContent',
+ 'Text',
+ ],
+};
diff --git a/packages/lab/blocks/DrawerHeaderWithCloseButton.tsx b/packages/lab/blocks/DrawerHeaderWithCloseButton.tsx
new file mode 100644
index 0000000000..327fadd77a
--- /dev/null
+++ b/packages/lab/blocks/DrawerHeaderWithCloseButton.tsx
@@ -0,0 +1,42 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+'use client';
+
+/**
+ * @input Controlled open state for a modal Drawer
+ * @output A Drawer whose DrawerHeader renders a close button because it receives onOpenChange
+ * @position Copyable Lab DrawerHeader example
+ */
+
+import {useState} from 'react';
+import {Drawer, DrawerHeader} from '@astryxdesign/lab';
+import {Button} from '@astryxdesign/core/Button';
+import {Layout, LayoutContent} from '@astryxdesign/core/Layout';
+import {Text} from '@astryxdesign/core/Text';
+
+export default function DrawerHeaderWithCloseButton() {
+ const [isOpen, setIsOpen] = useState(false);
+
+ return (
+ <>
+ <Button label="Open drawer" onClick={() => setIsOpen(true)} />
+ <Drawer
+ isOpen={isOpen}
+ onOpenChange={setIsOpen}
+ label="Details"
+ width={360}>
+ <Layout
+ header={<DrawerHeader title="Details" onOpenChange={setIsOpen} />}
+ content={
+ <LayoutContent>
+ <Text type="body">
+ Passing onOpenChange renders the close button, which calls it
+ with false.
+ </Text>
+ </LayoutContent>
+ }
+ />
+ </Drawer>
+ </>
+ );
+}