@storybook/cli 7.0.0-alpha.29 → 7.0.0-alpha.31
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/generators/PREACT/index.js +1 -3
- package/dist/cjs/versions.js +79 -79
- package/dist/esm/generators/PREACT/index.js +1 -3
- package/dist/esm/versions.js +79 -79
- package/package.json +11 -12
- package/rendererAssets/.eslintrc.json +11 -0
- package/rendererAssets/angular/Button.stories.ts +43 -0
- package/rendererAssets/angular/Header.stories.ts +35 -0
- package/rendererAssets/angular/Page.stories.ts +36 -0
- package/rendererAssets/angular/User.ts +2 -0
- package/rendererAssets/angular/button.component.ts +53 -0
- package/rendererAssets/angular/header.component.ts +75 -0
- package/rendererAssets/angular/page.component.ts +77 -0
- package/rendererAssets/aurelia/1-Button.stories.ts +49 -0
- package/rendererAssets/aurelia/button.ts +28 -0
- package/rendererAssets/common/Introduction.stories.mdx +211 -0
- package/rendererAssets/common/assets/code-brackets.svg +1 -0
- package/rendererAssets/common/assets/colors.svg +1 -0
- package/rendererAssets/common/assets/comments.svg +1 -0
- package/rendererAssets/common/assets/direction.svg +1 -0
- package/rendererAssets/common/assets/flow.svg +1 -0
- package/rendererAssets/common/assets/plugin.svg +1 -0
- package/rendererAssets/common/assets/repo.svg +1 -0
- package/rendererAssets/common/assets/stackalt.svg +1 -0
- package/rendererAssets/common/button.css +30 -0
- package/rendererAssets/common/header.css +32 -0
- package/rendererAssets/common/page.css +69 -0
- package/rendererAssets/ember/1-Button.stories.js +57 -0
- package/rendererAssets/html/js/Button.js +21 -0
- package/rendererAssets/html/js/Button.stories.js +48 -0
- package/rendererAssets/html/js/Header.js +47 -0
- package/rendererAssets/html/js/Header.stories.js +27 -0
- package/rendererAssets/html/js/Page.js +94 -0
- package/rendererAssets/html/js/Page.stories.js +23 -0
- package/rendererAssets/html/ts/Button.stories.ts +49 -0
- package/rendererAssets/html/ts/Button.ts +51 -0
- package/rendererAssets/html/ts/Header.stories.ts +26 -0
- package/rendererAssets/html/ts/Header.ts +54 -0
- package/rendererAssets/html/ts/Page.stories.ts +24 -0
- package/rendererAssets/html/ts/Page.ts +98 -0
- package/rendererAssets/marionette/index.stories.js +20 -0
- package/rendererAssets/marko/1-Button.stories.js +24 -0
- package/rendererAssets/marko/Button.marko +13 -0
- package/rendererAssets/mithril/Button.js +22 -0
- package/rendererAssets/mithril/Button.stories.js +43 -0
- package/rendererAssets/mithril/Header.js +51 -0
- package/rendererAssets/mithril/Header.stories.js +20 -0
- package/rendererAssets/mithril/Page.js +70 -0
- package/rendererAssets/mithril/Page.stories.js +24 -0
- package/rendererAssets/preact/Button.jsx +51 -0
- package/rendererAssets/preact/Button.stories.jsx +41 -0
- package/rendererAssets/preact/Header.jsx +58 -0
- package/rendererAssets/preact/Header.stories.jsx +29 -0
- package/rendererAssets/preact/Page.jsx +71 -0
- package/rendererAssets/preact/Page.stories.jsx +26 -0
- package/rendererAssets/rax/Button.js +26 -0
- package/rendererAssets/rax/Button.stories.js +40 -0
- package/rendererAssets/rax/Header.js +44 -0
- package/rendererAssets/rax/Header.stories.js +17 -0
- package/rendererAssets/rax/Page.js +64 -0
- package/rendererAssets/rax/Page.stories.js +21 -0
- package/rendererAssets/react/js/Button.jsx +50 -0
- package/rendererAssets/react/js/Button.stories.jsx +40 -0
- package/rendererAssets/react/js/Header.jsx +57 -0
- package/rendererAssets/react/js/Header.stories.jsx +24 -0
- package/rendererAssets/react/js/Page.jsx +69 -0
- package/rendererAssets/react/js/Page.stories.jsx +25 -0
- package/rendererAssets/react/ts/Button.stories.tsx +41 -0
- package/rendererAssets/react/ts/Button.tsx +48 -0
- package/rendererAssets/react/ts/Header.stories.tsx +25 -0
- package/rendererAssets/react/ts/Header.tsx +56 -0
- package/rendererAssets/react/ts/Page.stories.tsx +26 -0
- package/rendererAssets/react/ts/Page.tsx +73 -0
- package/rendererAssets/riot/1-Button.stories.js +52 -0
- package/rendererAssets/riot/MyButton.tag +24 -0
- package/rendererAssets/server/button.stories.json +32 -0
- package/rendererAssets/server/header.stories.json +15 -0
- package/rendererAssets/server/page.stories.json +15 -0
- package/rendererAssets/svelte/Button.stories.js +51 -0
- package/rendererAssets/svelte/Button.svelte +42 -0
- package/rendererAssets/svelte/Header.stories.js +35 -0
- package/rendererAssets/svelte/Header.svelte +51 -0
- package/rendererAssets/svelte/Page.stories.js +27 -0
- package/rendererAssets/svelte/Page.svelte +63 -0
- package/rendererAssets/vue/Button.stories.js +46 -0
- package/rendererAssets/vue/Button.vue +54 -0
- package/rendererAssets/vue/Header.stories.js +27 -0
- package/rendererAssets/vue/Header.vue +60 -0
- package/rendererAssets/vue/Page.stories.js +27 -0
- package/rendererAssets/vue/Page.vue +88 -0
- package/rendererAssets/vue3/Button.stories.js +52 -0
- package/rendererAssets/vue3/Button.vue +52 -0
- package/rendererAssets/vue3/Header.stories.js +34 -0
- package/rendererAssets/vue3/Header.vue +50 -0
- package/rendererAssets/vue3/Page.stories.js +29 -0
- package/rendererAssets/vue3/Page.vue +88 -0
- package/rendererAssets/web-components/js/Button.js +21 -0
- package/rendererAssets/web-components/js/Button.stories.js +42 -0
- package/rendererAssets/web-components/js/Header.js +45 -0
- package/rendererAssets/web-components/js/Header.stories.js +15 -0
- package/rendererAssets/web-components/js/Page.js +61 -0
- package/rendererAssets/web-components/js/Page.stories.js +19 -0
- package/rendererAssets/web-components/ts/Button.stories.ts +43 -0
- package/rendererAssets/web-components/ts/Button.ts +43 -0
- package/rendererAssets/web-components/ts/Header.stories.ts +16 -0
- package/rendererAssets/web-components/ts/Header.ts +52 -0
- package/rendererAssets/web-components/ts/Page.stories.ts +20 -0
- package/rendererAssets/web-components/ts/Page.ts +68 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createElement } from 'rax';
|
|
2
|
+
|
|
3
|
+
import { Header } from './Header';
|
|
4
|
+
import './page.css';
|
|
5
|
+
|
|
6
|
+
export const Page = ({ user, onLogin, onLogout, onCreateAccount }) => (
|
|
7
|
+
<article>
|
|
8
|
+
<Header user={user} onLogin={onLogin} onLogout={onLogout} onCreateAccount={onCreateAccount} />
|
|
9
|
+
|
|
10
|
+
<section>
|
|
11
|
+
<h2>Pages in Storybook</h2>
|
|
12
|
+
<p>
|
|
13
|
+
We recommend building UIs with a{' '}
|
|
14
|
+
<a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
|
|
15
|
+
<strong>component-driven</strong>
|
|
16
|
+
</a>{' '}
|
|
17
|
+
process starting with atomic components and ending with pages.
|
|
18
|
+
</p>
|
|
19
|
+
<p>
|
|
20
|
+
Render pages with mock data. This makes it easy to build and review page states without
|
|
21
|
+
needing to navigate to them in your app. Here are some handy patterns for managing page data
|
|
22
|
+
in Storybook:
|
|
23
|
+
</p>
|
|
24
|
+
<ul>
|
|
25
|
+
<li>
|
|
26
|
+
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
27
|
+
"args" of child component stories
|
|
28
|
+
</li>
|
|
29
|
+
<li>
|
|
30
|
+
Assemble data in the page component from your services. You can mock these services out
|
|
31
|
+
using Storybook.
|
|
32
|
+
</li>
|
|
33
|
+
</ul>
|
|
34
|
+
<p>
|
|
35
|
+
Get a guided tutorial on component-driven development at{' '}
|
|
36
|
+
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
|
|
37
|
+
Storybook tutorials
|
|
38
|
+
</a>
|
|
39
|
+
. Read more in the{' '}
|
|
40
|
+
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
|
|
41
|
+
docs
|
|
42
|
+
</a>
|
|
43
|
+
.
|
|
44
|
+
</p>
|
|
45
|
+
<div className="tip-wrapper">
|
|
46
|
+
<span className="tip">Tip</span> Adjust the width of the canvas with the{' '}
|
|
47
|
+
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
|
48
|
+
<g fill="none" fillRule="evenodd">
|
|
49
|
+
<path
|
|
50
|
+
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"
|
|
51
|
+
id="a"
|
|
52
|
+
fill="#999"
|
|
53
|
+
/>
|
|
54
|
+
</g>
|
|
55
|
+
</svg>
|
|
56
|
+
Viewports addon in the toolbar
|
|
57
|
+
</div>
|
|
58
|
+
</section>
|
|
59
|
+
</article>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
Page.defaultProps = {
|
|
63
|
+
user: null,
|
|
64
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createElement } from 'rax';
|
|
2
|
+
|
|
3
|
+
import { Page } from './Page';
|
|
4
|
+
import * as HeaderStories from './Header.stories';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Example/Page',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const Template = (args) => <Page {...args} />;
|
|
11
|
+
|
|
12
|
+
export const LoggedIn = Template.bind({});
|
|
13
|
+
LoggedIn.args = {
|
|
14
|
+
// More on composing args: https://storybook.js.org/docs/rax/writing-stories/args#args-composition
|
|
15
|
+
...HeaderStories.LoggedIn.args,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const LoggedOut = Template.bind({});
|
|
19
|
+
LoggedOut.args = {
|
|
20
|
+
...HeaderStories.LoggedOut.args,
|
|
21
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import './button.css';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Primary UI component for user interaction
|
|
7
|
+
*/
|
|
8
|
+
export const Button = ({ primary, backgroundColor, size, label, ...props }) => {
|
|
9
|
+
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
10
|
+
return (
|
|
11
|
+
<button
|
|
12
|
+
type="button"
|
|
13
|
+
className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
|
|
14
|
+
style={backgroundColor && { backgroundColor }}
|
|
15
|
+
{...props}
|
|
16
|
+
>
|
|
17
|
+
{label}
|
|
18
|
+
</button>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
Button.propTypes = {
|
|
23
|
+
/**
|
|
24
|
+
* Is this the principal call to action on the page?
|
|
25
|
+
*/
|
|
26
|
+
primary: PropTypes.bool,
|
|
27
|
+
/**
|
|
28
|
+
* What background color to use
|
|
29
|
+
*/
|
|
30
|
+
backgroundColor: PropTypes.string,
|
|
31
|
+
/**
|
|
32
|
+
* How large should the button be?
|
|
33
|
+
*/
|
|
34
|
+
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
35
|
+
/**
|
|
36
|
+
* Button contents
|
|
37
|
+
*/
|
|
38
|
+
label: PropTypes.string.isRequired,
|
|
39
|
+
/**
|
|
40
|
+
* Optional click handler
|
|
41
|
+
*/
|
|
42
|
+
onClick: PropTypes.func,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
Button.defaultProps = {
|
|
46
|
+
backgroundColor: null,
|
|
47
|
+
primary: false,
|
|
48
|
+
size: 'medium',
|
|
49
|
+
onClick: undefined,
|
|
50
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Button } from './Button';
|
|
4
|
+
|
|
5
|
+
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Example/Button',
|
|
8
|
+
component: Button,
|
|
9
|
+
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
|
|
10
|
+
argTypes: {
|
|
11
|
+
backgroundColor: { control: 'color' },
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
|
|
16
|
+
const Template = (args) => <Button {...args} />;
|
|
17
|
+
|
|
18
|
+
export const Primary = Template.bind({});
|
|
19
|
+
// More on args: https://storybook.js.org/docs/react/writing-stories/args
|
|
20
|
+
Primary.args = {
|
|
21
|
+
primary: true,
|
|
22
|
+
label: 'Button',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const Secondary = Template.bind({});
|
|
26
|
+
Secondary.args = {
|
|
27
|
+
label: 'Button',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const Large = Template.bind({});
|
|
31
|
+
Large.args = {
|
|
32
|
+
size: 'large',
|
|
33
|
+
label: 'Button',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const Small = Template.bind({});
|
|
37
|
+
Small.args = {
|
|
38
|
+
size: 'small',
|
|
39
|
+
label: 'Button',
|
|
40
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
import { Button } from './Button';
|
|
5
|
+
import './header.css';
|
|
6
|
+
|
|
7
|
+
export const Header = ({ user, onLogin, onLogout, onCreateAccount }) => (
|
|
8
|
+
<header>
|
|
9
|
+
<div className="wrapper">
|
|
10
|
+
<div>
|
|
11
|
+
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
|
12
|
+
<g fill="none" fillRule="evenodd">
|
|
13
|
+
<path
|
|
14
|
+
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
|
15
|
+
fill="#FFF"
|
|
16
|
+
/>
|
|
17
|
+
<path
|
|
18
|
+
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
|
|
19
|
+
fill="#555AB9"
|
|
20
|
+
/>
|
|
21
|
+
<path
|
|
22
|
+
d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
|
|
23
|
+
fill="#91BAF8"
|
|
24
|
+
/>
|
|
25
|
+
</g>
|
|
26
|
+
</svg>
|
|
27
|
+
<h1>Acme</h1>
|
|
28
|
+
</div>
|
|
29
|
+
<div>
|
|
30
|
+
{user ? (
|
|
31
|
+
<>
|
|
32
|
+
<span className="welcome">
|
|
33
|
+
Welcome, <b>{user.name}</b>!
|
|
34
|
+
</span>
|
|
35
|
+
<Button size="small" onClick={onLogout} label="Log out" />
|
|
36
|
+
</>
|
|
37
|
+
) : (
|
|
38
|
+
<>
|
|
39
|
+
<Button size="small" onClick={onLogin} label="Log in" />
|
|
40
|
+
<Button primary size="small" onClick={onCreateAccount} label="Sign up" />
|
|
41
|
+
</>
|
|
42
|
+
)}
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</header>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
Header.propTypes = {
|
|
49
|
+
user: PropTypes.shape({}),
|
|
50
|
+
onLogin: PropTypes.func.isRequired,
|
|
51
|
+
onLogout: PropTypes.func.isRequired,
|
|
52
|
+
onCreateAccount: PropTypes.func.isRequired,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
Header.defaultProps = {
|
|
56
|
+
user: null,
|
|
57
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Header } from './Header';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'Example/Header',
|
|
7
|
+
component: Header,
|
|
8
|
+
parameters: {
|
|
9
|
+
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
|
|
10
|
+
layout: 'fullscreen',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const Template = (args) => <Header {...args} />;
|
|
15
|
+
|
|
16
|
+
export const LoggedIn = Template.bind({});
|
|
17
|
+
LoggedIn.args = {
|
|
18
|
+
user: {
|
|
19
|
+
name: 'Jane Doe',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const LoggedOut = Template.bind({});
|
|
24
|
+
LoggedOut.args = {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Header } from './Header';
|
|
4
|
+
import './page.css';
|
|
5
|
+
|
|
6
|
+
export const Page = () => {
|
|
7
|
+
const [user, setUser] = React.useState();
|
|
8
|
+
|
|
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
|
+
/>
|
|
17
|
+
|
|
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
|
+
);
|
|
69
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { within, userEvent } from '@storybook/testing-library';
|
|
3
|
+
|
|
4
|
+
import { Page } from './Page';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Example/Page',
|
|
8
|
+
component: Page,
|
|
9
|
+
parameters: {
|
|
10
|
+
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
|
|
11
|
+
layout: 'fullscreen',
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const Template = (args) => <Page {...args} />;
|
|
16
|
+
|
|
17
|
+
// More on interaction testing: https://storybook.js.org/docs/react/writing-tests/interaction-testing
|
|
18
|
+
export const LoggedOut = Template.bind({});
|
|
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);
|
|
25
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ComponentStoryFn, ComponentMeta } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import { Button } from './Button';
|
|
5
|
+
|
|
6
|
+
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
|
|
7
|
+
export default {
|
|
8
|
+
title: 'Example/Button',
|
|
9
|
+
component: Button,
|
|
10
|
+
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
|
|
11
|
+
argTypes: {
|
|
12
|
+
backgroundColor: { control: 'color' },
|
|
13
|
+
},
|
|
14
|
+
} as ComponentMeta<typeof Button>;
|
|
15
|
+
|
|
16
|
+
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
|
|
17
|
+
const Template: ComponentStoryFn<typeof Button> = (args) => <Button {...args} />;
|
|
18
|
+
|
|
19
|
+
export const Primary = Template.bind({});
|
|
20
|
+
// More on args: https://storybook.js.org/docs/react/writing-stories/args
|
|
21
|
+
Primary.args = {
|
|
22
|
+
primary: true,
|
|
23
|
+
label: 'Button',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const Secondary = Template.bind({});
|
|
27
|
+
Secondary.args = {
|
|
28
|
+
label: 'Button',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const Large = Template.bind({});
|
|
32
|
+
Large.args = {
|
|
33
|
+
size: 'large',
|
|
34
|
+
label: 'Button',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const Small = Template.bind({});
|
|
38
|
+
Small.args = {
|
|
39
|
+
size: 'small',
|
|
40
|
+
label: 'Button',
|
|
41
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './button.css';
|
|
3
|
+
|
|
4
|
+
interface ButtonProps {
|
|
5
|
+
/**
|
|
6
|
+
* Is this the principal call to action on the page?
|
|
7
|
+
*/
|
|
8
|
+
primary?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* What background color to use
|
|
11
|
+
*/
|
|
12
|
+
backgroundColor?: string;
|
|
13
|
+
/**
|
|
14
|
+
* How large should the button be?
|
|
15
|
+
*/
|
|
16
|
+
size?: 'small' | 'medium' | 'large';
|
|
17
|
+
/**
|
|
18
|
+
* Button contents
|
|
19
|
+
*/
|
|
20
|
+
label: string;
|
|
21
|
+
/**
|
|
22
|
+
* Optional click handler
|
|
23
|
+
*/
|
|
24
|
+
onClick?: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Primary UI component for user interaction
|
|
29
|
+
*/
|
|
30
|
+
export const Button = ({
|
|
31
|
+
primary = false,
|
|
32
|
+
size = 'medium',
|
|
33
|
+
backgroundColor,
|
|
34
|
+
label,
|
|
35
|
+
...props
|
|
36
|
+
}: ButtonProps) => {
|
|
37
|
+
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
38
|
+
return (
|
|
39
|
+
<button
|
|
40
|
+
type="button"
|
|
41
|
+
className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
|
|
42
|
+
style={{ backgroundColor }}
|
|
43
|
+
{...props}
|
|
44
|
+
>
|
|
45
|
+
{label}
|
|
46
|
+
</button>
|
|
47
|
+
);
|
|
48
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ComponentStoryFn, ComponentMeta } from '@storybook/react';
|
|
3
|
+
|
|
4
|
+
import { Header } from './Header';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Example/Header',
|
|
8
|
+
component: Header,
|
|
9
|
+
parameters: {
|
|
10
|
+
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
|
|
11
|
+
layout: 'fullscreen',
|
|
12
|
+
},
|
|
13
|
+
} as ComponentMeta<typeof Header>;
|
|
14
|
+
|
|
15
|
+
const Template: ComponentStoryFn<typeof Header> = (args) => <Header {...args} />;
|
|
16
|
+
|
|
17
|
+
export const LoggedIn = Template.bind({});
|
|
18
|
+
LoggedIn.args = {
|
|
19
|
+
user: {
|
|
20
|
+
name: 'Jane Doe',
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const LoggedOut = Template.bind({});
|
|
25
|
+
LoggedOut.args = {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Button } from './Button';
|
|
4
|
+
import './header.css';
|
|
5
|
+
|
|
6
|
+
type User = {
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
interface HeaderProps {
|
|
11
|
+
user?: User;
|
|
12
|
+
onLogin: () => void;
|
|
13
|
+
onLogout: () => void;
|
|
14
|
+
onCreateAccount: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Header = ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => (
|
|
18
|
+
<header>
|
|
19
|
+
<div className="wrapper">
|
|
20
|
+
<div>
|
|
21
|
+
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
|
22
|
+
<g fill="none" fillRule="evenodd">
|
|
23
|
+
<path
|
|
24
|
+
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
|
25
|
+
fill="#FFF"
|
|
26
|
+
/>
|
|
27
|
+
<path
|
|
28
|
+
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
|
|
29
|
+
fill="#555AB9"
|
|
30
|
+
/>
|
|
31
|
+
<path
|
|
32
|
+
d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
|
|
33
|
+
fill="#91BAF8"
|
|
34
|
+
/>
|
|
35
|
+
</g>
|
|
36
|
+
</svg>
|
|
37
|
+
<h1>Acme</h1>
|
|
38
|
+
</div>
|
|
39
|
+
<div>
|
|
40
|
+
{user ? (
|
|
41
|
+
<>
|
|
42
|
+
<span className="welcome">
|
|
43
|
+
Welcome, <b>{user.name}</b>!
|
|
44
|
+
</span>
|
|
45
|
+
<Button size="small" onClick={onLogout} label="Log out" />
|
|
46
|
+
</>
|
|
47
|
+
) : (
|
|
48
|
+
<>
|
|
49
|
+
<Button size="small" onClick={onLogin} label="Log in" />
|
|
50
|
+
<Button primary size="small" onClick={onCreateAccount} label="Sign up" />
|
|
51
|
+
</>
|
|
52
|
+
)}
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
</header>
|
|
56
|
+
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ComponentStoryFn, ComponentMeta } from '@storybook/react';
|
|
3
|
+
import { within, userEvent } from '@storybook/testing-library';
|
|
4
|
+
import { Page } from './Page';
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
title: 'Example/Page',
|
|
8
|
+
component: Page,
|
|
9
|
+
parameters: {
|
|
10
|
+
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
|
|
11
|
+
layout: 'fullscreen',
|
|
12
|
+
},
|
|
13
|
+
} as ComponentMeta<typeof Page>;
|
|
14
|
+
|
|
15
|
+
const Template: ComponentStoryFn<typeof Page> = (args) => <Page {...args} />;
|
|
16
|
+
|
|
17
|
+
export const LoggedOut = Template.bind({});
|
|
18
|
+
|
|
19
|
+
export const LoggedIn = Template.bind({});
|
|
20
|
+
|
|
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);
|
|
26
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Header } from './Header';
|
|
4
|
+
import './page.css';
|
|
5
|
+
|
|
6
|
+
type User = {
|
|
7
|
+
name: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const Page: React.VFC = () => {
|
|
11
|
+
const [user, setUser] = React.useState<User>();
|
|
12
|
+
|
|
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
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { mount } from '@storybook/riot';
|
|
2
|
+
import { linkTo } from '@storybook/addon-links';
|
|
3
|
+
import { action } from '@storybook/addon-actions';
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line
|
|
6
|
+
import MyButtonRaw from 'raw-loader!./MyButton.tag';
|
|
7
|
+
import './MyButton.tag';
|
|
8
|
+
|
|
9
|
+
// More on default export: https://storybook.js.org/docs/riot/writing-stories/introduction#default-export
|
|
10
|
+
export default {
|
|
11
|
+
title: 'Button',
|
|
12
|
+
// More on argTypes: https://storybook.js.org/docs/riot/api/argtypes
|
|
13
|
+
argTypes: {
|
|
14
|
+
content: { control: 'text' },
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// More on component templates: https://storybook.js.org/docs/riot/writing-stories/introduction#using-args
|
|
19
|
+
const Template = (args) => mount('my-button', args);
|
|
20
|
+
|
|
21
|
+
export const Text = Template.bind({});
|
|
22
|
+
// More on args: https://storybook.js.org/docs/riot/writing-stories/args
|
|
23
|
+
Text.args = {
|
|
24
|
+
content: 'Button',
|
|
25
|
+
onClick: action('onClick'),
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const Emoji = Template.bind({});
|
|
29
|
+
Emoji.args = {
|
|
30
|
+
content: '😀 😎 👍 💯',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const WithScenario = () => ({
|
|
34
|
+
tags: [{ content: MyButtonRaw, boundAs: 'MyButton' }],
|
|
35
|
+
template: '<MyButton>With scenario</MyButton>',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const TextWithAction = () =>
|
|
39
|
+
mount('my-button', {
|
|
40
|
+
content: 'Trigger Action',
|
|
41
|
+
onClick: () => action('This was clicked')(),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
TextWithAction.storyName = 'With an action';
|
|
45
|
+
|
|
46
|
+
export const ButtonWithLinkToAnotherStory = () =>
|
|
47
|
+
mount('my-button', {
|
|
48
|
+
content: 'Go to Welcome Story',
|
|
49
|
+
onClick: linkTo('example-introduction--page'),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
ButtonWithLinkToAnotherStory.storyName = 'button with link to another story';
|