@storybook/cli 6.5.0-alpha.34 → 6.5.0-alpha.39

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.
Files changed (41) hide show
  1. package/dist/cjs/extract.js +7 -2
  2. package/dist/cjs/frameworks/angular/Header.stories.ts +8 -3
  3. package/dist/cjs/frameworks/angular/Page.stories.ts +12 -10
  4. package/dist/cjs/frameworks/angular/header.component.ts +30 -19
  5. package/dist/cjs/frameworks/angular/page.component.ts +13 -27
  6. package/dist/cjs/frameworks/common/header.css +6 -0
  7. package/dist/cjs/frameworks/react/js/Header.jsx +6 -1
  8. package/dist/cjs/frameworks/react/js/Header.stories.jsx +7 -1
  9. package/dist/cjs/frameworks/react/js/Page.jsx +61 -63
  10. package/dist/cjs/frameworks/react/js/Page.stories.jsx +12 -9
  11. package/dist/cjs/frameworks/react/ts/Header.stories.tsx +7 -1
  12. package/dist/cjs/frameworks/react/ts/Header.tsx +11 -2
  13. package/dist/cjs/frameworks/react/ts/Page.stories.tsx +12 -9
  14. package/dist/cjs/frameworks/react/ts/Page.tsx +66 -60
  15. package/dist/cjs/generators/baseGenerator.js +8 -0
  16. package/dist/cjs/versions.js +55 -55
  17. package/dist/esm/extract.js +7 -2
  18. package/dist/esm/frameworks/angular/Header.stories.ts +8 -3
  19. package/dist/esm/frameworks/angular/Page.stories.ts +12 -10
  20. package/dist/esm/frameworks/angular/header.component.ts +30 -19
  21. package/dist/esm/frameworks/angular/page.component.ts +13 -27
  22. package/dist/esm/frameworks/common/header.css +6 -0
  23. package/dist/esm/frameworks/react/js/Header.jsx +6 -1
  24. package/dist/esm/frameworks/react/js/Header.stories.jsx +7 -1
  25. package/dist/esm/frameworks/react/js/Page.jsx +61 -63
  26. package/dist/esm/frameworks/react/js/Page.stories.jsx +12 -9
  27. package/dist/esm/frameworks/react/ts/Header.stories.tsx +7 -1
  28. package/dist/esm/frameworks/react/ts/Header.tsx +11 -2
  29. package/dist/esm/frameworks/react/ts/Page.stories.tsx +12 -9
  30. package/dist/esm/frameworks/react/ts/Page.tsx +66 -60
  31. package/dist/esm/generators/baseGenerator.js +8 -0
  32. package/dist/esm/versions.js +55 -55
  33. package/dist/modern/extract.js +7 -2
  34. package/dist/modern/frameworks/common/header.css +6 -0
  35. package/dist/modern/frameworks/react/js/Header.jsx +6 -1
  36. package/dist/modern/frameworks/react/js/Header.stories.jsx +7 -1
  37. package/dist/modern/frameworks/react/js/Page.jsx +61 -63
  38. package/dist/modern/frameworks/react/js/Page.stories.jsx +12 -9
  39. package/dist/modern/generators/baseGenerator.js +8 -0
  40. package/dist/modern/versions.js +55 -55
  41. package/package.json +7 -7
@@ -3,65 +3,71 @@ import React from 'react';
3
3
  import { Header } from './Header';
4
4
  import './page.css';
5
5
 
6
- interface PageProps {
7
- user?: {};
8
- onLogin: () => void;
9
- onLogout: () => void;
10
- onCreateAccount: () => void;
11
- }
6
+ type User = {
7
+ name: string;
8
+ };
12
9
 
13
- export const Page = ({ user, onLogin, onLogout, onCreateAccount }: PageProps) => (
14
- <article>
15
- <Header user={user} onLogin={onLogin} onLogout={onLogout} onCreateAccount={onCreateAccount} />
10
+ export const Page: React.VFC = () => {
11
+ const [user, setUser] = React.useState<User>();
16
12
 
17
- <section>
18
- <h2>Pages in Storybook</h2>
19
- <p>
20
- We recommend building UIs with a{' '}
21
- <a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
22
- <strong>component-driven</strong>
23
- </a>{' '}
24
- process starting with atomic components and ending with pages.
25
- </p>
26
- <p>
27
- Render pages with mock data. This makes it easy to build and review page states without
28
- needing to navigate to them in your app. Here are some handy patterns for managing page data
29
- in Storybook:
30
- </p>
31
- <ul>
32
- <li>
33
- Use a higher-level connected component. Storybook helps you compose such data from the
34
- "args" of child component stories
35
- </li>
36
- <li>
37
- Assemble data in the page component from your services. You can mock these services out
38
- using Storybook.
39
- </li>
40
- </ul>
41
- <p>
42
- Get a guided tutorial on component-driven development at{' '}
43
- <a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
44
- Storybook tutorials
45
- </a>
46
- . Read more in the{' '}
47
- <a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
48
- docs
49
- </a>
50
- .
51
- </p>
52
- <div className="tip-wrapper">
53
- <span className="tip">Tip</span> Adjust the width of the canvas with the{' '}
54
- <svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
55
- <g fill="none" fillRule="evenodd">
56
- <path
57
- 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"
58
- id="a"
59
- fill="#999"
60
- />
61
- </g>
62
- </svg>
63
- Viewports addon in the toolbar
64
- </div>
65
- </section>
66
- </article>
67
- );
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>
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
+ };
@@ -51,6 +51,8 @@ const builderDependencies = builder => {
51
51
 
52
52
  const stripVersions = addons => addons.map(addon => (0, _jsPackageManager.getPackageDetails)(addon)[0]);
53
53
 
54
+ const hasInteractiveStories = framework => ['react', 'angular'].includes(framework);
55
+
54
56
  async function baseGenerator(packageManager, npmOptions, {
55
57
  language,
56
58
  builder
@@ -71,6 +73,12 @@ async function baseGenerator(packageManager, npmOptions, {
71
73
  const addons = ['@storybook/addon-links', '@storybook/addon-essentials']; // added to package.json
72
74
 
73
75
  const addonPackages = [...addons, '@storybook/addon-actions'];
76
+
77
+ if (hasInteractiveStories(framework)) {
78
+ addons.push('@storybook/addon-interactions');
79
+ addonPackages.push('@storybook/addon-interactions', '@storybook/testing-library');
80
+ }
81
+
74
82
  const yarn2Dependencies = packageManager.type === 'yarn2' ? ['@storybook/addon-docs', '@mdx-js/react@1.x.x'] : [];
75
83
  const files = await _fsExtra.default.readdir(process.cwd());
76
84
  const isNewFolder = !files.some(fname => fname.startsWith('.babel') || fname.startsWith('babel') || fname === 'package.json');
@@ -6,60 +6,60 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  // auto generated file, do not edit
8
8
  var _default = {
9
- "@storybook/addon-a11y": "6.5.0-alpha.34",
10
- "@storybook/addon-actions": "6.5.0-alpha.34",
11
- "@storybook/addon-backgrounds": "6.5.0-alpha.34",
12
- "@storybook/addon-controls": "6.5.0-alpha.34",
13
- "@storybook/addon-docs": "6.5.0-alpha.34",
14
- "@storybook/addon-essentials": "6.5.0-alpha.34",
15
- "@storybook/addon-interactions": "6.5.0-alpha.34",
16
- "@storybook/addon-jest": "6.5.0-alpha.34",
17
- "@storybook/addon-links": "6.5.0-alpha.34",
18
- "@storybook/addon-measure": "6.5.0-alpha.34",
19
- "@storybook/addon-outline": "6.5.0-alpha.34",
20
- "@storybook/addon-storyshots": "6.5.0-alpha.34",
21
- "@storybook/addon-storyshots-puppeteer": "6.5.0-alpha.34",
22
- "@storybook/addon-storysource": "6.5.0-alpha.34",
23
- "@storybook/addon-toolbars": "6.5.0-alpha.34",
24
- "@storybook/addon-viewport": "6.5.0-alpha.34",
25
- "@storybook/addons": "6.5.0-alpha.34",
26
- "@storybook/angular": "6.5.0-alpha.34",
27
- "@storybook/api": "6.5.0-alpha.34",
28
- "@storybook/builder-webpack4": "6.5.0-alpha.34",
29
- "@storybook/builder-webpack5": "6.5.0-alpha.34",
30
- "@storybook/channel-postmessage": "6.5.0-alpha.34",
31
- "@storybook/channel-websocket": "6.5.0-alpha.34",
32
- "@storybook/channels": "6.5.0-alpha.34",
33
- "@storybook/cli": "6.5.0-alpha.34",
34
- "@storybook/client-api": "6.5.0-alpha.34",
35
- "@storybook/client-logger": "6.5.0-alpha.34",
36
- "@storybook/codemod": "6.5.0-alpha.34",
37
- "@storybook/components": "6.5.0-alpha.34",
38
- "@storybook/core": "6.5.0-alpha.34",
39
- "@storybook/core-client": "6.5.0-alpha.34",
40
- "@storybook/core-common": "6.5.0-alpha.34",
41
- "@storybook/core-events": "6.5.0-alpha.34",
42
- "@storybook/core-server": "6.5.0-alpha.34",
43
- "@storybook/csf-tools": "6.5.0-alpha.34",
44
- "@storybook/ember": "6.5.0-alpha.34",
45
- "@storybook/html": "6.5.0-alpha.34",
46
- "@storybook/instrumenter": "6.5.0-alpha.34",
47
- "@storybook/manager-webpack4": "6.5.0-alpha.34",
48
- "@storybook/manager-webpack5": "6.5.0-alpha.34",
49
- "@storybook/node-logger": "6.5.0-alpha.34",
50
- "@storybook/postinstall": "6.5.0-alpha.34",
51
- "@storybook/preact": "6.5.0-alpha.34",
52
- "@storybook/preview-web": "6.5.0-alpha.34",
53
- "@storybook/react": "6.5.0-alpha.34",
54
- "@storybook/router": "6.5.0-alpha.34",
55
- "@storybook/server": "6.5.0-alpha.34",
56
- "@storybook/source-loader": "6.5.0-alpha.34",
57
- "@storybook/store": "6.5.0-alpha.34",
58
- "@storybook/svelte": "6.5.0-alpha.34",
59
- "@storybook/theming": "6.5.0-alpha.34",
60
- "@storybook/ui": "6.5.0-alpha.34",
61
- "@storybook/vue": "6.5.0-alpha.34",
62
- "@storybook/vue3": "6.5.0-alpha.34",
63
- "@storybook/web-components": "6.5.0-alpha.34"
9
+ "@storybook/addon-a11y": "6.5.0-alpha.39",
10
+ "@storybook/addon-actions": "6.5.0-alpha.39",
11
+ "@storybook/addon-backgrounds": "6.5.0-alpha.39",
12
+ "@storybook/addon-controls": "6.5.0-alpha.39",
13
+ "@storybook/addon-docs": "6.5.0-alpha.39",
14
+ "@storybook/addon-essentials": "6.5.0-alpha.39",
15
+ "@storybook/addon-interactions": "6.5.0-alpha.39",
16
+ "@storybook/addon-jest": "6.5.0-alpha.39",
17
+ "@storybook/addon-links": "6.5.0-alpha.39",
18
+ "@storybook/addon-measure": "6.5.0-alpha.39",
19
+ "@storybook/addon-outline": "6.5.0-alpha.39",
20
+ "@storybook/addon-storyshots": "6.5.0-alpha.39",
21
+ "@storybook/addon-storyshots-puppeteer": "6.5.0-alpha.39",
22
+ "@storybook/addon-storysource": "6.5.0-alpha.39",
23
+ "@storybook/addon-toolbars": "6.5.0-alpha.39",
24
+ "@storybook/addon-viewport": "6.5.0-alpha.39",
25
+ "@storybook/addons": "6.5.0-alpha.39",
26
+ "@storybook/angular": "6.5.0-alpha.39",
27
+ "@storybook/api": "6.5.0-alpha.39",
28
+ "@storybook/builder-webpack4": "6.5.0-alpha.39",
29
+ "@storybook/builder-webpack5": "6.5.0-alpha.39",
30
+ "@storybook/channel-postmessage": "6.5.0-alpha.39",
31
+ "@storybook/channel-websocket": "6.5.0-alpha.39",
32
+ "@storybook/channels": "6.5.0-alpha.39",
33
+ "@storybook/cli": "6.5.0-alpha.39",
34
+ "@storybook/client-api": "6.5.0-alpha.39",
35
+ "@storybook/client-logger": "6.5.0-alpha.39",
36
+ "@storybook/codemod": "6.5.0-alpha.39",
37
+ "@storybook/components": "6.5.0-alpha.39",
38
+ "@storybook/core": "6.5.0-alpha.39",
39
+ "@storybook/core-client": "6.5.0-alpha.39",
40
+ "@storybook/core-common": "6.5.0-alpha.39",
41
+ "@storybook/core-events": "6.5.0-alpha.39",
42
+ "@storybook/core-server": "6.5.0-alpha.39",
43
+ "@storybook/csf-tools": "6.5.0-alpha.39",
44
+ "@storybook/ember": "6.5.0-alpha.39",
45
+ "@storybook/html": "6.5.0-alpha.39",
46
+ "@storybook/instrumenter": "6.5.0-alpha.39",
47
+ "@storybook/manager-webpack4": "6.5.0-alpha.39",
48
+ "@storybook/manager-webpack5": "6.5.0-alpha.39",
49
+ "@storybook/node-logger": "6.5.0-alpha.39",
50
+ "@storybook/postinstall": "6.5.0-alpha.39",
51
+ "@storybook/preact": "6.5.0-alpha.39",
52
+ "@storybook/preview-web": "6.5.0-alpha.39",
53
+ "@storybook/react": "6.5.0-alpha.39",
54
+ "@storybook/router": "6.5.0-alpha.39",
55
+ "@storybook/server": "6.5.0-alpha.39",
56
+ "@storybook/source-loader": "6.5.0-alpha.39",
57
+ "@storybook/store": "6.5.0-alpha.39",
58
+ "@storybook/svelte": "6.5.0-alpha.39",
59
+ "@storybook/theming": "6.5.0-alpha.39",
60
+ "@storybook/ui": "6.5.0-alpha.39",
61
+ "@storybook/vue": "6.5.0-alpha.39",
62
+ "@storybook/vue3": "6.5.0-alpha.39",
63
+ "@storybook/web-components": "6.5.0-alpha.39"
64
64
  };
65
65
  exports.default = _default;
@@ -24,8 +24,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
24
24
  const read = async url => {
25
25
  const browser = await usePuppeteerBrowser();
26
26
  const page = await browser.newPage();
27
- await page.goto(url);
28
- await page.waitForFunction('window.__STORYBOOK_STORY_STORE__ && window.__STORYBOOK_STORY_STORE__.extract && window.__STORYBOOK_STORY_STORE__.extract()');
27
+ await page.goto(url); // we don't know whether we are running against a new or old storybook
28
+ // FIXME: add tests for both
29
+
30
+ await page.waitForFunction(`
31
+ (window.__STORYBOOK_PREVIEW__ && window.__STORYBOOK_PREVIEW__.extract && window.__STORYBOOK_PREVIEW__.extract()) ||
32
+ (window.__STORYBOOK_STORY_STORE__ && window.__STORYBOOK_STORY_STORE__.extract && window.__STORYBOOK_STORY_STORE__.extract())
33
+ `);
29
34
  const data = JSON.parse(await page.evaluate(async () => {
30
35
  // eslint-disable-next-line no-undef
31
36
  return JSON.stringify(window.__STORYBOOK_STORY_STORE__.getStoriesJsonData(), null, 2);
@@ -24,3 +24,9 @@ h1 {
24
24
  button + button {
25
25
  margin-left: 10px;
26
26
  }
27
+
28
+ .welcome {
29
+ color: #333;
30
+ font-size: 14px;
31
+ margin-right: 10px;
32
+ }
@@ -28,7 +28,12 @@ export const Header = ({ user, onLogin, onLogout, onCreateAccount }) => (
28
28
  </div>
29
29
  <div>
30
30
  {user ? (
31
- <Button size="small" onClick={onLogout} label="Log out" />
31
+ <>
32
+ <span className="welcome">
33
+ Welcome, <b>{user.name}</b>!
34
+ </span>
35
+ <Button size="small" onClick={onLogout} label="Log out" />
36
+ </>
32
37
  ) : (
33
38
  <>
34
39
  <Button size="small" onClick={onLogin} label="Log in" />
@@ -5,13 +5,19 @@ import { Header } from './Header';
5
5
  export default {
6
6
  title: 'Example/Header',
7
7
  component: Header,
8
+ parameters: {
9
+ // More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
10
+ layout: 'fullscreen',
11
+ },
8
12
  };
9
13
 
10
14
  const Template = (args) => <Header {...args} />;
11
15
 
12
16
  export const LoggedIn = Template.bind({});
13
17
  LoggedIn.args = {
14
- user: {},
18
+ user: {
19
+ name: 'Jane Doe',
20
+ },
15
21
  };
16
22
 
17
23
  export const LoggedOut = Template.bind({});
@@ -1,71 +1,69 @@
1
1
  import React from 'react';
2
- import PropTypes from 'prop-types';
3
2
 
4
3
  import { Header } from './Header';
5
4
  import './page.css';
6
5
 
7
- export const Page = ({ user, onLogin, onLogout, onCreateAccount }) => (
8
- <article>
9
- <Header user={user} onLogin={onLogin} onLogout={onLogout} onCreateAccount={onCreateAccount} />
6
+ export const Page = () => {
7
+ const [user, setUser] = React.useState();
10
8
 
11
- <section>
12
- <h2>Pages in Storybook</h2>
13
- <p>
14
- We recommend building UIs with a{' '}
15
- <a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
16
- <strong>component-driven</strong>
17
- </a>{' '}
18
- process starting with atomic components and ending with pages.
19
- </p>
20
- <p>
21
- Render pages with mock data. This makes it easy to build and review page states without
22
- needing to navigate to them in your app. Here are some handy patterns for managing page data
23
- in Storybook:
24
- </p>
25
- <ul>
26
- <li>
27
- Use a higher-level connected component. Storybook helps you compose such data from the
28
- "args" of child component stories
29
- </li>
30
- <li>
31
- Assemble data in the page component from your services. You can mock these services out
32
- using Storybook.
33
- </li>
34
- </ul>
35
- <p>
36
- Get a guided tutorial on component-driven development at{' '}
37
- <a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
38
- Storybook tutorials
39
- </a>
40
- . Read more in the{' '}
41
- <a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
42
- docs
43
- </a>
44
- .
45
- </p>
46
- <div className="tip-wrapper">
47
- <span className="tip">Tip</span> Adjust the width of the canvas with the{' '}
48
- <svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
49
- <g fill="none" fillRule="evenodd">
50
- <path
51
- 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"
52
- id="a"
53
- fill="#999"
54
- />
55
- </g>
56
- </svg>
57
- Viewports addon in the toolbar
58
- </div>
59
- </section>
60
- </article>
61
- );
62
- Page.propTypes = {
63
- user: PropTypes.shape({}),
64
- onLogin: PropTypes.func.isRequired,
65
- onLogout: PropTypes.func.isRequired,
66
- onCreateAccount: PropTypes.func.isRequired,
67
- };
9
+ return (
10
+ <article>
11
+ <Header
12
+ user={user}
13
+ onLogin={() => setUser({ name: 'Jane Doe' })}
14
+ onLogout={() => setUser(undefined)}
15
+ onCreateAccount={() => setUser({ name: 'Jane Doe' })}
16
+ />
68
17
 
69
- Page.defaultProps = {
70
- user: null,
18
+ <section>
19
+ <h2>Pages in Storybook</h2>
20
+ <p>
21
+ We recommend building UIs with a{' '}
22
+ <a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
23
+ <strong>component-driven</strong>
24
+ </a>{' '}
25
+ process starting with atomic components and ending with pages.
26
+ </p>
27
+ <p>
28
+ Render pages with mock data. This makes it easy to build and review page states without
29
+ needing to navigate to them in your app. Here are some handy patterns for managing page
30
+ data in Storybook:
31
+ </p>
32
+ <ul>
33
+ <li>
34
+ Use a higher-level connected component. Storybook helps you compose such data from the
35
+ "args" of child component stories
36
+ </li>
37
+ <li>
38
+ Assemble data in the page component from your services. You can mock these services out
39
+ using Storybook.
40
+ </li>
41
+ </ul>
42
+ <p>
43
+ Get a guided tutorial on component-driven development at{' '}
44
+ <a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
45
+ Storybook tutorials
46
+ </a>
47
+ . Read more in the{' '}
48
+ <a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">
49
+ docs
50
+ </a>
51
+ .
52
+ </p>
53
+ <div className="tip-wrapper">
54
+ <span className="tip">Tip</span> Adjust the width of the canvas with the{' '}
55
+ <svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
56
+ <g fill="none" fillRule="evenodd">
57
+ <path
58
+ 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"
59
+ id="a"
60
+ fill="#999"
61
+ />
62
+ </g>
63
+ </svg>
64
+ Viewports addon in the toolbar
65
+ </div>
66
+ </section>
67
+ </article>
68
+ );
71
69
  };
@@ -1,22 +1,25 @@
1
1
  import React from 'react';
2
+ import { within, userEvent } from '@storybook/testing-library';
2
3
 
3
4
  import { Page } from './Page';
4
- import * as HeaderStories from './Header.stories';
5
5
 
6
6
  export default {
7
7
  title: 'Example/Page',
8
8
  component: Page,
9
+ parameters: {
10
+ // More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
11
+ layout: 'fullscreen',
12
+ },
9
13
  };
10
14
 
11
15
  const Template = (args) => <Page {...args} />;
12
16
 
13
- export const LoggedIn = Template.bind({});
14
- LoggedIn.args = {
15
- // More on composing args: https://storybook.js.org/docs/react/writing-stories/args#args-composition
16
- ...HeaderStories.LoggedIn.args,
17
- };
18
-
17
+ // More on interaction testing: https://storybook.js.org/docs/react/writing-tests/interaction-testing
19
18
  export const LoggedOut = Template.bind({});
20
- LoggedOut.args = {
21
- ...HeaderStories.LoggedOut.args,
19
+
20
+ export const LoggedIn = Template.bind({});
21
+ LoggedIn.play = async ({ canvasElement }) => {
22
+ const canvas = within(canvasElement);
23
+ const loginButton = await canvas.getByRole('button', { name: /Log in/i });
24
+ await userEvent.click(loginButton);
22
25
  };
@@ -51,6 +51,8 @@ const builderDependencies = builder => {
51
51
 
52
52
  const stripVersions = addons => addons.map(addon => (0, _jsPackageManager.getPackageDetails)(addon)[0]);
53
53
 
54
+ const hasInteractiveStories = framework => ['react', 'angular'].includes(framework);
55
+
54
56
  async function baseGenerator(packageManager, npmOptions, {
55
57
  language,
56
58
  builder
@@ -71,6 +73,12 @@ async function baseGenerator(packageManager, npmOptions, {
71
73
  const addons = ['@storybook/addon-links', '@storybook/addon-essentials']; // added to package.json
72
74
 
73
75
  const addonPackages = [...addons, '@storybook/addon-actions'];
76
+
77
+ if (hasInteractiveStories(framework)) {
78
+ addons.push('@storybook/addon-interactions');
79
+ addonPackages.push('@storybook/addon-interactions', '@storybook/testing-library');
80
+ }
81
+
74
82
  const yarn2Dependencies = packageManager.type === 'yarn2' ? ['@storybook/addon-docs', '@mdx-js/react@1.x.x'] : [];
75
83
  const files = await _fsExtra.default.readdir(process.cwd());
76
84
  const isNewFolder = !files.some(fname => fname.startsWith('.babel') || fname.startsWith('babel') || fname === 'package.json');