@storybook/cli 7.0.0-alpha.46 → 7.0.0-alpha.47
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/generate.js +99 -99
- package/dist/generate.mjs +107 -107
- package/package.json +10 -10
- package/rendererAssets/angular/Button.stories.ts +0 -43
- package/rendererAssets/angular/Header.stories.ts +0 -35
- package/rendererAssets/angular/Page.stories.ts +0 -37
- package/rendererAssets/angular/User.ts +0 -2
- package/rendererAssets/angular/button.component.ts +0 -53
- package/rendererAssets/angular/header.component.ts +0 -75
- package/rendererAssets/angular/page.component.ts +0 -77
- package/rendererAssets/aurelia/1-Button.stories.ts +0 -49
- package/rendererAssets/aurelia/button.ts +0 -28
- package/rendererAssets/ember/1-Button.stories.js +0 -57
- package/rendererAssets/html/js/Button.js +0 -21
- package/rendererAssets/html/js/Button.stories.js +0 -48
- package/rendererAssets/html/js/Header.js +0 -47
- package/rendererAssets/html/js/Header.stories.js +0 -27
- package/rendererAssets/html/js/Page.js +0 -94
- package/rendererAssets/html/js/Page.stories.js +0 -23
- package/rendererAssets/html/ts/Button.stories.ts +0 -50
- package/rendererAssets/html/ts/Button.ts +0 -51
- package/rendererAssets/html/ts/Header.stories.ts +0 -27
- package/rendererAssets/html/ts/Header.ts +0 -54
- package/rendererAssets/html/ts/Page.stories.ts +0 -24
- package/rendererAssets/html/ts/Page.ts +0 -98
- package/rendererAssets/marionette/index.stories.js +0 -20
- package/rendererAssets/marko/1-Button.stories.js +0 -24
- package/rendererAssets/marko/Button.marko +0 -13
- package/rendererAssets/mithril/Button.js +0 -22
- package/rendererAssets/mithril/Button.stories.js +0 -43
- package/rendererAssets/mithril/Header.js +0 -51
- package/rendererAssets/mithril/Header.stories.js +0 -20
- package/rendererAssets/mithril/Page.js +0 -70
- package/rendererAssets/mithril/Page.stories.js +0 -24
- package/rendererAssets/nextjs/js/Button.jsx +0 -54
- package/rendererAssets/nextjs/js/Button.stories.jsx +0 -40
- package/rendererAssets/nextjs/js/Header.jsx +0 -57
- package/rendererAssets/nextjs/js/Header.stories.jsx +0 -24
- package/rendererAssets/nextjs/js/Introduction.stories.mdx +0 -228
- package/rendererAssets/nextjs/js/Page.jsx +0 -69
- package/rendererAssets/nextjs/js/Page.stories.jsx +0 -25
- package/rendererAssets/nextjs/ts/Button.stories.tsx +0 -41
- package/rendererAssets/nextjs/ts/Button.tsx +0 -52
- package/rendererAssets/nextjs/ts/Header.stories.tsx +0 -25
- package/rendererAssets/nextjs/ts/Header.tsx +0 -56
- package/rendererAssets/nextjs/ts/Introduction.stories.mdx +0 -228
- package/rendererAssets/nextjs/ts/Page.stories.tsx +0 -26
- package/rendererAssets/nextjs/ts/Page.tsx +0 -73
- package/rendererAssets/preact/Button.jsx +0 -49
- package/rendererAssets/preact/Button.stories.jsx +0 -39
- package/rendererAssets/preact/Header.jsx +0 -56
- package/rendererAssets/preact/Header.stories.jsx +0 -27
- package/rendererAssets/preact/Page.jsx +0 -69
- package/rendererAssets/preact/Page.stories.jsx +0 -24
- package/rendererAssets/rax/Button.js +0 -26
- package/rendererAssets/rax/Button.stories.js +0 -40
- package/rendererAssets/rax/Header.js +0 -44
- package/rendererAssets/rax/Header.stories.js +0 -17
- package/rendererAssets/rax/Page.js +0 -64
- package/rendererAssets/rax/Page.stories.js +0 -21
- package/rendererAssets/react/js/Button.jsx +0 -50
- package/rendererAssets/react/js/Button.stories.jsx +0 -40
- package/rendererAssets/react/js/Header.jsx +0 -57
- package/rendererAssets/react/js/Header.stories.jsx +0 -24
- package/rendererAssets/react/js/Page.jsx +0 -69
- package/rendererAssets/react/js/Page.stories.jsx +0 -25
- package/rendererAssets/react/ts/Button.stories.tsx +0 -41
- package/rendererAssets/react/ts/Button.tsx +0 -48
- package/rendererAssets/react/ts/Header.stories.tsx +0 -25
- package/rendererAssets/react/ts/Header.tsx +0 -56
- package/rendererAssets/react/ts/Page.stories.tsx +0 -26
- package/rendererAssets/react/ts/Page.tsx +0 -73
- package/rendererAssets/riot/1-Button.stories.js +0 -52
- package/rendererAssets/riot/MyButton.tag +0 -24
- package/rendererAssets/server/button.stories.json +0 -32
- package/rendererAssets/server/header.stories.json +0 -15
- package/rendererAssets/server/page.stories.json +0 -15
- package/rendererAssets/svelte/Button.stories.js +0 -51
- package/rendererAssets/svelte/Button.svelte +0 -43
- package/rendererAssets/svelte/Header.stories.js +0 -35
- package/rendererAssets/svelte/Header.svelte +0 -51
- package/rendererAssets/svelte/Page.stories.js +0 -27
- package/rendererAssets/svelte/Page.svelte +0 -63
- package/rendererAssets/vue/Button.stories.js +0 -46
- package/rendererAssets/vue/Button.vue +0 -54
- package/rendererAssets/vue/Header.stories.js +0 -27
- package/rendererAssets/vue/Header.vue +0 -51
- package/rendererAssets/vue/Page.stories.js +0 -27
- package/rendererAssets/vue/Page.vue +0 -88
- package/rendererAssets/vue3/Button.stories.js +0 -52
- package/rendererAssets/vue3/Button.vue +0 -52
- package/rendererAssets/vue3/Header.stories.js +0 -34
- package/rendererAssets/vue3/Header.vue +0 -41
- package/rendererAssets/vue3/Page.stories.js +0 -29
- package/rendererAssets/vue3/Page.vue +0 -88
- package/rendererAssets/web-components/js/Button.js +0 -21
- package/rendererAssets/web-components/js/Button.stories.js +0 -42
- package/rendererAssets/web-components/js/Header.js +0 -45
- package/rendererAssets/web-components/js/Header.stories.js +0 -15
- package/rendererAssets/web-components/js/Page.js +0 -61
- package/rendererAssets/web-components/js/Page.stories.js +0 -19
- package/rendererAssets/web-components/ts/Button.stories.ts +0 -44
- package/rendererAssets/web-components/ts/Button.ts +0 -43
- package/rendererAssets/web-components/ts/Header.stories.ts +0 -17
- package/rendererAssets/web-components/ts/Header.ts +0 -52
- package/rendererAssets/web-components/ts/Page.stories.ts +0 -21
- package/rendererAssets/web-components/ts/Page.ts +0 -68
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import './page.css';
|
|
2
|
-
import { createHeader } from './Header';
|
|
3
|
-
|
|
4
|
-
export const createPage = () => {
|
|
5
|
-
const article = document.createElement('article');
|
|
6
|
-
let user = null;
|
|
7
|
-
let header = null;
|
|
8
|
-
|
|
9
|
-
const rerenderHeader = () => {
|
|
10
|
-
const wrapper = document.getElementsByTagName('article')[0];
|
|
11
|
-
wrapper.replaceChild(createHeaderElement(), wrapper.firstChild);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const onLogin = () => {
|
|
15
|
-
user = { name: 'Jane Doe' };
|
|
16
|
-
rerenderHeader();
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const onLogout = () => {
|
|
20
|
-
user = null;
|
|
21
|
-
rerenderHeader();
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const onCreateAccount = () => {
|
|
25
|
-
user = { name: 'Jane Doe' };
|
|
26
|
-
rerenderHeader();
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const createHeaderElement = () => {
|
|
30
|
-
return createHeader({ onLogin, onLogout, onCreateAccount, user });
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
header = createHeaderElement();
|
|
34
|
-
article.appendChild(header);
|
|
35
|
-
|
|
36
|
-
const section = `
|
|
37
|
-
<section>
|
|
38
|
-
<h2>Pages in Storybook</h2>
|
|
39
|
-
<p>
|
|
40
|
-
We recommend building UIs with a
|
|
41
|
-
<a
|
|
42
|
-
href="https://blog.hichroma.com/component-driven-development-ce1109d56c8e"
|
|
43
|
-
target="_blank"
|
|
44
|
-
rel="noopener noreferrer">
|
|
45
|
-
<strong>component-driven</strong>
|
|
46
|
-
</a>
|
|
47
|
-
process starting with atomic components and ending with pages.
|
|
48
|
-
</p>
|
|
49
|
-
<p>
|
|
50
|
-
Render pages with mock data. This makes it easy to build and review page states without
|
|
51
|
-
needing to navigate to them in your app. Here are some handy patterns for managing page data
|
|
52
|
-
in Storybook:
|
|
53
|
-
</p>
|
|
54
|
-
<ul>
|
|
55
|
-
<li>
|
|
56
|
-
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
57
|
-
"args" of child component stories
|
|
58
|
-
</li>
|
|
59
|
-
<li>
|
|
60
|
-
Assemble data in the page component from your services. You can mock these services out
|
|
61
|
-
using Storybook.
|
|
62
|
-
</li>
|
|
63
|
-
</ul>
|
|
64
|
-
<p>
|
|
65
|
-
Get a guided tutorial on component-driven development at
|
|
66
|
-
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
|
|
67
|
-
Storybook tutorials
|
|
68
|
-
</a>
|
|
69
|
-
. Read more in the
|
|
70
|
-
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">docs</a>
|
|
71
|
-
.
|
|
72
|
-
</p>
|
|
73
|
-
<div class="tip-wrapper">
|
|
74
|
-
<span class="tip">Tip</span>
|
|
75
|
-
Adjust the width of the canvas with the
|
|
76
|
-
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
|
77
|
-
<g fill="none" fillRule="evenodd">
|
|
78
|
-
<path
|
|
79
|
-
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0
|
|
80
|
-
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
|
|
81
|
-
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"
|
|
82
|
-
id="a"
|
|
83
|
-
fill="#999" />
|
|
84
|
-
</g>
|
|
85
|
-
</svg>
|
|
86
|
-
Viewports addon in the toolbar
|
|
87
|
-
</div>
|
|
88
|
-
</section>
|
|
89
|
-
`;
|
|
90
|
-
|
|
91
|
-
article.insertAdjacentHTML('beforeend', section);
|
|
92
|
-
|
|
93
|
-
return article;
|
|
94
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { within, userEvent } from '@storybook/testing-library';
|
|
2
|
-
import { createPage } from './Page';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
5
|
-
title: 'Example/Page',
|
|
6
|
-
parameters: {
|
|
7
|
-
// More on Story layout: https://storybook.js.org/docs/html/configure/story-layout
|
|
8
|
-
layout: 'fullscreen',
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const Template = () => createPage();
|
|
13
|
-
|
|
14
|
-
export const LoggedOut = Template.bind({});
|
|
15
|
-
|
|
16
|
-
export const LoggedIn = Template.bind({});
|
|
17
|
-
|
|
18
|
-
// More on interaction testing: https://storybook.js.org/docs/html/writing-tests/interaction-testing
|
|
19
|
-
LoggedIn.play = async ({ canvasElement }) => {
|
|
20
|
-
const canvas = within(canvasElement);
|
|
21
|
-
const loginButton = await canvas.getByRole('button', { name: /Log in/i });
|
|
22
|
-
await userEvent.click(loginButton);
|
|
23
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryFn } from '@storybook/html';
|
|
2
|
-
import type { ButtonProps } from './Button';
|
|
3
|
-
import { createButton } from './Button';
|
|
4
|
-
|
|
5
|
-
// More on default export: https://storybook.js.org/docs/html/writing-stories/introduction#default-export
|
|
6
|
-
export default {
|
|
7
|
-
title: 'Example/Button',
|
|
8
|
-
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
|
9
|
-
argTypes: {
|
|
10
|
-
backgroundColor: { control: 'color' },
|
|
11
|
-
label: { control: 'text' },
|
|
12
|
-
onClick: { action: 'onClick' },
|
|
13
|
-
primary: { control: 'boolean' },
|
|
14
|
-
size: {
|
|
15
|
-
control: { type: 'select' },
|
|
16
|
-
options: ['small', 'medium', 'large'],
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
} as Meta<ButtonProps>;
|
|
20
|
-
|
|
21
|
-
// More on component templates: https://storybook.js.org/docs/html/writing-stories/introduction#using-args
|
|
22
|
-
const Template: StoryFn<ButtonProps> = (args) => {
|
|
23
|
-
// You can either use a function to create DOM elements or use a plain html string!
|
|
24
|
-
// return `<div>${label}</div>`;
|
|
25
|
-
return createButton(args);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const Primary = Template.bind({});
|
|
29
|
-
// More on args: https://storybook.js.org/docs/html/writing-stories/args
|
|
30
|
-
Primary.args = {
|
|
31
|
-
primary: true,
|
|
32
|
-
label: 'Button',
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const Secondary = Template.bind({});
|
|
36
|
-
Secondary.args = {
|
|
37
|
-
label: 'Button',
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const Large = Template.bind({});
|
|
41
|
-
Large.args = {
|
|
42
|
-
size: 'large',
|
|
43
|
-
label: 'Button',
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const Small = Template.bind({});
|
|
47
|
-
Small.args = {
|
|
48
|
-
size: 'small',
|
|
49
|
-
label: 'Button',
|
|
50
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import './button.css';
|
|
2
|
-
|
|
3
|
-
export interface ButtonProps {
|
|
4
|
-
/**
|
|
5
|
-
* Is this the principal call to action on the page?
|
|
6
|
-
*/
|
|
7
|
-
primary?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* What background color to use
|
|
10
|
-
*/
|
|
11
|
-
backgroundColor?: string;
|
|
12
|
-
/**
|
|
13
|
-
* How large should the button be?
|
|
14
|
-
*/
|
|
15
|
-
size?: 'small' | 'medium' | 'large';
|
|
16
|
-
/**
|
|
17
|
-
* Button contents
|
|
18
|
-
*/
|
|
19
|
-
label: string;
|
|
20
|
-
/**
|
|
21
|
-
* Optional click handler
|
|
22
|
-
*/
|
|
23
|
-
onClick?: () => void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Primary UI component for user interaction
|
|
28
|
-
*/
|
|
29
|
-
export const createButton = ({
|
|
30
|
-
primary = false,
|
|
31
|
-
size = 'medium',
|
|
32
|
-
backgroundColor,
|
|
33
|
-
label,
|
|
34
|
-
onClick,
|
|
35
|
-
}: ButtonProps) => {
|
|
36
|
-
const btn = document.createElement('button');
|
|
37
|
-
btn.type = 'button';
|
|
38
|
-
btn.innerText = label;
|
|
39
|
-
if (onClick) {
|
|
40
|
-
btn.addEventListener('click', onClick);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
44
|
-
btn.className = ['storybook-button', `storybook-button--${size}`, mode].join(' ');
|
|
45
|
-
|
|
46
|
-
if (backgroundColor) {
|
|
47
|
-
btn.style.backgroundColor = backgroundColor;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return btn;
|
|
51
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryFn } from '@storybook/html';
|
|
2
|
-
import type { HeaderProps } from './Header';
|
|
3
|
-
import { createHeader } from './Header';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: 'Example/Header',
|
|
7
|
-
parameters: {
|
|
8
|
-
// More on Story layout: https://storybook.js.org/docs/html/configure/story-layout
|
|
9
|
-
layout: 'fullscreen',
|
|
10
|
-
},
|
|
11
|
-
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
|
12
|
-
argTypes: {
|
|
13
|
-
onLogin: { action: 'onLogin' },
|
|
14
|
-
onLogout: { action: 'onLogout' },
|
|
15
|
-
onCreateAccount: { action: 'onCreateAccount' },
|
|
16
|
-
},
|
|
17
|
-
} as Meta<HeaderProps>;
|
|
18
|
-
|
|
19
|
-
const Template: StoryFn<HeaderProps> = (args) => createHeader(args);
|
|
20
|
-
|
|
21
|
-
export const LoggedIn = Template.bind({});
|
|
22
|
-
LoggedIn.args = {
|
|
23
|
-
user: {},
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const LoggedOut = Template.bind({});
|
|
27
|
-
LoggedOut.args = {};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import './header.css';
|
|
2
|
-
import { createButton } from './Button';
|
|
3
|
-
|
|
4
|
-
export interface HeaderProps {
|
|
5
|
-
user?: { name: string };
|
|
6
|
-
onLogin: () => void;
|
|
7
|
-
onLogout: () => void;
|
|
8
|
-
onCreateAccount: () => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const createHeader = ({ user, onLogout, onLogin, onCreateAccount }: HeaderProps) => {
|
|
12
|
-
const header = document.createElement('header');
|
|
13
|
-
|
|
14
|
-
const wrapper = document.createElement('div');
|
|
15
|
-
wrapper.className = 'wrapper';
|
|
16
|
-
|
|
17
|
-
const logo = `<div>
|
|
18
|
-
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
|
19
|
-
<g fill="none" fillRule="evenodd">
|
|
20
|
-
<path
|
|
21
|
-
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
|
22
|
-
fill="#FFF" />
|
|
23
|
-
<path
|
|
24
|
-
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
|
|
25
|
-
fill="#555AB9" />
|
|
26
|
-
<path d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" fill="#91BAF8" />
|
|
27
|
-
</g>
|
|
28
|
-
</svg>
|
|
29
|
-
<h1>Acme</h1>
|
|
30
|
-
</div>`;
|
|
31
|
-
|
|
32
|
-
wrapper.insertAdjacentHTML('afterbegin', logo);
|
|
33
|
-
|
|
34
|
-
const account = document.createElement('div');
|
|
35
|
-
if (user) {
|
|
36
|
-
const welcomeMessage = `<span class="welcome">Welcome, <b>${user.name}</b>!</span>`;
|
|
37
|
-
account.innerHTML = welcomeMessage;
|
|
38
|
-
account.appendChild(createButton({ size: 'small', label: 'Log out', onClick: onLogout }));
|
|
39
|
-
} else {
|
|
40
|
-
account.appendChild(createButton({ size: 'small', label: 'Log in', onClick: onLogin }));
|
|
41
|
-
account.appendChild(
|
|
42
|
-
createButton({
|
|
43
|
-
size: 'small',
|
|
44
|
-
label: 'Sign up',
|
|
45
|
-
onClick: onCreateAccount,
|
|
46
|
-
primary: true,
|
|
47
|
-
})
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
wrapper.appendChild(account);
|
|
51
|
-
header.appendChild(wrapper);
|
|
52
|
-
|
|
53
|
-
return header;
|
|
54
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { within, userEvent } from '@storybook/testing-library';
|
|
2
|
-
import type { Meta, StoryFn } from '@storybook/html';
|
|
3
|
-
import { createPage } from './Page';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: 'Example/Page',
|
|
7
|
-
parameters: {
|
|
8
|
-
// More on Story layout: https://storybook.js.org/docs/html/configure/story-layout
|
|
9
|
-
layout: 'fullscreen',
|
|
10
|
-
},
|
|
11
|
-
} as Meta;
|
|
12
|
-
|
|
13
|
-
const Template: StoryFn = () => createPage();
|
|
14
|
-
|
|
15
|
-
export const LoggedOut = Template.bind({});
|
|
16
|
-
|
|
17
|
-
export const LoggedIn = Template.bind({});
|
|
18
|
-
|
|
19
|
-
// More on interaction testing: https://storybook.js.org/docs/html/writing-tests/interaction-testing
|
|
20
|
-
LoggedIn.play = async ({ canvasElement }) => {
|
|
21
|
-
const canvas = within(canvasElement);
|
|
22
|
-
const loginButton = await canvas.getByRole('button', { name: /Log in/i });
|
|
23
|
-
await userEvent.click(loginButton);
|
|
24
|
-
};
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import './page.css';
|
|
2
|
-
import { createHeader } from './Header';
|
|
3
|
-
|
|
4
|
-
type User = {
|
|
5
|
-
name: string;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export const createPage = () => {
|
|
9
|
-
const article = document.createElement('article');
|
|
10
|
-
let user: User | undefined;
|
|
11
|
-
let header: HTMLElement | null = null;
|
|
12
|
-
|
|
13
|
-
const rerenderHeader = () => {
|
|
14
|
-
const wrapper = document.getElementsByTagName('article')[0];
|
|
15
|
-
wrapper.replaceChild(createHeaderElement(), wrapper.firstChild as HTMLElement);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const onLogin = () => {
|
|
19
|
-
user = { name: 'Jane Doe' };
|
|
20
|
-
rerenderHeader();
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const onLogout = () => {
|
|
24
|
-
user = undefined;
|
|
25
|
-
rerenderHeader();
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const onCreateAccount = () => {
|
|
29
|
-
user = { name: 'Jane Doe' };
|
|
30
|
-
rerenderHeader();
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const createHeaderElement = () => {
|
|
34
|
-
return createHeader({ onLogin, onLogout, onCreateAccount, user });
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
header = createHeaderElement();
|
|
38
|
-
article.appendChild(header);
|
|
39
|
-
|
|
40
|
-
const section = `
|
|
41
|
-
<section>
|
|
42
|
-
<h2>Pages in Storybook</h2>
|
|
43
|
-
<p>
|
|
44
|
-
We recommend building UIs with a
|
|
45
|
-
<a
|
|
46
|
-
href="https://blog.hichroma.com/component-driven-development-ce1109d56c8e"
|
|
47
|
-
target="_blank"
|
|
48
|
-
rel="noopener noreferrer">
|
|
49
|
-
<strong>component-driven</strong>
|
|
50
|
-
</a>
|
|
51
|
-
process starting with atomic components and ending with pages.
|
|
52
|
-
</p>
|
|
53
|
-
<p>
|
|
54
|
-
Render pages with mock data. This makes it easy to build and review page states without
|
|
55
|
-
needing to navigate to them in your app. Here are some handy patterns for managing page data
|
|
56
|
-
in Storybook:
|
|
57
|
-
</p>
|
|
58
|
-
<ul>
|
|
59
|
-
<li>
|
|
60
|
-
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
61
|
-
"args" of child component stories
|
|
62
|
-
</li>
|
|
63
|
-
<li>
|
|
64
|
-
Assemble data in the page component from your services. You can mock these services out
|
|
65
|
-
using Storybook.
|
|
66
|
-
</li>
|
|
67
|
-
</ul>
|
|
68
|
-
<p>
|
|
69
|
-
Get a guided tutorial on component-driven development at
|
|
70
|
-
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
|
|
71
|
-
Storybook tutorials
|
|
72
|
-
</a>
|
|
73
|
-
. Read more in the
|
|
74
|
-
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">docs</a>
|
|
75
|
-
.
|
|
76
|
-
</p>
|
|
77
|
-
<div class="tip-wrapper">
|
|
78
|
-
<span class="tip">Tip</span>
|
|
79
|
-
Adjust the width of the canvas with the
|
|
80
|
-
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
|
81
|
-
<g fill="none" fillRule="evenodd">
|
|
82
|
-
<path
|
|
83
|
-
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0
|
|
84
|
-
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
|
|
85
|
-
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"
|
|
86
|
-
id="a"
|
|
87
|
-
fill="#999" />
|
|
88
|
-
</g>
|
|
89
|
-
</svg>
|
|
90
|
-
Viewports addon in the toolbar
|
|
91
|
-
</div>
|
|
92
|
-
</section>
|
|
93
|
-
`;
|
|
94
|
-
|
|
95
|
-
article.insertAdjacentHTML('beforeend', section);
|
|
96
|
-
|
|
97
|
-
return article;
|
|
98
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { View } from 'backbone.marionette';
|
|
2
|
-
|
|
3
|
-
import { storiesOf } from '@storybook/marionette';
|
|
4
|
-
|
|
5
|
-
storiesOf('Demo', module).add(
|
|
6
|
-
'button',
|
|
7
|
-
() =>
|
|
8
|
-
new View({
|
|
9
|
-
template: () => '<button id="my_button">some button</button>',
|
|
10
|
-
ui: {
|
|
11
|
-
button: '#my_button',
|
|
12
|
-
},
|
|
13
|
-
triggers: {
|
|
14
|
-
'click @ui.button': 'click',
|
|
15
|
-
},
|
|
16
|
-
onClick() {
|
|
17
|
-
console.log('button clicked');
|
|
18
|
-
},
|
|
19
|
-
})
|
|
20
|
-
);
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { action } from '@storybook/addon-actions';
|
|
2
|
-
import Button from './Button.marko';
|
|
3
|
-
|
|
4
|
-
// More on default export: https://storybook.js.org/docs/marko/writing-stories/introduction#default-export
|
|
5
|
-
export default {
|
|
6
|
-
title: 'Button',
|
|
7
|
-
// More on argTypes: https://storybook.js.org/docs/marko/api/argtypes
|
|
8
|
-
argTypes: {
|
|
9
|
-
label: { control: 'text' },
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// More on component templates: https://storybook.js.org/docs/marko/writing-stories/introduction#using-args
|
|
14
|
-
const Template = (args) => ({
|
|
15
|
-
component: Button,
|
|
16
|
-
input: args,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
export const Text = Template.bind({});
|
|
20
|
-
// More on args: https://storybook.js.org/docs/marko/writing-stories/args
|
|
21
|
-
Text.args = {
|
|
22
|
-
label: 'Button',
|
|
23
|
-
onClick: action('onClick'),
|
|
24
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/** @jsx m */
|
|
2
|
-
|
|
3
|
-
import m from 'mithril';
|
|
4
|
-
import './button.css';
|
|
5
|
-
|
|
6
|
-
export const Button = {
|
|
7
|
-
view: ({ label, attrs }) => {
|
|
8
|
-
const mode = attrs.primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
9
|
-
const size = attrs.size || 'medium';
|
|
10
|
-
|
|
11
|
-
return (
|
|
12
|
-
<button
|
|
13
|
-
type="button"
|
|
14
|
-
class={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
|
|
15
|
-
style={attrs.backgroundColor && { backgroundColor: attrs.backgroundColor }}
|
|
16
|
-
onclick={attrs.onClick}
|
|
17
|
-
>
|
|
18
|
-
{label}
|
|
19
|
-
</button>
|
|
20
|
-
);
|
|
21
|
-
},
|
|
22
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import m from 'mithril';
|
|
2
|
-
|
|
3
|
-
import { Button } from './Button';
|
|
4
|
-
|
|
5
|
-
// More on default export: https://storybook.js.org/docs/mithril/writing-stories/introduction#default-export
|
|
6
|
-
export default {
|
|
7
|
-
title: 'Example/Button',
|
|
8
|
-
component: Button,
|
|
9
|
-
// More on argTypes: https://storybook.js.org/docs/mithril/api/argtypes
|
|
10
|
-
argTypes: {
|
|
11
|
-
backgroundColor: { control: 'color' },
|
|
12
|
-
onClick: { action: 'onClick' },
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// More on component templates: https://storybook.js.org/docs/mithril/writing-stories/introduction#using-args
|
|
17
|
-
const Template = ({ label, ...args }) => ({
|
|
18
|
-
view: () => m(Button, args, label),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export const Primary = Template.bind({});
|
|
22
|
-
// More on args: https://storybook.js.org/docs/mithril/writing-stories/args
|
|
23
|
-
Primary.args = {
|
|
24
|
-
primary: true,
|
|
25
|
-
label: 'Button',
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const Secondary = Template.bind({});
|
|
29
|
-
Secondary.args = {
|
|
30
|
-
label: 'Button',
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const Large = Template.bind({});
|
|
34
|
-
Large.args = {
|
|
35
|
-
size: 'large',
|
|
36
|
-
label: 'Button',
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const Small = Template.bind({});
|
|
40
|
-
Small.args = {
|
|
41
|
-
size: 'small',
|
|
42
|
-
label: 'Button',
|
|
43
|
-
};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/** @jsx m */
|
|
2
|
-
|
|
3
|
-
import m from 'mithril';
|
|
4
|
-
|
|
5
|
-
import { Button } from './Button';
|
|
6
|
-
import './header.css';
|
|
7
|
-
|
|
8
|
-
export const Header = {
|
|
9
|
-
view: ({ attrs }) => (
|
|
10
|
-
<header>
|
|
11
|
-
<div class="wrapper">
|
|
12
|
-
<div>
|
|
13
|
-
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
|
14
|
-
<g fill="none" fillRule="evenodd">
|
|
15
|
-
<path
|
|
16
|
-
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
|
17
|
-
fill="#FFF"
|
|
18
|
-
/>
|
|
19
|
-
<path
|
|
20
|
-
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
|
|
21
|
-
fill="#555AB9"
|
|
22
|
-
/>
|
|
23
|
-
<path
|
|
24
|
-
d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
|
|
25
|
-
fill="#91BAF8"
|
|
26
|
-
/>
|
|
27
|
-
</g>
|
|
28
|
-
</svg>
|
|
29
|
-
<h1>Acme</h1>
|
|
30
|
-
</div>
|
|
31
|
-
{m(
|
|
32
|
-
'div',
|
|
33
|
-
...(attrs.user
|
|
34
|
-
? [m(Button, { size: 'small', onClick: attrs.onLogout }, 'Log out')]
|
|
35
|
-
: [
|
|
36
|
-
m(Button, { size: 'small', onClick: attrs.onLogin }, 'Log in'),
|
|
37
|
-
m(
|
|
38
|
-
Button,
|
|
39
|
-
{
|
|
40
|
-
primary: true,
|
|
41
|
-
size: 'small',
|
|
42
|
-
onClick: attrs.onCreateAccount,
|
|
43
|
-
},
|
|
44
|
-
'Sign up'
|
|
45
|
-
),
|
|
46
|
-
])
|
|
47
|
-
)}
|
|
48
|
-
</div>
|
|
49
|
-
</header>
|
|
50
|
-
),
|
|
51
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import m from 'mithril';
|
|
2
|
-
|
|
3
|
-
import { Header } from './Header';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
title: 'Example/Header',
|
|
7
|
-
component: Header,
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
const Template = ({ label, ...args }) => ({
|
|
11
|
-
view: () => m(Header, args, label),
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export const LoggedIn = Template.bind({});
|
|
15
|
-
LoggedIn.args = {
|
|
16
|
-
user: {},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const LoggedOut = Template.bind({});
|
|
20
|
-
LoggedOut.args = {};
|