@storybook/cli 6.5.0-alpha.34 → 6.5.0-alpha.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/extract.js +7 -2
- package/dist/cjs/frameworks/angular/Header.stories.ts +8 -3
- package/dist/cjs/frameworks/angular/Page.stories.ts +12 -10
- package/dist/cjs/frameworks/angular/header.component.ts +30 -19
- package/dist/cjs/frameworks/angular/page.component.ts +13 -27
- package/dist/cjs/frameworks/common/header.css +6 -0
- package/dist/cjs/frameworks/react/js/Header.jsx +6 -1
- package/dist/cjs/frameworks/react/js/Header.stories.jsx +7 -1
- package/dist/cjs/frameworks/react/js/Page.jsx +61 -63
- package/dist/cjs/frameworks/react/js/Page.stories.jsx +12 -9
- package/dist/cjs/frameworks/react/ts/Header.stories.tsx +7 -1
- package/dist/cjs/frameworks/react/ts/Header.tsx +11 -2
- package/dist/cjs/frameworks/react/ts/Page.stories.tsx +12 -9
- package/dist/cjs/frameworks/react/ts/Page.tsx +66 -60
- package/dist/cjs/generators/baseGenerator.js +8 -0
- package/dist/cjs/versions.js +55 -55
- package/dist/esm/extract.js +7 -2
- package/dist/esm/frameworks/angular/Header.stories.ts +8 -3
- package/dist/esm/frameworks/angular/Page.stories.ts +12 -10
- package/dist/esm/frameworks/angular/header.component.ts +30 -19
- package/dist/esm/frameworks/angular/page.component.ts +13 -27
- package/dist/esm/frameworks/common/header.css +6 -0
- package/dist/esm/frameworks/react/js/Header.jsx +6 -1
- package/dist/esm/frameworks/react/js/Header.stories.jsx +7 -1
- package/dist/esm/frameworks/react/js/Page.jsx +61 -63
- package/dist/esm/frameworks/react/js/Page.stories.jsx +12 -9
- package/dist/esm/frameworks/react/ts/Header.stories.tsx +7 -1
- package/dist/esm/frameworks/react/ts/Header.tsx +11 -2
- package/dist/esm/frameworks/react/ts/Page.stories.tsx +12 -9
- package/dist/esm/frameworks/react/ts/Page.tsx +66 -60
- package/dist/esm/generators/baseGenerator.js +8 -0
- package/dist/esm/versions.js +55 -55
- package/dist/modern/extract.js +7 -2
- package/dist/modern/frameworks/common/header.css +6 -0
- package/dist/modern/frameworks/react/js/Header.jsx +6 -1
- package/dist/modern/frameworks/react/js/Header.stories.jsx +7 -1
- package/dist/modern/frameworks/react/js/Page.jsx +61 -63
- package/dist/modern/frameworks/react/js/Page.stories.jsx +12 -9
- package/dist/modern/generators/baseGenerator.js +8 -0
- package/dist/modern/versions.js +55 -55
- package/package.json +7 -7
package/dist/cjs/extract.js
CHANGED
|
@@ -24,8 +24,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
24
24
|
const read = async url => {
|
|
25
25
|
const browser = await usePuppeteerBrowser();
|
|
26
26
|
const page = await browser.newPage();
|
|
27
|
-
await page.goto(url);
|
|
28
|
-
|
|
27
|
+
await page.goto(url); // we don't know whether we are running against a new or old storybook
|
|
28
|
+
// FIXME: add tests for both
|
|
29
|
+
|
|
30
|
+
await page.waitForFunction(`
|
|
31
|
+
(window.__STORYBOOK_PREVIEW__ && window.__STORYBOOK_PREVIEW__.extract && window.__STORYBOOK_PREVIEW__.extract()) ||
|
|
32
|
+
(window.__STORYBOOK_STORY_STORE__ && window.__STORYBOOK_STORY_STORE__.extract && window.__STORYBOOK_STORY_STORE__.extract())
|
|
33
|
+
`);
|
|
29
34
|
const data = JSON.parse(await page.evaluate(async () => {
|
|
30
35
|
// eslint-disable-next-line no-undef
|
|
31
36
|
return JSON.stringify(window.__STORYBOOK_STORY_STORE__.getStoriesJsonData(), null, 2);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { moduleMetadata } from '@storybook/angular';
|
|
2
2
|
import { CommonModule } from '@angular/common';
|
|
3
|
-
|
|
4
|
-
import { Story, Meta } from '@storybook/angular/types-6-0';
|
|
3
|
+
import type { Story, Meta } from '@storybook/angular';
|
|
5
4
|
|
|
6
5
|
import Button from './button.component';
|
|
7
6
|
import Header from './header.component';
|
|
@@ -15,6 +14,10 @@ export default {
|
|
|
15
14
|
imports: [CommonModule],
|
|
16
15
|
}),
|
|
17
16
|
],
|
|
17
|
+
parameters: {
|
|
18
|
+
// More on Story layout: https://storybook.js.org/docs/angular/configure/story-layout
|
|
19
|
+
layout: 'fullscreen',
|
|
20
|
+
},
|
|
18
21
|
} as Meta;
|
|
19
22
|
|
|
20
23
|
const Template: Story<Header> = (args: Header) => ({
|
|
@@ -23,7 +26,9 @@ const Template: Story<Header> = (args: Header) => ({
|
|
|
23
26
|
|
|
24
27
|
export const LoggedIn = Template.bind({});
|
|
25
28
|
LoggedIn.args = {
|
|
26
|
-
user: {
|
|
29
|
+
user: {
|
|
30
|
+
name: 'Jane Doe',
|
|
31
|
+
},
|
|
27
32
|
};
|
|
28
33
|
|
|
29
34
|
export const LoggedOut = Template.bind({});
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { moduleMetadata, Story, Meta } from '@storybook/angular';
|
|
2
|
+
import { within, userEvent } from '@storybook/testing-library';
|
|
2
3
|
import { CommonModule } from '@angular/common';
|
|
3
4
|
|
|
4
5
|
import Button from './button.component';
|
|
5
6
|
import Header from './header.component';
|
|
6
7
|
import Page from './page.component';
|
|
7
8
|
|
|
8
|
-
import * as HeaderStories from './Header.stories';
|
|
9
|
-
|
|
10
9
|
export default {
|
|
11
10
|
title: 'Example/Page',
|
|
12
11
|
component: Page,
|
|
12
|
+
parameters: {
|
|
13
|
+
// More on Story layout: https://storybook.js.org/docs/angular/configure/story-layout
|
|
14
|
+
layout: 'fullscreen',
|
|
15
|
+
},
|
|
13
16
|
decorators: [
|
|
14
17
|
moduleMetadata({
|
|
15
18
|
declarations: [Button, Header],
|
|
@@ -22,13 +25,12 @@ const Template: Story<Page> = (args: Page) => ({
|
|
|
22
25
|
props: args,
|
|
23
26
|
});
|
|
24
27
|
|
|
25
|
-
export const LoggedIn = Template.bind({});
|
|
26
|
-
LoggedIn.args = {
|
|
27
|
-
// More on composing args: https://storybook.js.org/docs/angular/writing-stories/args#args-composition
|
|
28
|
-
...HeaderStories.LoggedIn.args,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
28
|
export const LoggedOut = Template.bind({});
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
|
|
30
|
+
// More on interaction testing: https://storybook.js.org/docs/angular/writing-tests/interaction-testing
|
|
31
|
+
export const LoggedIn = Template.bind({});
|
|
32
|
+
LoggedIn.play = async ({ canvasElement }) => {
|
|
33
|
+
const canvas = within(canvasElement);
|
|
34
|
+
const loginButton = await canvas.getByRole('button', { name: /Log in/i });
|
|
35
|
+
await userEvent.click(loginButton);
|
|
34
36
|
};
|
|
@@ -25,25 +25,36 @@ import { User } from './User';
|
|
|
25
25
|
<h1>Acme</h1>
|
|
26
26
|
</div>
|
|
27
27
|
<div>
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
28
|
+
<div *ngIf="user">
|
|
29
|
+
<span class="welcome">
|
|
30
|
+
Welcome, <b>{{ user.name }}</b
|
|
31
|
+
>!
|
|
32
|
+
</span>
|
|
33
|
+
<storybook-button
|
|
34
|
+
*ngIf="user"
|
|
35
|
+
size="small"
|
|
36
|
+
(onClick)="onLogout.emit($event)"
|
|
37
|
+
label="Log out"
|
|
38
|
+
></storybook-button>
|
|
39
|
+
</div>
|
|
40
|
+
<div *ngIf="!user">
|
|
41
|
+
<storybook-button
|
|
42
|
+
*ngIf="!user"
|
|
43
|
+
size="small"
|
|
44
|
+
class="margin-left"
|
|
45
|
+
(onClick)="onLogin.emit($event)"
|
|
46
|
+
label="Log in"
|
|
47
|
+
></storybook-button>
|
|
48
|
+
<storybook-button
|
|
49
|
+
*ngIf="!user"
|
|
50
|
+
primary
|
|
51
|
+
size="small"
|
|
52
|
+
primary="true"
|
|
53
|
+
class="margin-left"
|
|
54
|
+
(onClick)="onCreateAccount.emit($event)"
|
|
55
|
+
label="Sign up"
|
|
56
|
+
></storybook-button>
|
|
57
|
+
</div>
|
|
47
58
|
</div>
|
|
48
59
|
</div>
|
|
49
60
|
</header>`,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component
|
|
1
|
+
import { Component } from '@angular/core';
|
|
2
2
|
import { User } from './User';
|
|
3
3
|
|
|
4
4
|
@Component({
|
|
@@ -6,9 +6,9 @@ import { User } from './User';
|
|
|
6
6
|
template: `<article>
|
|
7
7
|
<storybook-header
|
|
8
8
|
[user]="user"
|
|
9
|
-
(onLogout)="
|
|
10
|
-
(onLogin)="
|
|
11
|
-
(onCreateAccount)="
|
|
9
|
+
(onLogout)="doLogout()"
|
|
10
|
+
(onLogin)="doLogin()"
|
|
11
|
+
(onCreateAccount)="doCreateAccount()"
|
|
12
12
|
></storybook-header>
|
|
13
13
|
<section>
|
|
14
14
|
<h2>Pages in Storybook</h2>
|
|
@@ -61,31 +61,17 @@ import { User } from './User';
|
|
|
61
61
|
styleUrls: ['./page.css'],
|
|
62
62
|
})
|
|
63
63
|
export default class PageComponent {
|
|
64
|
-
@Input()
|
|
65
64
|
user: User | null = null;
|
|
66
65
|
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
doLogout() {
|
|
67
|
+
this.user = null;
|
|
68
|
+
}
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
doLogin() {
|
|
71
|
+
this.user = { name: 'Jane Doe' };
|
|
72
|
+
}
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
doCreateAccount() {
|
|
75
|
+
this.user = { name: 'Jane Doe' };
|
|
76
|
+
}
|
|
75
77
|
}
|
|
76
|
-
|
|
77
|
-
// export const Page = ({ user, onLogin, onLogout, onCreateAccount }) => (
|
|
78
|
-
// <article>
|
|
79
|
-
// <Header user={user} onLogin={onLogin} onLogout={onLogout} onCreateAccount={onCreateAccount} />
|
|
80
|
-
|
|
81
|
-
// );
|
|
82
|
-
// Page.propTypes = {
|
|
83
|
-
// user: PropTypes.shape({}),
|
|
84
|
-
// onLogin: PropTypes.func.isRequired,
|
|
85
|
-
// onLogout: PropTypes.func.isRequired,
|
|
86
|
-
// onCreateAccount: PropTypes.func.isRequired,
|
|
87
|
-
// };
|
|
88
|
-
|
|
89
|
-
// Page.defaultProps = {
|
|
90
|
-
// user: null,
|
|
91
|
-
// };
|
|
@@ -28,7 +28,12 @@ export const Header = ({ user, onLogin, onLogout, onCreateAccount }) => (
|
|
|
28
28
|
</div>
|
|
29
29
|
<div>
|
|
30
30
|
{user ? (
|
|
31
|
-
|
|
31
|
+
<>
|
|
32
|
+
<span className="welcome">
|
|
33
|
+
Welcome, <b>{user.name}</b>!
|
|
34
|
+
</span>
|
|
35
|
+
<Button size="small" onClick={onLogout} label="Log out" />
|
|
36
|
+
</>
|
|
32
37
|
) : (
|
|
33
38
|
<>
|
|
34
39
|
<Button size="small" onClick={onLogin} label="Log in" />
|
|
@@ -5,13 +5,19 @@ import { Header } from './Header';
|
|
|
5
5
|
export default {
|
|
6
6
|
title: 'Example/Header',
|
|
7
7
|
component: Header,
|
|
8
|
+
parameters: {
|
|
9
|
+
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
|
|
10
|
+
layout: 'fullscreen',
|
|
11
|
+
},
|
|
8
12
|
};
|
|
9
13
|
|
|
10
14
|
const Template = (args) => <Header {...args} />;
|
|
11
15
|
|
|
12
16
|
export const LoggedIn = Template.bind({});
|
|
13
17
|
LoggedIn.args = {
|
|
14
|
-
user: {
|
|
18
|
+
user: {
|
|
19
|
+
name: 'Jane Doe',
|
|
20
|
+
},
|
|
15
21
|
};
|
|
16
22
|
|
|
17
23
|
export const LoggedOut = Template.bind({});
|
|
@@ -1,71 +1,69 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
2
|
|
|
4
3
|
import { Header } from './Header';
|
|
5
4
|
import './page.css';
|
|
6
5
|
|
|
7
|
-
export const Page = (
|
|
8
|
-
|
|
9
|
-
<Header user={user} onLogin={onLogin} onLogout={onLogout} onCreateAccount={onCreateAccount} />
|
|
6
|
+
export const Page = () => {
|
|
7
|
+
const [user, setUser] = React.useState();
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
</p>
|
|
20
|
-
<p>
|
|
21
|
-
Render pages with mock data. This makes it easy to build and review page states without
|
|
22
|
-
needing to navigate to them in your app. Here are some handy patterns for managing page data
|
|
23
|
-
in Storybook:
|
|
24
|
-
</p>
|
|
25
|
-
<ul>
|
|
26
|
-
<li>
|
|
27
|
-
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
28
|
-
"args" of child component stories
|
|
29
|
-
</li>
|
|
30
|
-
<li>
|
|
31
|
-
Assemble data in the page component from your services. You can mock these services out
|
|
32
|
-
using Storybook.
|
|
33
|
-
</li>
|
|
34
|
-
</ul>
|
|
35
|
-
<p>
|
|
36
|
-
Get a guided tutorial on component-driven development at{' '}
|
|
37
|
-
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
|
|
38
|
-
Storybook tutorials
|
|
39
|
-
</a>
|
|
40
|
-
. Read more in the{' '}
|
|
41
|
-
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
|
|
42
|
-
docs
|
|
43
|
-
</a>
|
|
44
|
-
.
|
|
45
|
-
</p>
|
|
46
|
-
<div className="tip-wrapper">
|
|
47
|
-
<span className="tip">Tip</span> Adjust the width of the canvas with the{' '}
|
|
48
|
-
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
|
49
|
-
<g fill="none" fillRule="evenodd">
|
|
50
|
-
<path
|
|
51
|
-
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
|
|
52
|
-
id="a"
|
|
53
|
-
fill="#999"
|
|
54
|
-
/>
|
|
55
|
-
</g>
|
|
56
|
-
</svg>
|
|
57
|
-
Viewports addon in the toolbar
|
|
58
|
-
</div>
|
|
59
|
-
</section>
|
|
60
|
-
</article>
|
|
61
|
-
);
|
|
62
|
-
Page.propTypes = {
|
|
63
|
-
user: PropTypes.shape({}),
|
|
64
|
-
onLogin: PropTypes.func.isRequired,
|
|
65
|
-
onLogout: PropTypes.func.isRequired,
|
|
66
|
-
onCreateAccount: PropTypes.func.isRequired,
|
|
67
|
-
};
|
|
9
|
+
return (
|
|
10
|
+
<article>
|
|
11
|
+
<Header
|
|
12
|
+
user={user}
|
|
13
|
+
onLogin={() => setUser({ name: 'Jane Doe' })}
|
|
14
|
+
onLogout={() => setUser(undefined)}
|
|
15
|
+
onCreateAccount={() => setUser({ name: 'Jane Doe' })}
|
|
16
|
+
/>
|
|
68
17
|
|
|
69
|
-
|
|
70
|
-
|
|
18
|
+
<section>
|
|
19
|
+
<h2>Pages in Storybook</h2>
|
|
20
|
+
<p>
|
|
21
|
+
We recommend building UIs with a{' '}
|
|
22
|
+
<a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
|
|
23
|
+
<strong>component-driven</strong>
|
|
24
|
+
</a>{' '}
|
|
25
|
+
process starting with atomic components and ending with pages.
|
|
26
|
+
</p>
|
|
27
|
+
<p>
|
|
28
|
+
Render pages with mock data. This makes it easy to build and review page states without
|
|
29
|
+
needing to navigate to them in your app. Here are some handy patterns for managing page
|
|
30
|
+
data in Storybook:
|
|
31
|
+
</p>
|
|
32
|
+
<ul>
|
|
33
|
+
<li>
|
|
34
|
+
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
35
|
+
"args" of child component stories
|
|
36
|
+
</li>
|
|
37
|
+
<li>
|
|
38
|
+
Assemble data in the page component from your services. You can mock these services out
|
|
39
|
+
using Storybook.
|
|
40
|
+
</li>
|
|
41
|
+
</ul>
|
|
42
|
+
<p>
|
|
43
|
+
Get a guided tutorial on component-driven development at{' '}
|
|
44
|
+
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
|
|
45
|
+
Storybook tutorials
|
|
46
|
+
</a>
|
|
47
|
+
. Read more in the{' '}
|
|
48
|
+
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
|
|
49
|
+
docs
|
|
50
|
+
</a>
|
|
51
|
+
.
|
|
52
|
+
</p>
|
|
53
|
+
<div className="tip-wrapper">
|
|
54
|
+
<span className="tip">Tip</span> Adjust the width of the canvas with the{' '}
|
|
55
|
+
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
|
56
|
+
<g fill="none" fillRule="evenodd">
|
|
57
|
+
<path
|
|
58
|
+
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
|
|
59
|
+
id="a"
|
|
60
|
+
fill="#999"
|
|
61
|
+
/>
|
|
62
|
+
</g>
|
|
63
|
+
</svg>
|
|
64
|
+
Viewports addon in the toolbar
|
|
65
|
+
</div>
|
|
66
|
+
</section>
|
|
67
|
+
</article>
|
|
68
|
+
);
|
|
71
69
|
};
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { within, userEvent } from '@storybook/testing-library';
|
|
2
3
|
|
|
3
4
|
import { Page } from './Page';
|
|
4
|
-
import * as HeaderStories from './Header.stories';
|
|
5
5
|
|
|
6
6
|
export default {
|
|
7
7
|
title: 'Example/Page',
|
|
8
8
|
component: Page,
|
|
9
|
+
parameters: {
|
|
10
|
+
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
|
|
11
|
+
layout: 'fullscreen',
|
|
12
|
+
},
|
|
9
13
|
};
|
|
10
14
|
|
|
11
15
|
const Template = (args) => <Page {...args} />;
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
LoggedIn.args = {
|
|
15
|
-
// More on composing args: https://storybook.js.org/docs/react/writing-stories/args#args-composition
|
|
16
|
-
...HeaderStories.LoggedIn.args,
|
|
17
|
-
};
|
|
18
|
-
|
|
17
|
+
// More on interaction testing: https://storybook.js.org/docs/react/writing-tests/interaction-testing
|
|
19
18
|
export const LoggedOut = Template.bind({});
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
|
|
20
|
+
export const LoggedIn = Template.bind({});
|
|
21
|
+
LoggedIn.play = async ({ canvasElement }) => {
|
|
22
|
+
const canvas = within(canvasElement);
|
|
23
|
+
const loginButton = await canvas.getByRole('button', { name: /Log in/i });
|
|
24
|
+
await userEvent.click(loginButton);
|
|
22
25
|
};
|
|
@@ -6,13 +6,19 @@ import { Header } from './Header';
|
|
|
6
6
|
export default {
|
|
7
7
|
title: 'Example/Header',
|
|
8
8
|
component: Header,
|
|
9
|
+
parameters: {
|
|
10
|
+
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
|
|
11
|
+
layout: 'fullscreen',
|
|
12
|
+
},
|
|
9
13
|
} as ComponentMeta<typeof Header>;
|
|
10
14
|
|
|
11
15
|
const Template: ComponentStory<typeof Header> = (args) => <Header {...args} />;
|
|
12
16
|
|
|
13
17
|
export const LoggedIn = Template.bind({});
|
|
14
18
|
LoggedIn.args = {
|
|
15
|
-
user: {
|
|
19
|
+
user: {
|
|
20
|
+
name: 'Jane Doe',
|
|
21
|
+
},
|
|
16
22
|
};
|
|
17
23
|
|
|
18
24
|
export const LoggedOut = Template.bind({});
|
|
@@ -3,8 +3,12 @@ import React from 'react';
|
|
|
3
3
|
import { Button } from './Button';
|
|
4
4
|
import './header.css';
|
|
5
5
|
|
|
6
|
+
type User = {
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
6
10
|
interface HeaderProps {
|
|
7
|
-
user?:
|
|
11
|
+
user?: User;
|
|
8
12
|
onLogin: () => void;
|
|
9
13
|
onLogout: () => void;
|
|
10
14
|
onCreateAccount: () => void;
|
|
@@ -34,7 +38,12 @@ export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps
|
|
|
34
38
|
</div>
|
|
35
39
|
<div>
|
|
36
40
|
{user ? (
|
|
37
|
-
|
|
41
|
+
<>
|
|
42
|
+
<span className="welcome">
|
|
43
|
+
Welcome, <b>{user.name}</b>!
|
|
44
|
+
</span>
|
|
45
|
+
<Button size="small" onClick={onLogout} label="Log out" />
|
|
46
|
+
</>
|
|
38
47
|
) : (
|
|
39
48
|
<>
|
|
40
49
|
<Button size="small" onClick={onLogin} label="Log in" />
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { ComponentStory, ComponentMeta } from '@storybook/react';
|
|
3
|
-
|
|
3
|
+
import { within, userEvent } from '@storybook/testing-library';
|
|
4
4
|
import { Page } from './Page';
|
|
5
|
-
import * as HeaderStories from './Header.stories';
|
|
6
5
|
|
|
7
6
|
export default {
|
|
8
7
|
title: 'Example/Page',
|
|
9
8
|
component: Page,
|
|
9
|
+
parameters: {
|
|
10
|
+
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
|
|
11
|
+
layout: 'fullscreen',
|
|
12
|
+
},
|
|
10
13
|
} as ComponentMeta<typeof Page>;
|
|
11
14
|
|
|
12
15
|
const Template: ComponentStory<typeof Page> = (args) => <Page {...args} />;
|
|
13
16
|
|
|
17
|
+
export const LoggedOut = Template.bind({});
|
|
18
|
+
|
|
14
19
|
export const LoggedIn = Template.bind({});
|
|
15
|
-
LoggedIn.args = {
|
|
16
|
-
// More on composing args: https://storybook.js.org/docs/react/writing-stories/args#args-composition
|
|
17
|
-
...HeaderStories.LoggedIn.args,
|
|
18
|
-
};
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
// More on interaction testing: https://storybook.js.org/docs/react/writing-tests/interaction-testing
|
|
22
|
+
LoggedIn.play = async ({ canvasElement }) => {
|
|
23
|
+
const canvas = within(canvasElement);
|
|
24
|
+
const loginButton = await canvas.getByRole('button', { name: /Log in/i });
|
|
25
|
+
await userEvent.click(loginButton);
|
|
23
26
|
};
|
|
@@ -3,65 +3,71 @@ import React from 'react';
|
|
|
3
3
|
import { Header } from './Header';
|
|
4
4
|
import './page.css';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
onLogout: () => void;
|
|
10
|
-
onCreateAccount: () => void;
|
|
11
|
-
}
|
|
6
|
+
type User = {
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
12
9
|
|
|
13
|
-
export const Page = (
|
|
14
|
-
<
|
|
15
|
-
<Header user={user} onLogin={onLogin} onLogout={onLogout} onCreateAccount={onCreateAccount} />
|
|
10
|
+
export const Page: React.VFC = () => {
|
|
11
|
+
const [user, setUser] = React.useState<User>();
|
|
16
12
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
</
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
</
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
13
|
+
return (
|
|
14
|
+
<article>
|
|
15
|
+
<Header
|
|
16
|
+
user={user}
|
|
17
|
+
onLogin={() => setUser({ name: 'Jane Doe' })}
|
|
18
|
+
onLogout={() => setUser(undefined)}
|
|
19
|
+
onCreateAccount={() => setUser({ name: 'Jane Doe' })}
|
|
20
|
+
/>
|
|
21
|
+
|
|
22
|
+
<section>
|
|
23
|
+
<h2>Pages in Storybook</h2>
|
|
24
|
+
<p>
|
|
25
|
+
We recommend building UIs with a{' '}
|
|
26
|
+
<a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
|
|
27
|
+
<strong>component-driven</strong>
|
|
28
|
+
</a>{' '}
|
|
29
|
+
process starting with atomic components and ending with pages.
|
|
30
|
+
</p>
|
|
31
|
+
<p>
|
|
32
|
+
Render pages with mock data. This makes it easy to build and review page states without
|
|
33
|
+
needing to navigate to them in your app. Here are some handy patterns for managing page
|
|
34
|
+
data in Storybook:
|
|
35
|
+
</p>
|
|
36
|
+
<ul>
|
|
37
|
+
<li>
|
|
38
|
+
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
39
|
+
"args" of child component stories
|
|
40
|
+
</li>
|
|
41
|
+
<li>
|
|
42
|
+
Assemble data in the page component from your services. You can mock these services out
|
|
43
|
+
using Storybook.
|
|
44
|
+
</li>
|
|
45
|
+
</ul>
|
|
46
|
+
<p>
|
|
47
|
+
Get a guided tutorial on component-driven development at{' '}
|
|
48
|
+
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
|
|
49
|
+
Storybook tutorials
|
|
50
|
+
</a>
|
|
51
|
+
. Read more in the{' '}
|
|
52
|
+
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
|
|
53
|
+
docs
|
|
54
|
+
</a>
|
|
55
|
+
.
|
|
56
|
+
</p>
|
|
57
|
+
<div className="tip-wrapper">
|
|
58
|
+
<span className="tip">Tip</span> Adjust the width of the canvas with the{' '}
|
|
59
|
+
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
|
60
|
+
<g fill="none" fillRule="evenodd">
|
|
61
|
+
<path
|
|
62
|
+
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
|
|
63
|
+
id="a"
|
|
64
|
+
fill="#999"
|
|
65
|
+
/>
|
|
66
|
+
</g>
|
|
67
|
+
</svg>
|
|
68
|
+
Viewports addon in the toolbar
|
|
69
|
+
</div>
|
|
70
|
+
</section>
|
|
71
|
+
</article>
|
|
72
|
+
);
|
|
73
|
+
};
|