Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

Commit cb0c7b2

Browse files
authored
Merge pull request #35 from storybookjs/chore/add-csf3-example
chore: add example stories using CSF 3 [skip ci]
2 parents faf0045 + fb71673 commit cb0c7b2

File tree

7 files changed

+2848
-894
lines changed

7 files changed

+2848
-894
lines changed

example/.storybook/main.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/.storybook/main.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { StorybookConfig } from '@storybook/react/types';
2+
3+
const config: StorybookConfig = {
4+
stories: ['../src/**/*.stories.tsx'],
5+
logLevel: 'debug',
6+
addons: ['@storybook/preset-create-react-app', '@storybook/addon-essentials'],
7+
features: {
8+
previewCsfV3: true,
9+
},
10+
};
11+
12+
module.exports = config;

example/.storybook/preview.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { Story } from '@storybook/react';
2+
import type { Story } from '@storybook/react';
3+
import { ThemeProvider, convert, themes } from '@storybook/theming';
34

45
export const parameters = {
56
actions: { argTypesRegex: '^on[A-Z].*' }
@@ -12,6 +13,11 @@ export const decorators = [
1213
<StoryFn />
1314
</>
1415
),
16+
(StoryFn: Story) => (
17+
<ThemeProvider theme={convert(themes.light)}>
18+
<StoryFn />
19+
</ThemeProvider>
20+
),
1521
];
1622

1723
export const globalTypes = {

example/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,20 @@
2727
"@types/node": "14.14.20",
2828
"@types/react": "^16.14.2",
2929
"@types/react-dom": "16.9.10",
30+
"formik": "^2.2.9",
3031
"global": "^4.4.0",
3132
"react": "16.14.0",
3233
"react-dom": "16.14.0",
3334
"react-scripts": "3.4.4",
3435
"typescript": "^3.9.7"
3536
},
3637
"devDependencies": {
37-
"@storybook/addon-essentials": "^6.1.21",
38-
"@storybook/react": "^6.1.21",
38+
"@storybook/addon-essentials": "^6.4.0-alpha.12",
39+
"@storybook/react": "^6.4.0-alpha.12",
40+
"@storybook/components": "^6.4.0-alpha.12",
41+
"@storybook/theming": "^6.4.0-alpha.12",
3942
"@storybook/preset-create-react-app": "^3.1.5",
40-
"@testing-library/react": "^11.2.5"
43+
"@testing-library/react": "^11.2.5",
44+
"@testing-library/user-event": "^13.1.9"
4145
}
4246
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import React from 'react';
2+
import type { ComponentMeta } from '@storybook/react';
3+
import { screen } from '@testing-library/dom';
4+
import userEvent from '@testing-library/user-event';
5+
6+
import { AccountForm, AccountFormProps } from './AccountForm';
7+
8+
export default {
9+
title: 'CSF3/AccountForm',
10+
component: AccountForm,
11+
parameters: {
12+
layout: 'centered',
13+
},
14+
} as ComponentMeta<typeof AccountForm>;
15+
16+
17+
export const Standard = {
18+
args: { passwordVerification: false },
19+
};
20+
21+
export const StandardEmailFilled = {
22+
...Standard,
23+
play: () => userEvent.type(screen.getByTestId('email'), 'michael@chromatic.com'),
24+
};
25+
26+
export const StandardEmailFailed = {
27+
...Standard,
28+
play: async () => {
29+
await userEvent.type(screen.getByTestId('email'), 'michael@chromatic.com.com@com');
30+
await userEvent.type(screen.getByTestId('password1'), 'testpasswordthatwontfail');
31+
await userEvent.click(screen.getByTestId('submit'));
32+
},
33+
};
34+
35+
export const StandardPasswordFailed = {
36+
...Standard,
37+
play: async () => {
38+
await StandardEmailFilled.play();
39+
await userEvent.type(screen.getByTestId('password1'), 'asdf');
40+
await userEvent.click(screen.getByTestId('submit'));
41+
},
42+
};
43+
44+
export const StandardFailHover = {
45+
...StandardPasswordFailed,
46+
play: async () => {
47+
await StandardPasswordFailed.play();
48+
await sleep(100);
49+
await userEvent.hover(screen.getByTestId('password-error-info'));
50+
},
51+
};
52+
53+
export const Verification = {
54+
args: { passwordVerification: true },
55+
};
56+
57+
export const VerificationPasssword1 = {
58+
...Verification,
59+
play: async () => {
60+
await StandardEmailFilled.play();
61+
await userEvent.type(screen.getByTestId('password1'), 'asdfasdf');
62+
await userEvent.click(screen.getByTestId('submit'));
63+
},
64+
};
65+
66+
export const VerificationPasswordMismatch = {
67+
...Verification,
68+
play: async () => {
69+
await StandardEmailFilled.play();
70+
await userEvent.type(screen.getByTestId('password1'), 'asdfasdf');
71+
await userEvent.type(screen.getByTestId('password2'), 'asdf1234');
72+
await userEvent.click(screen.getByTestId('submit'));
73+
},
74+
};
75+
76+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
77+
78+
export const VerificationSuccess = {
79+
...Verification,
80+
play: async () => {
81+
await StandardEmailFilled.play();
82+
await sleep(1000);
83+
await userEvent.type(screen.getByTestId('password1'), 'asdfasdf', { delay: 50 });
84+
await sleep(1000);
85+
await userEvent.type(screen.getByTestId('password2'), 'asdfasdf', { delay: 50 });
86+
await sleep(1000);
87+
await userEvent.click(screen.getByTestId('submit'));
88+
},
89+
};
90+
91+
export const StandardWithRenderFunction = {
92+
...Standard,
93+
render: (args: AccountFormProps) => (<div>
94+
<p>This uses a custom render</p>
95+
<AccountForm {...args} />
96+
</div>),
97+
};

0 commit comments

Comments
 (0)