Skip to content

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

TypeScript

fix(core): add playground wrapper and defaults for LayoutPanel docsite preview (#5919)

Geervan8449e3823fb4
diff --git a/.changeset/layout-panel-playground-wrapper.md b/.changeset/layout-panel-playground-wrapper.md
new file mode 100644
index 0000000000..55eb78f074
--- /dev/null
+++ b/.changeset/layout-panel-playground-wrapper.md
@@ -0,0 +1,10 @@
+---
+'@astryxdesign/core': patch
+'@astryxdesign/cli': patch
+---
+
+[fix] LayoutPanel: add playground wrapper and default children for docsite preview
+
+Prevents the properties-tab preview on the docsite from rendering an empty stage by wrapping LayoutPanel inside a Layout scaffold with representative panel content in start slot.
+
+@Geervan
diff --git a/apps/docsite/scripts/generate-data.mjs b/apps/docsite/scripts/generate-data.mjs
index 072ad19df3..4dcf68e2ab 100644
--- a/apps/docsite/scripts/generate-data.mjs
+++ b/apps/docsite/scripts/generate-data.mjs
@@ -701,6 +701,11 @@ async function generateComponentRegistry() {
const content = `// Auto-generated by scripts/generate-data.mjs — do not edit
+import type {
+ ComponentPlaygroundConfig,
+ ComponentSlotElement,
+} from '@astryxdesign/cli/authoring';
+
export interface PropDoc {
name: string;
type: string;
@@ -893,25 +898,8 @@ export interface ComponentEntry {
playground: PlaygroundConfig | null;
}
-export interface ElementDescriptor {
- __element: string;
- props?: Record<string, unknown>;
- children?: string | ElementDescriptor | (string | ElementDescriptor)[];
-}
-
-export interface PlaygroundConfig {
- defaults?: Record<string, unknown>;
- overlay?: boolean;
- overlayControl?: {
- stateProp: string;
- openValue: unknown;
- };
- appShellMobile?: boolean;
- wrapper?: {
- component: string;
- props?: Record<string, unknown>;
- };
-}
+export type ElementDescriptor = ComponentSlotElement;
+export type PlaygroundConfig = ComponentPlaygroundConfig;
export const components: Record<string, ComponentEntry[]> = ${JSON.stringify(allComponents, null, 2)};
diff --git a/apps/docsite/src/__tests__/data-extraction.test.ts b/apps/docsite/src/__tests__/data-extraction.test.ts
index 5f87881fe8..5cbb924e4b 100644
--- a/apps/docsite/src/__tests__/data-extraction.test.ts
+++ b/apps/docsite/src/__tests__/data-extraction.test.ts
@@ -30,6 +30,14 @@ const REPO_ROOT = path.resolve(
'../../../..',
);
const CORE_SRC_DIR = path.join(REPO_ROOT, 'packages/core/src');
+const COMPONENT_REGISTRY_PATH = new URL(
+ '../generated/componentRegistry.ts',
+ import.meta.url,
+);
+const COMPONENT_REGISTRY_SOURCE = fs.readFileSync(
+ COMPONENT_REGISTRY_PATH,
+ 'utf-8',
+);
function findFiles(dir: string, predicate: (filePath: string) => boolean) {
const files: string[] = [];
@@ -173,6 +181,19 @@ describe('packageRegistry', () => {
// ── Component Registry ─────────────────────────────────────────────────
describe('componentRegistry', () => {
+ it('derives playground types from the CLI authoring contract', () => {
+ const playground: NonNullable<ComponentEntry['playground']> = {
+ wrapper: {component: 'Layout', slotProp: 'start'},
+ };
+ expect(COMPONENT_REGISTRY_SOURCE).toContain(
+ "from '@astryxdesign/cli/authoring'",
+ );
+ expect(COMPONENT_REGISTRY_SOURCE).toContain(
+ 'export type PlaygroundConfig = ComponentPlaygroundConfig;',
+ );
+ expect(playground.wrapper?.slotProp).toBe('start');
+ });
+
it('discovers components in @astryxdesign/core', () => {
expect(components['@astryxdesign/core']).toBeDefined();
expect(components['@astryxdesign/core'].length).toBeGreaterThan(100);
@@ -430,6 +451,20 @@ describe('componentRegistry', () => {
});
});
+ it('LayoutPanel declares a playground wrapper in start slot so hasDivider preview is not 0px (#5897)', () => {
+ const core = components['@astryxdesign/core'];
+ const layoutPanel = core.find(c => c.name === 'LayoutPanel');
+ expect(layoutPanel).toBeDefined();
+ expect(layoutPanel!.playground?.defaults).toMatchObject({
+ children: expect.any(String),
+ hasDivider: true,
+ });
+ expect(layoutPanel!.playground?.wrapper).toMatchObject({
+ component: 'Layout',
+ slotProp: 'start',
+ });
+ });
+
it('Lightbox declares an overlay playground with a closed initial state (#3657)', () => {
const core = components['@astryxdesign/core'];
const lightbox = core.find(c => c.name === 'Lightbox');
diff --git a/packages/cli/authoring/doctypes/base/type.ts b/packages/cli/authoring/doctypes/base/type.ts
index a2ab8d221d..edba89792c 100644
--- a/packages/cli/authoring/doctypes/base/type.ts
+++ b/packages/cli/authoring/doctypes/base/type.ts
@@ -256,8 +256,10 @@ export interface ComponentPlaygroundConfig {
wrapper?: {
/** Parent component name as exported from `@astryxdesign/core`, e.g. `'TabList'`. */
component: string;
- /** Props for the wrapper. The previewed sub-component becomes its `children`. */
+ /** Props for the wrapper. The previewed sub-component becomes its `children` unless slotProp is set. */
props?: Record<string, unknown>;
+ /** Wrapper prop that receives the previewed sub-component instead of `children`. */
+ slotProp?: string;
};
}
diff --git a/packages/core/src/Layout/LayoutPanel.doc.mjs b/packages/core/src/Layout/LayoutPanel.doc.mjs
index ea3a290567..6047f49b97 100644
--- a/packages/core/src/Layout/LayoutPanel.doc.mjs
+++ b/packages/core/src/Layout/LayoutPanel.doc.mjs
@@ -8,6 +8,24 @@ export const docs = {
displayName: 'Layout Panel',
isHiddenFromOverview: true,
description: 'Sidebar for navigation, settings, or inspector panels.',
+ playground: {
+ defaults: {
+ children: 'Panel Content',
+ hasDivider: true,
+ width: 200,
+ },
+ wrapper: {
+ component: 'Layout',
+ slotProp: 'start',
+ props: {
+ content: {
+ __element: 'LayoutContent',
+ props: {},
+ children: 'Main content area',
+ },
+ },
+ },
+ },
props: [
{
name: 'children',