Skip to content

Commit 01462bf

Browse files
authored
fix: storyName for csf2 stories (#784)
1 parent 4902839 commit 01462bf

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { Meta, StoryObj } from '@storybook/react-native';
2+
import { Text } from 'react-native';
3+
4+
const StoryName = ({ name }: { name: string }) => <Text>{name}</Text>;
5+
6+
const meta = {
7+
component: StoryName,
8+
} satisfies Meta<typeof StoryName>;
9+
10+
export default meta;
11+
12+
type Story = StoryObj<typeof meta>;
13+
14+
export const WithStoryName: Story = {
15+
storyName: 'story name here',
16+
args: {
17+
name: 'story name here',
18+
},
19+
};
20+
21+
export const WithName: Story = {
22+
storyName: 'name here',
23+
args: {
24+
name: 'name here',
25+
},
26+
};
27+
28+
export const WithNoName: Story = {
29+
args: {
30+
name: 'no name here',
31+
},
32+
};
33+
34+
export const CSF2Example = (args: { name: string }) => <StoryName {...args} />;
35+
CSF2Example.args = { name: 'csf2 with no name' };
36+
37+
export const CSF2ExampleWithName = (args: { name: string }) => <StoryName {...args} />;
38+
CSF2ExampleWithName.storyName = 'csf2 with name';
39+
CSF2ExampleWithName.args = { name: 'csf2 with name' };

packages/react-native/src/Start.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,13 @@ export function prepareStories({
125125
const nameFromExport = storyNameFromExport(key);
126126
const id = toId(title, nameFromExport);
127127

128-
const name = exportValue?.name || exportValue?.storyName || nameFromExport;
128+
let name = nameFromExport;
129+
130+
if (typeof exportValue === 'function') {
131+
name = exportValue?.storyName || nameFromExport;
132+
} else {
133+
name = exportValue?.name || exportValue?.storyName || nameFromExport;
134+
}
129135

130136
index.entries[id] = {
131137
type: 'story',

0 commit comments

Comments
 (0)