-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
React: Experimental code examples #32813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
d903424
fa08b04
e474ea9
c165fc5
ddff493
308889e
7b5dadc
7d970f5
d53734f
13a2dbe
46d43a6
fdcb204
7d3aa5d
a496f56
8422167
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| // should be node:http, but that caused the ui/manager to fail to build, might be able to switch this back once ui/manager is in the core | ||
| import type { FileSystemCache } from 'storybook/internal/common'; | ||
| import { type StoryIndexGenerator } from 'storybook/internal/core-server'; | ||
| import { type CsfFile } from 'storybook/internal/csf-tools'; | ||
|
|
||
| import type { Server as HttpServer, IncomingMessage, ServerResponse } from 'http'; | ||
| import type { Server as NetServer } from 'net'; | ||
|
|
@@ -106,6 +107,9 @@ export interface Presets { | |
| config?: StorybookConfigRaw['staticDirs'], | ||
| args?: any | ||
| ): Promise<StorybookConfigRaw['staticDirs']>; | ||
|
|
||
| /** The second and third parameter are not needed. And make type inference easier. */ | ||
| apply<T extends keyof StorybookConfigRaw>(extension: T): Promise<StorybookConfigRaw[T]>; | ||
| apply<T>(extension: string, config?: T, args?: unknown): Promise<T>; | ||
| } | ||
|
|
||
|
|
@@ -359,6 +363,8 @@ export type ComponentManifestGenerator = ( | |
| storyIndexGenerator: StoryIndexGenerator | ||
| ) => Promise<ComponentsManifest>; | ||
|
|
||
| export type CsfEnricher = (csf: CsfFile, csfSource: CsfFile) => Promise<void>; | ||
|
|
||
| export interface StorybookConfigRaw { | ||
| /** | ||
| * Sets the addons you want to use with Storybook. | ||
|
|
@@ -373,6 +379,7 @@ export interface StorybookConfigRaw { | |
| addons?: Preset[]; | ||
| core?: CoreConfig; | ||
| componentManifestGenerator?: ComponentManifestGenerator; | ||
| experimental_enrichCsf?: CsfEnricher; | ||
| staticDirs?: (DirectoryMapping | string)[]; | ||
| logLevel?: string; | ||
| features?: { | ||
|
|
@@ -472,6 +479,19 @@ export interface StorybookConfigRaw { | |
| angularFilterNonInputControls?: boolean; | ||
|
|
||
| experimentalComponentsManifest?: boolean; | ||
|
|
||
| /** | ||
| * Enables the new code example generation for React components. You can see those examples when | ||
| * clicking on the "Show code" button in the Storybook UI. | ||
| * | ||
| * We refactored the code examples by reading the actual source file. This should make the code | ||
| * examples a lot faster, more readable and more accurate. They are not dynamic though, it won't | ||
| * change if you change when using the control panel. | ||
| * | ||
| * @default false | ||
| * @experimental This feature is in early development and may change significantly in future releases. | ||
| */ | ||
| experimentalCodeExamples?: boolean; | ||
|
Comment on lines
+484
to
+495
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Fix grammatical error in JSDoc and consider addressing past review feedback. The JSDoc has a grammatical issue in the sentence "it won't change if you change when using the control panel." Apply this diff to fix the grammar: * We refactored the code examples by reading the actual source file. This should make the code
* examples a lot faster, more readable and more accurate. They are not dynamic though, it won't
- * change if you change when using the control panel.
+ * change when you modify controls in the control panel.Additionally, the past review comment mentions "better support for render functions." If this is a key improvement, consider adding it explicitly to the JSDoc: * Enables the new code example generation for React components. You can see those examples when
* clicking on the "Show code" button in the Storybook UI.
*
* We refactored the code examples by reading the actual source file. This should make the code
- * examples a lot faster, more readable and more accurate. They are not dynamic though, it won't
- * change when you modify controls in the control panel.
+ * examples a lot faster, more readable and more accurate, with improved support for render
+ * functions. They are not dynamic though, meaning they won't change when you modify controls
+ * in the control panel.🤖 Prompt for AI Agents |
||
| }; | ||
|
|
||
| build?: TestBuildConfig; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,24 +2,21 @@ import { parse } from 'comment-parser'; | |
|
|
||
| import { groupBy } from './utils'; | ||
|
|
||
| export function extractJSDocTags(jsdocComment: string) { | ||
| export function extractJSDocInfo(jsdocComment: string) { | ||
| const lines = jsdocComment.split('\n'); | ||
| const jsDoc = ['/**', ...lines.map((line) => ` * ${line}`), ' */'].join('\n'); | ||
|
|
||
| const parsed = parse(jsDoc); | ||
|
|
||
| return Object.fromEntries( | ||
| Object.entries(groupBy(parsed[0].tags, (it) => it.tag)).map(([key, tags]) => [ | ||
| key, | ||
| tags?.map((tag) => (tag.type ? `{${tag.type}} ` : '') + `${tag.name} ${tag.description}`) ?? | ||
| [], | ||
| ]) | ||
| ); | ||
| return { | ||
| description: parsed[0].description, | ||
| tags: Object.fromEntries( | ||
| Object.entries(groupBy(parsed[0].tags, (it) => it.tag)).map(([key, tags]) => [ | ||
| key, | ||
| tags?.map((tag) => (tag.type ? `{${tag.type}} ` : '') + `${tag.name} ${tag.description}`) ?? | ||
| [], | ||
| ]) | ||
| ), | ||
|
Comment on lines
+13
to
+19
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against undefined tag properties. The string concatenation on line 16 may produce Apply this diff to safely handle undefined values: Object.entries(groupBy(parsed[0].tags, (it) => it.tag)).map(([key, tags]) => [
key,
- tags?.map((tag) => (tag.type ? `{${tag.type}} ` : '') + `${tag.name} ${tag.description}`) ??
+ tags?.map((tag) => {
+ const typePrefix = tag.type ? `{${tag.type}} ` : '';
+ const name = tag.name || '';
+ const description = tag.description || '';
+ return `${typePrefix}${name} ${description}`.trim();
+ }) ??
[],
])🤖 Prompt for AI Agents |
||
| }; | ||
| } | ||
|
|
||
| export function removeTags(jsdocComment: string) { | ||
| return jsdocComment | ||
| .split('\n') | ||
| .filter((line) => !line.trim().startsWith('@')) | ||
| .join('\n'); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.