@storybook/experimental-nextjs-vite 0.0.0-pr-28768-sha-4bf04455

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. package/README.md +10 -0
  2. package/dist/chunk-4N4PSHX6.mjs +3 -0
  3. package/dist/chunk-DWCMLBIB.mjs +20 -0
  4. package/dist/chunk-GKRSUUNG.mjs +6 -0
  5. package/dist/export-mocks/cache/index.d.ts +14 -0
  6. package/dist/export-mocks/cache/index.js +1 -0
  7. package/dist/export-mocks/cache/index.mjs +6 -0
  8. package/dist/export-mocks/headers/index.d.ts +36 -0
  9. package/dist/export-mocks/headers/index.js +1 -0
  10. package/dist/export-mocks/headers/index.mjs +10 -0
  11. package/dist/export-mocks/navigation/index.d.ts +42 -0
  12. package/dist/export-mocks/navigation/index.js +1 -0
  13. package/dist/export-mocks/navigation/index.mjs +11 -0
  14. package/dist/export-mocks/router/index.d.ts +46 -0
  15. package/dist/export-mocks/router/index.js +1 -0
  16. package/dist/export-mocks/router/index.mjs +10 -0
  17. package/dist/images/decorator.d.ts +6 -0
  18. package/dist/images/decorator.js +1 -0
  19. package/dist/images/decorator.mjs +2 -0
  20. package/dist/index.d-5a935e77.d.ts +266 -0
  21. package/dist/index.d.ts +103 -0
  22. package/dist/index.js +1 -0
  23. package/dist/index.mjs +10 -0
  24. package/dist/preset.d.ts +8 -0
  25. package/dist/preset.js +1 -0
  26. package/dist/preview.d.ts +18 -0
  27. package/dist/preview.js +1 -0
  28. package/dist/preview.mjs +3 -0
  29. package/dist/react-18-E7XCW3XF.mjs +7 -0
  30. package/package.json +143 -0
  31. package/preset.js +1 -0
  32. package/template/cli/.eslintrc.json +7 -0
  33. package/template/cli/js/Button.jsx +56 -0
  34. package/template/cli/js/Button.stories.js +49 -0
  35. package/template/cli/js/Configure.mdx +446 -0
  36. package/template/cli/js/Header.jsx +60 -0
  37. package/template/cli/js/Header.stories.js +30 -0
  38. package/template/cli/js/Page.jsx +68 -0
  39. package/template/cli/js/Page.stories.js +28 -0
  40. package/template/cli/ts-3-8/Button.stories.ts +53 -0
  41. package/template/cli/ts-3-8/Button.tsx +53 -0
  42. package/template/cli/ts-3-8/Configure.mdx +446 -0
  43. package/template/cli/ts-3-8/Header.stories.ts +33 -0
  44. package/template/cli/ts-3-8/Header.tsx +56 -0
  45. package/template/cli/ts-3-8/Page.stories.ts +32 -0
  46. package/template/cli/ts-3-8/Page.tsx +73 -0
  47. package/template/cli/ts-4-9/Button.stories.ts +53 -0
  48. package/template/cli/ts-4-9/Button.tsx +53 -0
  49. package/template/cli/ts-4-9/Configure.mdx +446 -0
  50. package/template/cli/ts-4-9/Header.stories.ts +33 -0
  51. package/template/cli/ts-4-9/Header.tsx +56 -0
  52. package/template/cli/ts-4-9/Page.stories.ts +32 -0
  53. package/template/cli/ts-4-9/Page.tsx +73 -0
  54. package/template/next-env.d.ts +7 -0
  55. package/template/typings.d.ts +14 -0
@@ -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
+ export 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="storybook-header">
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,32 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { expect, userEvent, within } from '@storybook/test';
3
+
4
+ import { Page } from './Page';
5
+
6
+ const meta: Meta<typeof Page> = {
7
+ title: 'Example/Page',
8
+ component: Page,
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
+ type Story = StoryObj<typeof Page>;
17
+
18
+ export const LoggedOut: Story = {};
19
+
20
+ // More on interaction testing: https://storybook.js.org/docs/writing-tests/interaction-testing
21
+ export const LoggedIn: Story = {
22
+ play: async ({ canvasElement }) => {
23
+ const canvas = within(canvasElement);
24
+ const loginButton = canvas.getByRole('button', { name: /Log in/i });
25
+ await expect(loginButton).toBeInTheDocument();
26
+ await userEvent.click(loginButton);
27
+ await expect(loginButton).not.toBeInTheDocument();
28
+
29
+ const logoutButton = canvas.getByRole('button', { name: /Log out/i });
30
+ await expect(logoutButton).toBeInTheDocument();
31
+ },
32
+ };
@@ -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.FC = () => {
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 className="storybook-page">
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,53 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { fn } from '@storybook/test';
3
+
4
+ import { Button } from './Button';
5
+
6
+ // More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
7
+ const meta = {
8
+ title: 'Example/Button',
9
+ component: Button,
10
+ parameters: {
11
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
12
+ layout: 'centered',
13
+ },
14
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
15
+ tags: ['autodocs'],
16
+ // More on argTypes: https://storybook.js.org/docs/api/argtypes
17
+ argTypes: {
18
+ backgroundColor: { control: 'color' },
19
+ },
20
+ // 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
21
+ args: { onClick: fn() },
22
+ } satisfies Meta<typeof Button>;
23
+
24
+ export default meta;
25
+ type Story = StoryObj<typeof meta>;
26
+
27
+ // More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
28
+ export const Primary: Story = {
29
+ args: {
30
+ primary: true,
31
+ label: 'Button',
32
+ },
33
+ };
34
+
35
+ export const Secondary: Story = {
36
+ args: {
37
+ label: 'Button',
38
+ },
39
+ };
40
+
41
+ export const Large: Story = {
42
+ args: {
43
+ size: 'large',
44
+ label: 'Button',
45
+ },
46
+ };
47
+
48
+ export const Small: Story = {
49
+ args: {
50
+ size: 'small',
51
+ label: 'Button',
52
+ },
53
+ };
@@ -0,0 +1,53 @@
1
+ import React from 'react';
2
+
3
+ import './button.css';
4
+
5
+ export interface ButtonProps {
6
+ /**
7
+ * Is this the principal call to action on the page?
8
+ */
9
+ primary?: boolean;
10
+ /**
11
+ * What background color to use
12
+ */
13
+ backgroundColor?: string;
14
+ /**
15
+ * How large should the button be?
16
+ */
17
+ size?: 'small' | 'medium' | 'large';
18
+ /**
19
+ * Button contents
20
+ */
21
+ label: string;
22
+ /**
23
+ * Optional click handler
24
+ */
25
+ onClick?: () => void;
26
+ }
27
+
28
+ /**
29
+ * Primary UI component for user interaction
30
+ */
31
+ export const Button = ({
32
+ primary = false,
33
+ size = 'medium',
34
+ backgroundColor,
35
+ label,
36
+ ...props
37
+ }: ButtonProps) => {
38
+ const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
39
+ return (
40
+ <button
41
+ type="button"
42
+ className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
43
+ {...props}
44
+ >
45
+ {label}
46
+ <style jsx>{`
47
+ button {
48
+ background-color: ${backgroundColor};
49
+ }
50
+ `}</style>
51
+ </button>
52
+ );
53
+ };