Skip to content

Commit

Permalink
Add example and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wrose504 committed May 23, 2024
1 parent 0d5263d commit 6ac5468
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/react-rsbuild/src/loaders/react-docgen-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const actualNameHandler: Handler = function actualNameHandler(
documentation,
componentDefinition,
) {
documentation.set('definedInFile', componentDefinition.hub.file.opts.filename)
if (
(componentDefinition.isClassDeclaration() ||
componentDefinition.isFunctionDeclaration()) &&
Expand Down Expand Up @@ -71,7 +72,7 @@ const actualNameHandler: Handler = function actualNameHandler(
}
}

type DocObj = Documentation & { actualName: string }
type DocObj = Documentation & { actualName: string; definedInFile: string }

const defaultHandlers = Object.values(docgenHandlers).map((handler) => handler)
const defaultResolver = new docgenResolver.FindExportedDefinitionsResolver()
Expand Down Expand Up @@ -141,8 +142,8 @@ export default async function reactDocgenLoader(
const magicString = new MagicString(source)

docgenResults.forEach((info) => {
const { actualName, ...docgenInfo } = info
if (actualName) {
const { actualName, definedInFile, ...docgenInfo } = info
if (actualName && definedInFile === this.resourcePath) {
const docNode = JSON.stringify(docgenInfo)
magicString.append(`;${actualName}.__docgenInfo=${docNode}`)
}
Expand Down
32 changes: 32 additions & 0 deletions sandboxes/react-rsbuild/src/stories/Bouton.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Meta, StoryObj } from '@storybook/react'
import { fn } from '@storybook/test'
import Bouton from './Bouton'

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
const meta = {
title: 'Example/Bouton',
component: Bouton,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
layout: 'centered',
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
// More on argTypes: https://storybook.js.org/docs/api/argtypes
argTypes: {
backgroundColor: { control: 'color' },
},
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
args: { onClick: fn() },
} satisfies Meta<typeof Bouton>

export default meta
type Story = StoryObj<typeof meta>

// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
export const Primary: Story = {
args: {
primary: true,
label: 'Button',
},
}
2 changes: 2 additions & 0 deletions sandboxes/react-rsbuild/src/stories/Bouton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { Button as Bouton } from './Button'
export default Bouton

0 comments on commit 6ac5468

Please sign in to comment.