Skip to content

Commit 9939968

Browse files
authored
Merge pull request storybookjs#35109 from storybookjs/split/docgen-ui-consumption
Docs: Route ArgTypes and Controls through docgen service when flag enabled
2 parents 35ea567 + 3e9e4d6 commit 9939968

35 files changed

Lines changed: 1065 additions & 199 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ Do **not** use `/tmp` paths or replace `node:fs/promises` with a full async fact
258258

259259
After changing files:
260260

261-
1. Format with `yarn fmt:write` (run from the repo root)
261+
1. **Always** format with `yarn fmt:write`, run from the `code/` directory (`cd code && yarn fmt:write`), once you are done editing. The repo uses `oxfmt`, so hand-written formatting will frequently be wrong — do not skip this step.
262262
2. Lint with `yarn --cwd code lint:js:cmd <file-relative-to-code-folder> --fix` or `cd code && yarn lint:js:cmd <file-relative-to-code-folder>`
263263
3. Run relevant tests before submitting a PR
264264

code/.storybook/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ const config = defineMain({
156156
features: {
157157
developmentModeForBuild: true,
158158
experimentalTestSyntax: true,
159-
experimentalDocgenServer: true,
159+
// Disabled for now: the docgen service does not yet work in production builds. Keeping it off
160+
// ensures this branch exercises the normal (non-experimental) docgen path without regressions.
161+
experimentalDocgenServer: false,
160162
experimentalReactComponentMeta: true,
161163
changeDetection: true,
162164
},
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { Meta } from '@storybook/addon-docs/blocks';
2+
3+
import * as ArgTypesStories from './ArgTypes.stories.tsx';
4+
import * as ExampleStories from '../examples/ArgTypesParameters.stories';
5+
import * as SubcomponentsExampleStories from '../examples/ArgTypesWithSubcomponentsParameters.stories';
6+
7+
import { ArgTypes } from './ArgTypes';
8+
9+
<Meta of={ArgTypesStories} />
10+
11+
# ArgTypes block (MDX)
12+
13+
Each section below uses the `ArgTypes` block the same way as the matching story in `ArgTypes.stories.tsx`.
14+
15+
## OfComponent
16+
17+
<ArgTypes of={ExampleStories.default.component} />
18+
19+
## OfMeta
20+
21+
<ArgTypes of={ExampleStories.default} />
22+
23+
## OfStory
24+
25+
<ArgTypes of={ExampleStories.NoParameters} />
26+
27+
## IncludeProp
28+
29+
<ArgTypes of={ExampleStories.NoParameters} include={['a']} />
30+
31+
## IncludeParameter
32+
33+
<ArgTypes of={ExampleStories.Include} />
34+
35+
## ExcludeProp
36+
37+
<ArgTypes of={ExampleStories.NoParameters} exclude={['a']} />
38+
39+
## ExcludeParameter
40+
41+
<ArgTypes of={ExampleStories.Exclude} />
42+
43+
## SortProp
44+
45+
<ArgTypes of={ExampleStories.NoParameters} sort="alpha" />
46+
47+
## SortParameter
48+
49+
<ArgTypes of={ExampleStories.Sort} />
50+
51+
## Categories
52+
53+
<ArgTypes of={ExampleStories.Categories} />
54+
55+
## SubcomponentsOfMeta
56+
57+
<ArgTypes of={SubcomponentsExampleStories.default} />
58+
59+
## SubcomponentsOfStory
60+
61+
<ArgTypes of={SubcomponentsExampleStories.NoParameters} />
62+
63+
## SubcomponentsIncludeProp
64+
65+
<ArgTypes of={SubcomponentsExampleStories.NoParameters} include={['a', 'f']} />
66+
67+
## SubcomponentsExcludeProp
68+
69+
<ArgTypes of={SubcomponentsExampleStories.NoParameters} exclude={['a', 'c', 'f', 'g']} />
70+
71+
## SubcomponentsSortProp
72+
73+
<ArgTypes of={SubcomponentsExampleStories.NoParameters} sort="alpha" />

code/addons/docs/src/blocks/blocks/ArgTypes.stories.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
import React from 'react';
2-
1+
/** Custom docs page: {@link ./ArgTypes.mdx} (attached via `<Meta of={...} />`). */
32
import type { PlayFunctionContext } from 'storybook/internal/csf';
43

54
import type { Meta, StoryObj } from '@storybook/react-vite';
65

7-
import { within } from 'storybook/test';
8-
96
import * as ExampleStories from '../examples/ArgTypesParameters.stories';
107
import * as SubcomponentsExampleStories from '../examples/ArgTypesWithSubcomponentsParameters.stories';
118
import { ArgTypes } from './ArgTypes';
129

13-
const meta: Meta<typeof ArgTypes> = {
10+
const meta = {
1411
title: 'Blocks/ArgTypes',
1512
component: ArgTypes,
1613
parameters: {
@@ -21,7 +18,8 @@ const meta: Meta<typeof ArgTypes> = {
2118
],
2219
docsStyles: true,
2320
},
24-
};
21+
} satisfies Meta<typeof ArgTypes>;
22+
2523
export default meta;
2624

2725
type Story = StoryObj<typeof meta>;
@@ -108,7 +106,7 @@ export const Categories: Story = {
108106
};
109107

110108
const findSubcomponentTabs = async (
111-
canvas: ReturnType<typeof within>,
109+
canvas: Parameters<NonNullable<Story['play']>>[0]['canvas'],
112110
step: PlayFunctionContext['step']
113111
) => {
114112
let subcomponentATab: HTMLElement | null = null;
@@ -124,26 +122,26 @@ export const SubcomponentsOfMeta: Story = {
124122
args: {
125123
of: SubcomponentsExampleStories.default,
126124
},
127-
play: async ({ canvasElement, step }) => {
128-
const canvas = within(canvasElement);
125+
play: async ({ canvas, step }) => {
129126
await findSubcomponentTabs(canvas, step);
130127
},
131128
};
132129

133130
export const SubcomponentsOfStory: Story = {
134-
...SubcomponentsOfMeta,
135131
args: {
136132
of: SubcomponentsExampleStories.NoParameters,
137133
},
134+
play: async ({ canvas, step }) => {
135+
await findSubcomponentTabs(canvas, step);
136+
},
138137
};
139138

140139
export const SubcomponentsIncludeProp: Story = {
141140
args: {
142141
of: SubcomponentsExampleStories.NoParameters,
143142
include: ['a', 'f'],
144143
},
145-
play: async ({ canvasElement, step }) => {
146-
const canvas = within(canvasElement);
144+
play: async ({ canvas, step }) => {
147145
const { subcomponentBTab } = await findSubcomponentTabs(canvas, step);
148146
if (subcomponentBTab) {
149147
await (subcomponentBTab as HTMLElement & { click: () => Promise<void> }).click();

0 commit comments

Comments
 (0)