@storybook/html 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/package.json +9 -8
- package/template/cli/.eslintrc.json +6 -0
- package/template/cli/js/Button.js +21 -0
- package/template/cli/js/Button.stories.js +50 -0
- package/template/cli/js/Header.js +47 -0
- package/template/cli/js/Header.stories.js +26 -0
- package/template/cli/js/Page.js +94 -0
- package/template/cli/js/Page.stories.js +24 -0
- package/template/cli/ts/Button.stories.ts +55 -0
- package/template/cli/ts/Button.ts +51 -0
- package/template/cli/ts/Header.stories.ts +31 -0
- package/template/cli/ts/Header.ts +54 -0
- package/template/cli/ts/Page.stories.ts +27 -0
- package/template/cli/ts/Page.ts +98 -0
- package/template/components/Button.js +9 -0
- package/template/components/Form.js +32 -0
- package/template/components/Html.js +1 -0
- package/template/components/Pre.js +15 -0
- package/template/components/index.js +9 -0
- package/template/stories/README.md +1 -0
- package/template/stories/html-mdx.stories.mdx +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/html",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.47",
|
|
4
4
|
"description": "Storybook HTML renderer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"types": "dist/index.d.ts",
|
|
42
42
|
"files": [
|
|
43
43
|
"dist/**/*",
|
|
44
|
+
"template/**/*",
|
|
44
45
|
"README.md",
|
|
45
46
|
"*.js",
|
|
46
47
|
"*.d.ts"
|
|
@@ -50,12 +51,12 @@
|
|
|
50
51
|
"prep": "../../../scripts/prepare/bundle.ts"
|
|
51
52
|
},
|
|
52
53
|
"dependencies": {
|
|
53
|
-
"@storybook/addons": "7.0.0-alpha.
|
|
54
|
-
"@storybook/core-client": "7.0.0-alpha.
|
|
55
|
-
"@storybook/docs-tools": "7.0.0-alpha.
|
|
56
|
-
"@storybook/preview-web": "7.0.0-alpha.
|
|
57
|
-
"@storybook/store": "7.0.0-alpha.
|
|
58
|
-
"@storybook/types": "7.0.0-alpha.
|
|
54
|
+
"@storybook/addons": "7.0.0-alpha.47",
|
|
55
|
+
"@storybook/core-client": "7.0.0-alpha.47",
|
|
56
|
+
"@storybook/docs-tools": "7.0.0-alpha.47",
|
|
57
|
+
"@storybook/preview-web": "7.0.0-alpha.47",
|
|
58
|
+
"@storybook/store": "7.0.0-alpha.47",
|
|
59
|
+
"@storybook/types": "7.0.0-alpha.47",
|
|
59
60
|
"global": "^4.4.0",
|
|
60
61
|
"react": "16.14.0",
|
|
61
62
|
"react-dom": "16.14.0",
|
|
@@ -80,5 +81,5 @@
|
|
|
80
81
|
],
|
|
81
82
|
"platform": "browser"
|
|
82
83
|
},
|
|
83
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "1c706a4a778831e012343c905f86225fa71491a7"
|
|
84
85
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import './button.css';
|
|
2
|
+
|
|
3
|
+
export const createButton = ({
|
|
4
|
+
primary = false,
|
|
5
|
+
size = 'medium',
|
|
6
|
+
backgroundColor,
|
|
7
|
+
label,
|
|
8
|
+
onClick,
|
|
9
|
+
}) => {
|
|
10
|
+
const btn = document.createElement('button');
|
|
11
|
+
btn.type = 'button';
|
|
12
|
+
btn.innerText = label;
|
|
13
|
+
btn.addEventListener('click', onClick);
|
|
14
|
+
|
|
15
|
+
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
16
|
+
btn.className = ['storybook-button', `storybook-button--${size}`, mode].join(' ');
|
|
17
|
+
|
|
18
|
+
btn.style.backgroundColor = backgroundColor;
|
|
19
|
+
|
|
20
|
+
return btn;
|
|
21
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createButton } from './Button';
|
|
2
|
+
|
|
3
|
+
// More on default export: https://storybook.js.org/docs/html/writing-stories/introduction#default-export
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Example/Button',
|
|
6
|
+
// More on component templates: https://storybook.js.org/docs/html/writing-stories/introduction#using-args
|
|
7
|
+
render: ({ label, ...args }) => {
|
|
8
|
+
// You can either use a function to create DOM elements or use a plain html string!
|
|
9
|
+
// return `<div>${label}</div>`;
|
|
10
|
+
return createButton({ label, ...args });
|
|
11
|
+
},
|
|
12
|
+
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
|
13
|
+
argTypes: {
|
|
14
|
+
backgroundColor: { control: 'color' },
|
|
15
|
+
label: { control: 'text' },
|
|
16
|
+
onClick: { action: 'onClick' },
|
|
17
|
+
primary: { control: 'boolean' },
|
|
18
|
+
size: {
|
|
19
|
+
control: { type: 'select' },
|
|
20
|
+
options: ['small', 'medium', 'large'],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const Primary = {
|
|
26
|
+
args: {
|
|
27
|
+
primary: true,
|
|
28
|
+
label: 'Button',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const Secondary = {
|
|
33
|
+
args: {
|
|
34
|
+
label: 'Button',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const Large = {
|
|
39
|
+
args: {
|
|
40
|
+
size: 'large',
|
|
41
|
+
label: 'Button',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const Small = {
|
|
46
|
+
args: {
|
|
47
|
+
size: 'small',
|
|
48
|
+
label: 'Button',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import './header.css';
|
|
2
|
+
import { createButton } from './Button';
|
|
3
|
+
|
|
4
|
+
export const createHeader = ({ user, onLogout, onLogin, onCreateAccount }) => {
|
|
5
|
+
const header = document.createElement('header');
|
|
6
|
+
|
|
7
|
+
const wrapper = document.createElement('div');
|
|
8
|
+
wrapper.className = 'wrapper';
|
|
9
|
+
|
|
10
|
+
const logo = `<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
|
+
<path
|
|
17
|
+
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
|
|
18
|
+
fill="#555AB9" />
|
|
19
|
+
<path d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" fill="#91BAF8" />
|
|
20
|
+
</g>
|
|
21
|
+
</svg>
|
|
22
|
+
<h1>Acme</h1>
|
|
23
|
+
</div>`;
|
|
24
|
+
|
|
25
|
+
wrapper.insertAdjacentHTML('afterbegin', logo);
|
|
26
|
+
|
|
27
|
+
const account = document.createElement('div');
|
|
28
|
+
if (user) {
|
|
29
|
+
const welcomeMessage = `<span class="welcome">Welcome, <b>${user.name}</b>!</span>`;
|
|
30
|
+
account.innerHTML = welcomeMessage;
|
|
31
|
+
account.appendChild(createButton({ size: 'small', label: 'Log out', onClick: onLogout }));
|
|
32
|
+
} else {
|
|
33
|
+
account.appendChild(createButton({ size: 'small', label: 'Log in', onClick: onLogin }));
|
|
34
|
+
account.appendChild(
|
|
35
|
+
createButton({
|
|
36
|
+
size: 'small',
|
|
37
|
+
label: 'Sign up',
|
|
38
|
+
onClick: onCreateAccount,
|
|
39
|
+
primary: true,
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
wrapper.appendChild(account);
|
|
44
|
+
header.appendChild(wrapper);
|
|
45
|
+
|
|
46
|
+
return header;
|
|
47
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createHeader } from './Header';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
title: 'Example/Header',
|
|
5
|
+
render: (args) => createHeader(args),
|
|
6
|
+
parameters: {
|
|
7
|
+
// More on Story layout: https://storybook.js.org/docs/html/configure/story-layout
|
|
8
|
+
layout: 'fullscreen',
|
|
9
|
+
},
|
|
10
|
+
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
|
11
|
+
argTypes: {
|
|
12
|
+
onLogin: { action: 'onLogin' },
|
|
13
|
+
onLogout: { action: 'onLogout' },
|
|
14
|
+
onCreateAccount: { action: 'onCreateAccount' },
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const LoggedIn = {
|
|
19
|
+
args: {
|
|
20
|
+
user: {
|
|
21
|
+
name: 'Jane Doe',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const LoggedOut = {};
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { within, userEvent } from '@storybook/testing-library';
|
|
2
|
+
import { createPage } from './Page';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Example/Page',
|
|
6
|
+
render: () => createPage(),
|
|
7
|
+
parameters: {
|
|
8
|
+
// More on Story layout: https://storybook.js.org/docs/html/configure/story-layout
|
|
9
|
+
layout: 'fullscreen',
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const LoggedOut = {};
|
|
14
|
+
|
|
15
|
+
// More on interaction testing: https://storybook.js.org/docs/html/writing-tests/interaction-testing
|
|
16
|
+
export const LoggedIn = {
|
|
17
|
+
play: async ({ canvasElement }) => {
|
|
18
|
+
const canvas = within(canvasElement);
|
|
19
|
+
const loginButton = await canvas.getByRole('button', {
|
|
20
|
+
name: /Log in/i,
|
|
21
|
+
});
|
|
22
|
+
await userEvent.click(loginButton);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { StoryObj, Meta } from '@storybook/html';
|
|
2
|
+
import type { ButtonProps } from './Button';
|
|
3
|
+
import { createButton } from './Button';
|
|
4
|
+
|
|
5
|
+
// More on how to set up stories at: https://storybook.js.org/docs/html/writing-stories/introduction#default-export
|
|
6
|
+
const meta: Meta<ButtonProps> = {
|
|
7
|
+
title: 'Example/Button',
|
|
8
|
+
render: (args) => {
|
|
9
|
+
// You can either use a function to create DOM elements or use a plain html string!
|
|
10
|
+
// return `<div>${label}</div>`;
|
|
11
|
+
return createButton(args);
|
|
12
|
+
},
|
|
13
|
+
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
|
14
|
+
argTypes: {
|
|
15
|
+
backgroundColor: { control: 'color' },
|
|
16
|
+
label: { control: 'text' },
|
|
17
|
+
onClick: { action: 'onClick' },
|
|
18
|
+
primary: { control: 'boolean' },
|
|
19
|
+
size: {
|
|
20
|
+
control: { type: 'select' },
|
|
21
|
+
options: ['small', 'medium', 'large'],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default meta;
|
|
27
|
+
type Story = StoryObj<ButtonProps>;
|
|
28
|
+
|
|
29
|
+
// More on component templates: https://storybook.js.org/docs/html/writing-stories/introduction#using-args
|
|
30
|
+
export const Primary: Story = {
|
|
31
|
+
args: {
|
|
32
|
+
primary: true,
|
|
33
|
+
label: 'Button',
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const Secondary: Story = {
|
|
38
|
+
args: {
|
|
39
|
+
label: 'Button',
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const Large: Story = {
|
|
44
|
+
args: {
|
|
45
|
+
size: 'large',
|
|
46
|
+
label: 'Button',
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const Small: Story = {
|
|
51
|
+
args: {
|
|
52
|
+
size: 'small',
|
|
53
|
+
label: 'Button',
|
|
54
|
+
},
|
|
55
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/html';
|
|
2
|
+
import type { HeaderProps } from './Header';
|
|
3
|
+
import { createHeader } from './Header';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<HeaderProps> = {
|
|
6
|
+
title: 'Example/Header',
|
|
7
|
+
render: (args) => createHeader(args),
|
|
8
|
+
parameters: {
|
|
9
|
+
// More on Story layout: https://storybook.js.org/docs/html/configure/story-layout
|
|
10
|
+
layout: 'fullscreen',
|
|
11
|
+
},
|
|
12
|
+
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
|
13
|
+
argTypes: {
|
|
14
|
+
onLogin: { action: 'onLogin' },
|
|
15
|
+
onLogout: { action: 'onLogout' },
|
|
16
|
+
onCreateAccount: { action: 'onCreateAccount' },
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default meta;
|
|
21
|
+
type Story = StoryObj<HeaderProps>;
|
|
22
|
+
|
|
23
|
+
export const LoggedIn: Story = {
|
|
24
|
+
args: {
|
|
25
|
+
user: {
|
|
26
|
+
name: 'John Doe',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const LoggedOut: Story = {};
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/html';
|
|
2
|
+
import { within, userEvent } from '@storybook/testing-library';
|
|
3
|
+
import { createPage } from './Page';
|
|
4
|
+
|
|
5
|
+
const meta: Meta = {
|
|
6
|
+
title: 'Example/Page',
|
|
7
|
+
render: () => createPage(),
|
|
8
|
+
parameters: {
|
|
9
|
+
// More on Story layout: https://storybook.js.org/docs/html/configure/story-layout
|
|
10
|
+
layout: 'fullscreen',
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
|
|
16
|
+
export const LoggedOut: StoryObj = {};
|
|
17
|
+
|
|
18
|
+
// More on interaction testing: https://storybook.js.org/docs/html/writing-tests/interaction-testing
|
|
19
|
+
export const LoggedIn: StoryObj = {
|
|
20
|
+
play: async ({ canvasElement }) => {
|
|
21
|
+
const canvas = within(canvasElement);
|
|
22
|
+
const loginButton = await canvas.getByRole('button', {
|
|
23
|
+
name: /Log in/i,
|
|
24
|
+
});
|
|
25
|
+
await userEvent.click(loginButton);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
export const Form = ({ onSuccess }) => {
|
|
3
|
+
const container = document.createElement('div');
|
|
4
|
+
|
|
5
|
+
const getInnerHTML = ({ complete }) => `
|
|
6
|
+
<form id="interaction-test-form">
|
|
7
|
+
<label>
|
|
8
|
+
Enter Value
|
|
9
|
+
<input type="text" data-testid="value" required />
|
|
10
|
+
</label>
|
|
11
|
+
<button type="submit">Submit</button>
|
|
12
|
+
${complete ? '<p>Completed!!</p>' : ''}
|
|
13
|
+
</form>
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
container.innerHTML = getInnerHTML({ complete: false });
|
|
17
|
+
|
|
18
|
+
const form = container.querySelector('form');
|
|
19
|
+
form.addEventListener('submit', (e) => {
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
container.innerHTML = getInnerHTML({ complete: true });
|
|
24
|
+
}, 500);
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
container.innerHTML = getInnerHTML({ complete: false });
|
|
27
|
+
}, 1500);
|
|
28
|
+
onSuccess(e);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return container;
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const Html = `<div>{{content}}</div>`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
export const Pre = (args) => {
|
|
3
|
+
const pre = document.createElement('pre');
|
|
4
|
+
|
|
5
|
+
pre.setAttribute('data-testid', 'pre');
|
|
6
|
+
pre.style = args.style;
|
|
7
|
+
|
|
8
|
+
if (args.object) {
|
|
9
|
+
pre.textContent = JSON.stringify(args.object, null, 2);
|
|
10
|
+
} else {
|
|
11
|
+
pre.textContent = args.text;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return pre;
|
|
15
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import globalThis from 'global';
|
|
2
|
+
|
|
3
|
+
import { Button } from './Button';
|
|
4
|
+
import { Pre } from './Pre';
|
|
5
|
+
import { Form } from './Form';
|
|
6
|
+
import { Html } from './Html';
|
|
7
|
+
|
|
8
|
+
globalThis.Components = { Button, Pre, Form, Html };
|
|
9
|
+
globalThis.storybookRenderer = 'html';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Placeholder until we write some render-specific stories
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Meta, Story, Canvas } from '@storybook/addon-docs';
|
|
2
|
+
|
|
3
|
+
<Meta title="html/html-mdx" />
|
|
4
|
+
|
|
5
|
+
## HTML-specific MDX Stories
|
|
6
|
+
|
|
7
|
+
<Canvas>
|
|
8
|
+
<Story name="Basic" height="100px">
|
|
9
|
+
{'<h1>Hello World</h1>'}
|
|
10
|
+
</Story>
|
|
11
|
+
</Canvas>
|
|
12
|
+
|
|
13
|
+
<Canvas>
|
|
14
|
+
<Story name="Function" height="100px">
|
|
15
|
+
{() => {
|
|
16
|
+
const btn = document.createElement('button');
|
|
17
|
+
btn.innerHTML = 'Hello Button';
|
|
18
|
+
return btn;
|
|
19
|
+
}}
|
|
20
|
+
</Story>
|
|
21
|
+
</Canvas>
|