Skip to content

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

TypeScript

fix(docsite): show an open trigger for closed overlay previews (#2706) (#3616)

Jiun Shin52998dbe2e12
diff --git a/.changeset/mobilenav-previews-with-an-open-trigger-instead--wbqg.md b/.changeset/mobilenav-previews-with-an-open-trigger-instead--wbqg.md
new file mode 100644
index 0000000000..deaf99c628
--- /dev/null
+++ b/.changeset/mobilenav-previews-with-an-open-trigger-instead--wbqg.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[docs] MobileNav previews with an open trigger instead of an empty stage: new playground.overlay for full-viewport overlay components, and inline sub-components can declare their own playground (#3616)
+@jiunshinn
diff --git a/apps/docsite/scripts/generate-data.mjs b/apps/docsite/scripts/generate-data.mjs
index 056529950e..bb1b679ae7 100644
--- a/apps/docsite/scripts/generate-data.mjs
+++ b/apps/docsite/scripts/generate-data.mjs
@@ -574,7 +574,15 @@ async function generateComponentRegistry() {
? sub.relatedComponents || (doc.name ? [doc.name] : null)
: null,
relatedHooks: isHookEntry ? sub.relatedHooks || null : null,
- playground: isHookEntry ? null : playground,
+ // Sub-components may declare their own playground (e.g. an
+ // overlay drawer whose sibling toggle must not inherit it);
+ // fall back to the parent doc's playground otherwise — same
+ // override rule as extracted subComponentOf docs.
+ playground: isHookEntry
+ ? null
+ : sub.playground
+ ? sanitizeForJson(sub.playground)
+ : playground,
});
}
} else if (doc.params) {
@@ -767,6 +775,7 @@ export interface ElementDescriptor {
export interface PlaygroundConfig {
defaults?: Record<string, unknown>;
+ overlay?: boolean;
wrapper?: {
component: string;
props?: Record<string, unknown>;
diff --git a/apps/docsite/src/__tests__/component-preview-state.test.ts b/apps/docsite/src/__tests__/component-preview-state.test.ts
index 98aa55ff7f..dedb2494f4 100644
--- a/apps/docsite/src/__tests__/component-preview-state.test.ts
+++ b/apps/docsite/src/__tests__/component-preview-state.test.ts
@@ -5,6 +5,7 @@ import {
buildInitialState,
buildRuntimePreviewState,
getMissingRequiredProps,
+ isOverlayPreviewClosed,
pickPrimaryProps,
} from '../components/component-detail/interactiveState';
import type {PropDoc} from '../generated/componentRegistry';
@@ -325,4 +326,38 @@ describe('component detail preview state', () => {
(withOptIn.onOpenChange as (isOpen: boolean) => void)(false);
expect(onPropChange).toHaveBeenCalledWith('isOpen', false);
});
+
+ it('keeps an explicit isOpen: false playground default in preview state', () => {
+ const knobs = pickPrimaryProps('MobileNav', [
+ prop({name: 'isOpen', type: 'boolean'}),
+ prop({name: 'onOpenChange', type: '(isOpen: boolean) => void'}),
+ prop({name: 'children', type: 'ReactNode', required: true}),
+ ]);
+
+ const state = buildInitialState(knobs, {
+ overlay: true,
+ defaults: {isOpen: false, children: 'nav items'},
+ });
+
+ // isOpen must be present (not undefined) so buildRuntimePreviewState can
+ // bridge onOpenChange back into playground state for the open trigger.
+ expect(state.isOpen).toBe(false);
+
+ const onPropChange = vi.fn();
+ const runtimeState = buildRuntimePreviewState(state, onPropChange, {
+ knobs,
+ canControlOpenState: true,
+ });
+ (runtimeState.onOpenChange as (isOpen: boolean) => void)(true);
+ expect(onPropChange).toHaveBeenCalledWith('isOpen', true);
+ });
+
+ it('flags closed overlay previews only for overlay-mode playgrounds', () => {
+ expect(isOverlayPreviewClosed({overlay: true}, {isOpen: false})).toBe(true);
+ expect(isOverlayPreviewClosed({overlay: true}, {})).toBe(true);
+ expect(isOverlayPreviewClosed({overlay: true}, {isOpen: true})).toBe(false);
+ expect(isOverlayPreviewClosed({}, {isOpen: false})).toBe(false);
+ expect(isOverlayPreviewClosed(null, {isOpen: false})).toBe(false);
+ expect(isOverlayPreviewClosed(undefined, {})).toBe(false);
+ });
});
diff --git a/apps/docsite/src/components/component-detail/InteractivePreview.tsx b/apps/docsite/src/components/component-detail/InteractivePreview.tsx
index 0d2634cbd5..f3649f9e3a 100644
--- a/apps/docsite/src/components/component-detail/InteractivePreview.tsx
+++ b/apps/docsite/src/components/component-detail/InteractivePreview.tsx
@@ -25,6 +25,7 @@ import {
buildInitialState,
buildRuntimePreviewState,
getMissingRequiredProps,
+ isOverlayPreviewClosed,
pickPrimaryProps,
type KnobProp,
} from './interactiveState';
@@ -354,6 +355,29 @@ export function InteractivePreviewStage({
<PreviewErrorBoundary
resetKeys={[Component, runtimeState, WrapperComponent]}>
{renderPreview(createElement(Component, runtimeState))}
+ {isOverlayPreviewClosed(playground, state) && (
+ <VStack
+ gap={2}
+ style={{
+ alignItems: 'center',
+ paddingBlock: 24,
+ paddingInline: 16,
+ textAlign: 'center',
+ }}>
+ <Text type="supporting" color="secondary">
+ Opens as a full-screen overlay — nothing renders while it is
+ closed.
+ </Text>
+ {onPropChange != null && canControlOpenState && (
+ <Button
+ label="Open preview"
+ variant="secondary"
+ size="sm"
+ onClick={() => onPropChange('isOpen', true)}
+ />
+ )}
+ </VStack>
+ )}
</PreviewErrorBoundary>
</Center>
)}
diff --git a/apps/docsite/src/components/component-detail/interactiveState.ts b/apps/docsite/src/components/component-detail/interactiveState.ts
index cd76ee497a..0053bcf585 100644
--- a/apps/docsite/src/components/component-detail/interactiveState.ts
+++ b/apps/docsite/src/components/component-detail/interactiveState.ts
@@ -198,6 +198,19 @@ export function buildInitialState(
return state;
}
+/**
+ * True when an overlay-mode component (`playground.overlay`) is closed in the
+ * current preview state. The component renders nothing inline while closed
+ * (e.g. a `showModal()` drawer), so the stage shows an open-trigger
+ * placeholder instead of an empty box.
+ */
+export function isOverlayPreviewClosed(
+ playground: PlaygroundConfig | null | undefined,
+ state: Record<string, unknown>,
+): boolean {
+ return playground?.overlay === true && state.isOpen !== true;
+}
+
export function getMissingRequiredProps(
knobs: KnobProp[],
state: Record<string, unknown>,
diff --git a/packages/core/src/MobileNav/MobileNav.doc.mjs b/packages/core/src/MobileNav/MobileNav.doc.mjs
index 127f924a3d..6cf42da16b 100644
--- a/packages/core/src/MobileNav/MobileNav.doc.mjs
+++ b/packages/core/src/MobileNav/MobileNav.doc.mjs
@@ -14,6 +14,26 @@ export const docs = {
name: 'MobileNav',
displayName: 'Mobile Nav',
description: 'A slide-out drawer for mobile navigation. Accepts SideNav children.',
+ // The drawer opens via showModal() and renders nothing while closed —
+ // overlay mode gives the Properties preview an open trigger instead of
+ // an empty stage (#2706). Declared on this entry (not the directory
+ // doc) so MobileNavToggle does not inherit it.
+ playground: {
+ overlay: true,
+ defaults: {
+ isOpen: false,
+ header: 'Navigation',
+ children: {
+ __element: 'SideNavSection',
+ props: {title: 'Main'},
+ children: [
+ {__element: 'SideNavItem', props: {label: 'Dashboard', isSelected: true}},
+ {__element: 'SideNavItem', props: {label: 'Projects'}},
+ {__element: 'SideNavItem', props: {label: 'Settings'}},
+ ],
+ },
+ },
+ },
props: [
{
name: 'isOpen',
diff --git a/packages/core/src/docs-types.ts b/packages/core/src/docs-types.ts
index 5e37337a10..c397f4fbc1 100644
--- a/packages/core/src/docs-types.ts
+++ b/packages/core/src/docs-types.ts
@@ -217,6 +217,11 @@ export interface ComponentEntry {
examples?: ExampleDoc[];
/** When true, this sub-component is excluded from the overview page. */
isHiddenFromOverview?: boolean;
+ /** Playground configuration for this specific component. Falls back to
+ * the directory doc's `playground` when omitted — declare one here when
+ * siblings must not share it (e.g. an overlay drawer whose toggle
+ * sub-component should not inherit `overlay: true`). */
+ playground?: PlaygroundConfig;
}
/**
@@ -390,6 +395,13 @@ export interface PlaygroundConfig {
/** Initial prop values for the playground preview.
* Keys are prop names. Values are primitives or ElementDescriptors. */
defaults?: Record<string, unknown>;
+ /** The component opens as a full-viewport overlay (e.g. via
+ * `dialog.showModal()`) and renders nothing inline while closed. The
+ * interactive preview shows an open-trigger placeholder instead of an
+ * empty stage while `isOpen` is false, and lets the real overlay render
+ * when opened. Include `isOpen: false` in `defaults` so the preview can
+ * bridge `onOpenChange` back into playground state. */
+ overlay?: boolean;
/** Required parent wrapper for sub-components that depend on a parent
* context provider (e.g. `Tab` calls `useTabListContext()` and throws
* standalone). The preview wraps the component in this parent before