@storybook/html 9.0.0-alpha.0 → 9.0.0-alpha.2

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": "9.0.0-alpha.0",
3
+ "version": "9.0.0-alpha.2",
4
4
  "description": "Storybook HTML renderer",
5
5
  "keywords": [
6
6
  "storybook"
@@ -46,18 +46,14 @@
46
46
  "prep": "jiti ../../../scripts/prepare/bundle.ts"
47
47
  },
48
48
  "dependencies": {
49
- "@storybook/components": "9.0.0-alpha.0",
50
49
  "@storybook/global": "^5.0.0",
51
- "@storybook/manager-api": "9.0.0-alpha.0",
52
- "@storybook/preview-api": "9.0.0-alpha.0",
53
- "@storybook/theming": "9.0.0-alpha.0",
54
50
  "ts-dedent": "^2.0.0"
55
51
  },
56
52
  "devDependencies": {
57
53
  "typescript": "^5.7.3"
58
54
  },
59
55
  "peerDependencies": {
60
- "storybook": "^9.0.0-alpha.0"
56
+ "storybook": "^9.0.0-alpha.2"
61
57
  },
62
58
  "engines": {
63
59
  "node": ">=18.0.0"
@@ -1,59 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/html';
2
- import { fn } from '@storybook/test';
3
-
4
- import type { ButtonProps } from './Button';
5
- import { createButton } from './Button';
6
-
7
- // More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
8
- const meta: Meta<ButtonProps> = {
9
- title: 'Example/Button',
10
- tags: ['autodocs'],
11
- render: (args) => {
12
- // You can either use a function to create DOM elements or use a plain html string!
13
- // return `<div>${label}</div>`;
14
- return createButton(args);
15
- },
16
- argTypes: {
17
- backgroundColor: { control: 'color' },
18
- label: { control: 'text' },
19
- onClick: { action: 'onClick' },
20
- primary: { control: 'boolean' },
21
- size: {
22
- control: { type: 'select' },
23
- options: ['small', 'medium', 'large'],
24
- },
25
- },
26
- // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
27
- args: { onClick: fn() },
28
- };
29
-
30
- export default meta;
31
- type Story = StoryObj<ButtonProps>;
32
-
33
- // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
34
- export const Primary: Story = {
35
- args: {
36
- primary: true,
37
- label: 'Button',
38
- },
39
- };
40
-
41
- export const Secondary: Story = {
42
- args: {
43
- label: 'Button',
44
- },
45
- };
46
-
47
- export const Large: Story = {
48
- args: {
49
- size: 'large',
50
- label: 'Button',
51
- },
52
- };
53
-
54
- export const Small: Story = {
55
- args: {
56
- size: 'small',
57
- label: 'Button',
58
- },
59
- };
@@ -1,39 +0,0 @@
1
- import './button.css';
2
-
3
- export interface ButtonProps {
4
- /** Is this the principal call to action on the page? */
5
- primary?: boolean;
6
- /** What background color to use */
7
- backgroundColor?: string;
8
- /** How large should the button be? */
9
- size?: 'small' | 'medium' | 'large';
10
- /** Button contents */
11
- label: string;
12
- /** Optional click handler */
13
- onClick?: () => void;
14
- }
15
-
16
- /** Primary UI component for user interaction */
17
- export const createButton = ({
18
- primary = false,
19
- size = 'medium',
20
- backgroundColor,
21
- label,
22
- onClick,
23
- }: ButtonProps) => {
24
- const btn = document.createElement('button');
25
- btn.type = 'button';
26
- btn.innerText = label;
27
- if (onClick) {
28
- btn.addEventListener('click', onClick);
29
- }
30
-
31
- const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
32
- btn.className = ['storybook-button', `storybook-button--${size}`, mode].join(' ');
33
-
34
- if (backgroundColor) {
35
- btn.style.backgroundColor = backgroundColor;
36
- }
37
-
38
- return btn;
39
- };
@@ -1,35 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/html';
2
- import { fn } from '@storybook/test';
3
-
4
- import type { HeaderProps } from './Header';
5
- import { createHeader } from './Header';
6
-
7
- const meta: Meta<HeaderProps> = {
8
- title: 'Example/Header',
9
- // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
10
- tags: ['autodocs'],
11
- render: (args) => createHeader(args),
12
- parameters: {
13
- // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
14
- layout: 'fullscreen',
15
- },
16
- // More on argTypes: https://storybook.js.org/docs/api/argtypes
17
- args: {
18
- onLogin: fn(),
19
- onLogout: fn(),
20
- onCreateAccount: fn(),
21
- },
22
- };
23
-
24
- export default meta;
25
- type Story = StoryObj<HeaderProps>;
26
-
27
- export const LoggedIn: Story = {
28
- args: {
29
- user: {
30
- name: 'Jane Doe',
31
- },
32
- },
33
- };
34
-
35
- export const LoggedOut: Story = {};
@@ -1,54 +0,0 @@
1
- import { createButton } from './Button';
2
- import './header.css';
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 = 'storybook-header';
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,31 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/html';
2
- import { expect, userEvent, within } from '@storybook/test';
3
-
4
- import { createPage } from './Page';
5
-
6
- const meta: Meta = {
7
- title: 'Example/Page',
8
- render: () => createPage(),
9
- parameters: {
10
- // More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
11
- layout: 'fullscreen',
12
- },
13
- };
14
-
15
- export default meta;
16
-
17
- export const LoggedOut: StoryObj = {};
18
-
19
- // More on component testing: https://storybook.js.org/docs/writing-tests/component-testing
20
- export const LoggedIn: StoryObj = {
21
- play: async ({ canvasElement }) => {
22
- const canvas = within(canvasElement);
23
- const loginButton = canvas.getByRole('button', { name: /Log in/i });
24
- await expect(loginButton).toBeInTheDocument();
25
- await userEvent.click(loginButton);
26
- await expect(loginButton).not.toBeInTheDocument();
27
-
28
- const logoutButton = canvas.getByRole('button', { name: /Log out/i });
29
- await expect(logoutButton).toBeInTheDocument();
30
- },
31
- };
@@ -1,98 +0,0 @@
1
- import { createHeader } from './Header';
2
- import './page.css';
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 class="storybook-page">
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
- };