@storybook/html 7.0.0-rc.4 → 7.0.0-rc.6

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/html",
3
- "version": "7.0.0-rc.4",
3
+ "version": "7.0.0-rc.6",
4
4
  "description": "Storybook HTML renderer",
5
5
  "keywords": [
6
6
  "storybook"
@@ -48,11 +48,11 @@
48
48
  "prep": "../../../scripts/prepare/bundle.ts"
49
49
  },
50
50
  "dependencies": {
51
- "@storybook/core-client": "7.0.0-rc.4",
52
- "@storybook/docs-tools": "7.0.0-rc.4",
51
+ "@storybook/core-client": "7.0.0-rc.6",
52
+ "@storybook/docs-tools": "7.0.0-rc.6",
53
53
  "@storybook/global": "^5.0.0",
54
- "@storybook/preview-api": "7.0.0-rc.4",
55
- "@storybook/types": "7.0.0-rc.4",
54
+ "@storybook/preview-api": "7.0.0-rc.6",
55
+ "@storybook/types": "7.0.0-rc.6",
56
56
  "ts-dedent": "^2.0.0"
57
57
  },
58
58
  "devDependencies": {
@@ -74,5 +74,5 @@
74
74
  ],
75
75
  "platform": "browser"
76
76
  },
77
- "gitHead": "6fb713a2ca980fa241f82a076579889fcdf47ecc"
77
+ "gitHead": "1467fa1d714cbf43d5d87f9233c6dd42e20da787"
78
78
  }
@@ -25,7 +25,7 @@ type Story = StoryObj<HeaderProps>;
25
25
  export const LoggedIn: Story = {
26
26
  args: {
27
27
  user: {
28
- name: 'John Doe',
28
+ name: 'Jane Doe',
29
29
  },
30
30
  },
31
31
  };
@@ -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 = {
7
+ title: 'Example/Button',
8
+ tags: ['autodocs'],
9
+ render: (args) => {
10
+ // You can either use a function to create DOM elements or use a plain html string!
11
+ // return `<div>${label}</div>`;
12
+ return createButton(args);
13
+ },
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
+ } satisfies Meta<ButtonProps>;
25
+
26
+ export default meta;
27
+ type Story = StoryObj<ButtonProps>;
28
+
29
+ // More on writing stories with args: https://storybook.js.org/docs/7.0/html/writing-stories/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,33 @@
1
+ import type { Meta, StoryObj } from '@storybook/html';
2
+ import type { HeaderProps } from './Header';
3
+ import { createHeader } from './Header';
4
+
5
+ const meta = {
6
+ title: 'Example/Header',
7
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/7.0/html/writing-docs/docs-page
8
+ tags: ['autodocs'],
9
+ render: (args) => createHeader(args),
10
+ parameters: {
11
+ // More on how to position stories at: https://storybook.js.org/docs/7.0/html/configure/story-layout
12
+ layout: 'fullscreen',
13
+ },
14
+ // More on argTypes: https://storybook.js.org/docs/7.0/html/api/argtypes
15
+ argTypes: {
16
+ onLogin: { action: 'onLogin' },
17
+ onLogout: { action: 'onLogout' },
18
+ onCreateAccount: { action: 'onCreateAccount' },
19
+ },
20
+ } satisfies Meta<HeaderProps>;
21
+
22
+ export default meta;
23
+ type Story = StoryObj<HeaderProps>;
24
+
25
+ export const LoggedIn: Story = {
26
+ args: {
27
+ user: {
28
+ name: 'Jane Doe',
29
+ },
30
+ },
31
+ };
32
+
33
+ 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 = {
6
+ title: 'Example/Page',
7
+ render: () => createPage(),
8
+ parameters: {
9
+ // More on how to position stories at: https://storybook.js.org/docs/7.0/html/configure/story-layout
10
+ layout: 'fullscreen',
11
+ },
12
+ } satisfies Meta;
13
+
14
+ export default meta;
15
+
16
+ export const LoggedOut: StoryObj = {};
17
+
18
+ // More on interaction testing: https://storybook.js.org/docs/7.0/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
+ };
File without changes
File without changes
File without changes
File without changes
File without changes