@storybook/react 7.0.0-alpha.7 → 7.0.0-beta.0

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 (181) hide show
  1. package/dist/chunk-LSK4KSW4.mjs +1 -0
  2. package/dist/config.d.ts +11 -13
  3. package/dist/config.js +3 -7
  4. package/dist/config.mjs +3 -7
  5. package/dist/index.d.ts +57 -37
  6. package/dist/index.js +1 -1
  7. package/dist/index.mjs +1 -1
  8. package/dist/types-0a347bb9.d.ts +10 -0
  9. package/jest.config.js +7 -0
  10. package/package.json +27 -22
  11. package/template/cli/.eslintrc.json +5 -0
  12. package/template/cli/js/Button.jsx +50 -0
  13. package/template/cli/js/Button.stories.js +39 -0
  14. package/template/cli/js/Header.jsx +59 -0
  15. package/template/cli/js/Header.stories.js +22 -0
  16. package/template/cli/js/Page.jsx +69 -0
  17. package/template/cli/js/Page.stories.js +25 -0
  18. package/template/cli/ts/Button.stories.ts +44 -0
  19. package/template/cli/ts/Button.tsx +48 -0
  20. package/template/cli/ts/Header.stories.ts +26 -0
  21. package/template/cli/ts/Header.tsx +56 -0
  22. package/template/cli/ts/Page.stories.ts +29 -0
  23. package/template/cli/ts/Page.tsx +73 -0
  24. package/template/cli/ts-legacy/Button.stories.ts +45 -0
  25. package/template/cli/ts-legacy/Button.tsx +48 -0
  26. package/template/cli/ts-legacy/Header.stories.ts +24 -0
  27. package/template/cli/ts-legacy/Header.tsx +56 -0
  28. package/template/cli/ts-legacy/Page.stories.ts +29 -0
  29. package/template/cli/ts-legacy/Page.tsx +73 -0
  30. package/template/components/Button.jsx +13 -0
  31. package/template/components/Form.jsx +36 -0
  32. package/template/components/Html.jsx +9 -0
  33. package/template/components/Pre.jsx +20 -0
  34. package/template/components/index.js +9 -0
  35. package/template/stories/decorators.stories.tsx +28 -0
  36. package/template/stories/docgen-components/10017-ts-union/argTypes.snapshot +36 -0
  37. package/template/stories/docgen-components/10017-ts-union/docgen.snapshot +34 -0
  38. package/template/stories/docgen-components/10017-ts-union/input.tsx +12 -0
  39. package/template/stories/docgen-components/10017-ts-union/properties.snapshot +32 -0
  40. package/template/stories/docgen-components/10278-ts-multiple-components/argTypes.snapshot +26 -0
  41. package/template/stories/docgen-components/10278-ts-multiple-components/docgen.snapshot +49 -0
  42. package/template/stories/docgen-components/10278-ts-multiple-components/input.tsx +27 -0
  43. package/template/stories/docgen-components/10278-ts-multiple-components/properties.snapshot +22 -0
  44. package/template/stories/docgen-components/8140-js-prop-types-oneof/argTypes.snapshot +127 -0
  45. package/template/stories/docgen-components/8140-js-prop-types-oneof/docgen.snapshot +97 -0
  46. package/template/stories/docgen-components/8140-js-prop-types-oneof/input.jsx +27 -0
  47. package/template/stories/docgen-components/8140-js-prop-types-oneof/properties.snapshot +89 -0
  48. package/template/stories/docgen-components/8143-ts-imported-types/argTypes.snapshot +27 -0
  49. package/template/stories/docgen-components/8143-ts-imported-types/docgen.snapshot +22 -0
  50. package/template/stories/docgen-components/8143-ts-imported-types/input.tsx +10 -0
  51. package/template/stories/docgen-components/8143-ts-imported-types/properties.snapshot +23 -0
  52. package/template/stories/docgen-components/8143-ts-imported-types/types.ts +3 -0
  53. package/template/stories/docgen-components/8143-ts-react-fc-generics/argTypes.snapshot +27 -0
  54. package/template/stories/docgen-components/8143-ts-react-fc-generics/docgen.snapshot +24 -0
  55. package/template/stories/docgen-components/8143-ts-react-fc-generics/input.tsx +10 -0
  56. package/template/stories/docgen-components/8143-ts-react-fc-generics/properties.snapshot +21 -0
  57. package/template/stories/docgen-components/8428-js-static-prop-types/argTypes.snapshot +25 -0
  58. package/template/stories/docgen-components/8428-js-static-prop-types/docgen.snapshot +39 -0
  59. package/template/stories/docgen-components/8428-js-static-prop-types/input.jsx +20 -0
  60. package/template/stories/docgen-components/8428-js-static-prop-types/properties.snapshot +21 -0
  61. package/template/stories/docgen-components/8740-ts-multi-props/argTypes.snapshot +27 -0
  62. package/template/stories/docgen-components/8740-ts-multi-props/docgen.snapshot +49 -0
  63. package/template/stories/docgen-components/8740-ts-multi-props/input.tsx +23 -0
  64. package/template/stories/docgen-components/8740-ts-multi-props/properties.snapshot +21 -0
  65. package/template/stories/docgen-components/8894-9511-ts-forward-ref/argTypes.snapshot +48 -0
  66. package/template/stories/docgen-components/8894-9511-ts-forward-ref/docgen.snapshot +39 -0
  67. package/template/stories/docgen-components/8894-9511-ts-forward-ref/input.tsx +31 -0
  68. package/template/stories/docgen-components/8894-9511-ts-forward-ref/properties.snapshot +34 -0
  69. package/template/stories/docgen-components/9023-js-hoc/argTypes.snapshot +89 -0
  70. package/template/stories/docgen-components/9023-js-hoc/docgen.snapshot +84 -0
  71. package/template/stories/docgen-components/9023-js-hoc/input.jsx +40 -0
  72. package/template/stories/docgen-components/9023-js-hoc/properties.snapshot +67 -0
  73. package/template/stories/docgen-components/9399-js-proptypes-shape/argTypes.snapshot +39 -0
  74. package/template/stories/docgen-components/9399-js-proptypes-shape/docgen.snapshot +48 -0
  75. package/template/stories/docgen-components/9399-js-proptypes-shape/input.jsx +16 -0
  76. package/template/stories/docgen-components/9399-js-proptypes-shape/properties.snapshot +35 -0
  77. package/template/stories/docgen-components/9465-ts-type-props/argTypes.snapshot +28 -0
  78. package/template/stories/docgen-components/9465-ts-type-props/docgen.snapshot +33 -0
  79. package/template/stories/docgen-components/9465-ts-type-props/input.tsx +12 -0
  80. package/template/stories/docgen-components/9465-ts-type-props/properties.snapshot +24 -0
  81. package/template/stories/docgen-components/9493-ts-display-name/argTypes.snapshot +62 -0
  82. package/template/stories/docgen-components/9493-ts-display-name/docgen.snapshot +50 -0
  83. package/template/stories/docgen-components/9493-ts-display-name/input.tsx +30 -0
  84. package/template/stories/docgen-components/9493-ts-display-name/properties.snapshot +52 -0
  85. package/template/stories/docgen-components/9556-ts-react-default-exports/argTypes.snapshot +28 -0
  86. package/template/stories/docgen-components/9556-ts-react-default-exports/docgen.snapshot +32 -0
  87. package/template/stories/docgen-components/9556-ts-react-default-exports/input.tsx +12 -0
  88. package/template/stories/docgen-components/9556-ts-react-default-exports/properties.snapshot +24 -0
  89. package/template/stories/docgen-components/9575-ts-camel-case/argTypes.snapshot +28 -0
  90. package/template/stories/docgen-components/9575-ts-camel-case/docgen.snapshot +38 -0
  91. package/template/stories/docgen-components/9575-ts-camel-case/input.tsx +26 -0
  92. package/template/stories/docgen-components/9575-ts-camel-case/properties.snapshot +24 -0
  93. package/template/stories/docgen-components/9586-js-react-memo/argTypes.snapshot +41 -0
  94. package/template/stories/docgen-components/9586-js-react-memo/docgen.snapshot +42 -0
  95. package/template/stories/docgen-components/9586-js-react-memo/input.jsx +15 -0
  96. package/template/stories/docgen-components/9586-js-react-memo/properties.snapshot +34 -0
  97. package/template/stories/docgen-components/9591-ts-import-types/Bar.tsx +3 -0
  98. package/template/stories/docgen-components/9591-ts-import-types/argTypes.snapshot +25 -0
  99. package/template/stories/docgen-components/9591-ts-import-types/docgen.snapshot +21 -0
  100. package/template/stories/docgen-components/9591-ts-import-types/input.tsx +10 -0
  101. package/template/stories/docgen-components/9591-ts-import-types/properties.snapshot +21 -0
  102. package/template/stories/docgen-components/9626-js-default-values/argTypes.snapshot +27 -0
  103. package/template/stories/docgen-components/9626-js-default-values/docgen.snapshot +25 -0
  104. package/template/stories/docgen-components/9626-js-default-values/input.jsx +5 -0
  105. package/template/stories/docgen-components/9626-js-default-values/properties.snapshot +21 -0
  106. package/template/stories/docgen-components/9668-js-proptypes-no-jsdoc/argTypes.snapshot +42 -0
  107. package/template/stories/docgen-components/9668-js-proptypes-no-jsdoc/docgen.snapshot +36 -0
  108. package/template/stories/docgen-components/9668-js-proptypes-no-jsdoc/input.jsx +13 -0
  109. package/template/stories/docgen-components/9668-js-proptypes-no-jsdoc/properties.snapshot +35 -0
  110. package/template/stories/docgen-components/9721-ts-deprecated-jsdoc/argTypes.snapshot +53 -0
  111. package/template/stories/docgen-components/9721-ts-deprecated-jsdoc/docgen.snapshot +45 -0
  112. package/template/stories/docgen-components/9721-ts-deprecated-jsdoc/input.tsx +18 -0
  113. package/template/stories/docgen-components/9721-ts-deprecated-jsdoc/properties.snapshot +43 -0
  114. package/template/stories/docgen-components/9764-ts-extend-props/argTypes.snapshot +72 -0
  115. package/template/stories/docgen-components/9764-ts-extend-props/docgen.snapshot +41 -0
  116. package/template/stories/docgen-components/9764-ts-extend-props/input.tsx +17 -0
  117. package/template/stories/docgen-components/9764-ts-extend-props/properties.snapshot +56 -0
  118. package/template/stories/docgen-components/9827-ts-default-values/argTypes.snapshot +72 -0
  119. package/template/stories/docgen-components/9827-ts-default-values/docgen.snapshot +52 -0
  120. package/template/stories/docgen-components/9827-ts-default-values/input.tsx +17 -0
  121. package/template/stories/docgen-components/9827-ts-default-values/properties.snapshot +56 -0
  122. package/template/stories/docgen-components/9832-ts-enum-export/argTypes.snapshot +3 -0
  123. package/template/stories/docgen-components/9832-ts-enum-export/docgen.snapshot +16 -0
  124. package/template/stories/docgen-components/9832-ts-enum-export/input.tsx +8 -0
  125. package/template/stories/docgen-components/9832-ts-enum-export/properties.snapshot +7 -0
  126. package/template/stories/docgen-components/9922-ts-component-props/argTypes.snapshot +25 -0
  127. package/template/stories/docgen-components/9922-ts-component-props/docgen.snapshot +35 -0
  128. package/template/stories/docgen-components/9922-ts-component-props/input.tsx +24 -0
  129. package/template/stories/docgen-components/9922-ts-component-props/properties.snapshot +21 -0
  130. package/template/stories/docgen-components/imported.js +1 -0
  131. package/template/stories/docgen-components/js-class-component/argTypes.snapshot +386 -0
  132. package/template/stories/docgen-components/js-class-component/docgen.snapshot +252 -0
  133. package/template/stories/docgen-components/js-class-component/input.jsx +57 -0
  134. package/template/stories/docgen-components/js-class-component/properties.snapshot +286 -0
  135. package/template/stories/docgen-components/js-function-component/argTypes.snapshot +386 -0
  136. package/template/stories/docgen-components/js-function-component/docgen.snapshot +236 -0
  137. package/template/stories/docgen-components/js-function-component/input.jsx +50 -0
  138. package/template/stories/docgen-components/js-function-component/properties.snapshot +286 -0
  139. package/template/stories/docgen-components/js-function-component-inline-defaults/argTypes.snapshot +386 -0
  140. package/template/stories/docgen-components/js-function-component-inline-defaults/docgen.snapshot +247 -0
  141. package/template/stories/docgen-components/js-function-component-inline-defaults/input.jsx +65 -0
  142. package/template/stories/docgen-components/js-function-component-inline-defaults/properties.snapshot +286 -0
  143. package/template/stories/docgen-components/js-function-component-inline-defaults-no-propTypes/argTypes.snapshot +237 -0
  144. package/template/stories/docgen-components/js-function-component-inline-defaults-no-propTypes/docgen.snapshot +124 -0
  145. package/template/stories/docgen-components/js-function-component-inline-defaults-no-propTypes/input.jsx +41 -0
  146. package/template/stories/docgen-components/js-function-component-inline-defaults-no-propTypes/properties.snapshot +151 -0
  147. package/template/stories/docgen-components/js-proptypes/docgen.snapshot +1770 -0
  148. package/template/stories/docgen-components/js-proptypes/ext.js +13 -0
  149. package/template/stories/docgen-components/js-proptypes/input.jsx +497 -0
  150. package/template/stories/docgen-components/jsdoc/argTypes.snapshot +969 -0
  151. package/template/stories/docgen-components/jsdoc/docgen.snapshot +548 -0
  152. package/template/stories/docgen-components/jsdoc/input.jsx +231 -0
  153. package/template/stories/docgen-components/jsdoc/properties.snapshot +857 -0
  154. package/template/stories/docgen-components/ts-function-component/argTypes.snapshot +396 -0
  155. package/template/stories/docgen-components/ts-function-component/docgen.snapshot +241 -0
  156. package/template/stories/docgen-components/ts-function-component/input.tsx +52 -0
  157. package/template/stories/docgen-components/ts-function-component/properties.snapshot +296 -0
  158. package/template/stories/docgen-components/ts-function-component-inline-defaults/argTypes.snapshot +279 -0
  159. package/template/stories/docgen-components/ts-function-component-inline-defaults/docgen.snapshot +151 -0
  160. package/template/stories/docgen-components/ts-function-component-inline-defaults/input.tsx +80 -0
  161. package/template/stories/docgen-components/ts-function-component-inline-defaults/properties.snapshot +177 -0
  162. package/template/stories/docgen-components/ts-html/argTypes.snapshot +3 -0
  163. package/template/stories/docgen-components/ts-html/docgen.snapshot +12 -0
  164. package/template/stories/docgen-components/ts-html/input.tsx +12 -0
  165. package/template/stories/docgen-components/ts-html/properties.snapshot +7 -0
  166. package/template/stories/docgen-components/ts-jsdoc/argTypes.snapshot +3 -0
  167. package/template/stories/docgen-components/ts-jsdoc/docgen.snapshot +21 -0
  168. package/template/stories/docgen-components/ts-jsdoc/input.tsx +27 -0
  169. package/template/stories/docgen-components/ts-jsdoc/properties.snapshot +7 -0
  170. package/template/stories/docgen-components/ts-types/argTypes.snapshot +656 -0
  171. package/template/stories/docgen-components/ts-types/docgen.snapshot +317 -0
  172. package/template/stories/docgen-components/ts-types/input.tsx +130 -0
  173. package/template/stories/docgen-components/ts-types/properties.snapshot +410 -0
  174. package/template/stories/errors.stories.tsx +37 -0
  175. package/template/stories/hooks.stories.tsx +17 -0
  176. package/template/stories/js-argtypes.stories.jsx +91 -0
  177. package/template/stories/react-mdx.stories.mdx +26 -0
  178. package/template/stories/ts-argtypes.stories.tsx +81 -0
  179. package/LICENSE +0 -21
  180. package/dist/chunk-DGYCFUMN.mjs +0 -1
  181. package/dist/types-9f8d440a.d.ts +0 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react",
3
- "version": "7.0.0-alpha.7",
3
+ "version": "7.0.0-beta.0",
4
4
  "description": "Storybook React renderer",
5
5
  "keywords": [
6
6
  "storybook"
@@ -41,46 +41,48 @@
41
41
  "types": "dist/index.d.ts",
42
42
  "files": [
43
43
  "dist/**/*",
44
+ "template/**/*",
44
45
  "types/**/*",
45
46
  "README.md",
46
47
  "*.js",
47
48
  "*.d.ts"
48
49
  ],
49
50
  "scripts": {
50
- "prepare": "esrun ../../scripts/prepare/bundle.ts"
51
+ "check": "../../../scripts/node_modules/.bin/tsc --noEmit",
52
+ "prep": "../../../scripts/prepare/bundle.ts"
51
53
  },
52
54
  "dependencies": {
53
- "@storybook/addons": "7.0.0-alpha.7",
54
- "@storybook/client-logger": "7.0.0-alpha.7",
55
- "@storybook/core-client": "7.0.0-alpha.7",
56
- "@storybook/csf": "0.0.2--canary.4566f4d.1",
57
- "@storybook/docs-tools": "7.0.0-alpha.7",
58
- "@storybook/store": "7.0.0-alpha.7",
55
+ "@storybook/client-logger": "7.0.0-beta.0",
56
+ "@storybook/core-client": "7.0.0-beta.0",
57
+ "@storybook/docs-tools": "7.0.0-beta.0",
58
+ "@storybook/preview-api": "7.0.0-beta.0",
59
+ "@storybook/types": "7.0.0-beta.0",
59
60
  "@types/estree": "^0.0.51",
60
- "@types/node": "^14.14.20 || ^16.0.0",
61
+ "@types/node": "^16.0.0",
61
62
  "acorn": "^7.4.1",
62
63
  "acorn-jsx": "^5.3.1",
63
64
  "acorn-walk": "^7.2.0",
64
- "core-js": "^3.8.2",
65
65
  "escodegen": "^2.0.0",
66
66
  "global": "^4.4.0",
67
67
  "html-tags": "^3.1.0",
68
68
  "lodash": "^4.17.21",
69
69
  "prop-types": "^15.7.2",
70
- "react-element-to-jsx-string": "^14.3.4",
70
+ "react-element-to-jsx-string": "^15.0.0",
71
71
  "ts-dedent": "^2.0.0",
72
+ "type-fest": "^2.19.0",
72
73
  "util-deprecate": "^1.0.2"
73
74
  },
74
75
  "devDependencies": {
75
- "@babel/core": "^7.11.5",
76
- "@digitak/esrun": "^3.2.2",
77
- "@types/util-deprecate": "^1.0.0"
76
+ "@babel/core": "^7.20.2",
77
+ "@types/util-deprecate": "^1.0.0",
78
+ "expect-type": "^0.14.2",
79
+ "jest-specific-snapshot": "^7.0.0",
80
+ "require-from-string": "^2.0.2",
81
+ "typescript": "~4.9.3"
78
82
  },
79
83
  "peerDependencies": {
80
- "jest-specific-snapshot": "^4.0.0",
81
84
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
82
- "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
83
- "require-from-string": "^2.0.2"
85
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
84
86
  },
85
87
  "peerDependenciesMeta": {
86
88
  "typescript": {
@@ -93,9 +95,12 @@
93
95
  "publishConfig": {
94
96
  "access": "public"
95
97
  },
96
- "bundlerEntrypoint": [
97
- "./src/index.ts",
98
- "./src/config.ts"
99
- ],
100
- "gitHead": "d334cabd251cd0ed8b845a87707dc84f007d4074"
98
+ "bundler": {
99
+ "entries": [
100
+ "./src/index.ts",
101
+ "./src/config.ts"
102
+ ],
103
+ "platform": "browser"
104
+ },
105
+ "gitHead": "2e4ddde6a0a291266d91fe6a5ecda767bf119e70"
101
106
  }
@@ -0,0 +1,5 @@
1
+ {
2
+ "rules": {
3
+ "import/extensions": "off"
4
+ }
5
+ }
@@ -0,0 +1,50 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import './button.css';
4
+
5
+ /**
6
+ * Primary UI component for user interaction
7
+ */
8
+ export const Button = ({ primary, backgroundColor, size, label, ...props }) => {
9
+ const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
10
+ return (
11
+ <button
12
+ type="button"
13
+ className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
14
+ style={backgroundColor && { backgroundColor }}
15
+ {...props}
16
+ >
17
+ {label}
18
+ </button>
19
+ );
20
+ };
21
+
22
+ Button.propTypes = {
23
+ /**
24
+ * Is this the principal call to action on the page?
25
+ */
26
+ primary: PropTypes.bool,
27
+ /**
28
+ * What background color to use
29
+ */
30
+ backgroundColor: PropTypes.string,
31
+ /**
32
+ * How large should the button be?
33
+ */
34
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
35
+ /**
36
+ * Button contents
37
+ */
38
+ label: PropTypes.string.isRequired,
39
+ /**
40
+ * Optional click handler
41
+ */
42
+ onClick: PropTypes.func,
43
+ };
44
+
45
+ Button.defaultProps = {
46
+ backgroundColor: null,
47
+ primary: false,
48
+ size: 'medium',
49
+ onClick: undefined,
50
+ };
@@ -0,0 +1,39 @@
1
+ import { Button } from './Button';
2
+
3
+ // More on how to set up stories at: https://storybook.js.org/docs/7.0/react/writing-stories/introduction
4
+ export default {
5
+ title: 'Example/Button',
6
+ component: Button,
7
+ tags: ['docsPage'],
8
+ argTypes: {
9
+ backgroundColor: { control: 'color' },
10
+ },
11
+ };
12
+
13
+ // More on writing stories with args: https://storybook.js.org/docs/7.0/react/writing-stories/args
14
+ export const Primary = {
15
+ args: {
16
+ primary: true,
17
+ label: 'Button',
18
+ },
19
+ };
20
+
21
+ export const Secondary = {
22
+ args: {
23
+ label: 'Button',
24
+ },
25
+ };
26
+
27
+ export const Large = {
28
+ args: {
29
+ size: 'large',
30
+ label: 'Button',
31
+ },
32
+ };
33
+
34
+ export const Small = {
35
+ args: {
36
+ size: 'small',
37
+ label: 'Button',
38
+ },
39
+ };
@@ -0,0 +1,59 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+
4
+ import { Button } from './Button';
5
+ import './header.css';
6
+
7
+ export const Header = ({ user, onLogin, onLogout, onCreateAccount }) => (
8
+ <header>
9
+ <div className="wrapper">
10
+ <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
+ />
17
+ <path
18
+ d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
19
+ fill="#555AB9"
20
+ />
21
+ <path
22
+ d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
23
+ fill="#91BAF8"
24
+ />
25
+ </g>
26
+ </svg>
27
+ <h1>Acme</h1>
28
+ </div>
29
+ <div>
30
+ {user ? (
31
+ <>
32
+ <span className="welcome">
33
+ Welcome, <b>{user.name}</b>!
34
+ </span>
35
+ <Button size="small" onClick={onLogout} label="Log out" />
36
+ </>
37
+ ) : (
38
+ <>
39
+ <Button size="small" onClick={onLogin} label="Log in" />
40
+ <Button primary size="small" onClick={onCreateAccount} label="Sign up" />
41
+ </>
42
+ )}
43
+ </div>
44
+ </div>
45
+ </header>
46
+ );
47
+
48
+ Header.propTypes = {
49
+ user: PropTypes.shape({
50
+ name: PropTypes.string.isRequired,
51
+ }),
52
+ onLogin: PropTypes.func.isRequired,
53
+ onLogout: PropTypes.func.isRequired,
54
+ onCreateAccount: PropTypes.func.isRequired,
55
+ };
56
+
57
+ Header.defaultProps = {
58
+ user: null,
59
+ };
@@ -0,0 +1,22 @@
1
+ import { Header } from './Header';
2
+
3
+ export default {
4
+ title: 'Example/Header',
5
+ component: Header,
6
+ // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/react/writing-docs/docs-page
7
+ tags: ['docsPage'],
8
+ parameters: {
9
+ // More on how to position stories at: https://storybook.js.org/docs/7.0/react/configure/story-layout
10
+ layout: 'fullscreen',
11
+ },
12
+ };
13
+
14
+ export const LoggedIn = {
15
+ args: {
16
+ user: {
17
+ name: 'Jane Doe',
18
+ },
19
+ },
20
+ };
21
+
22
+ export const LoggedOut = {};
@@ -0,0 +1,69 @@
1
+ import React from 'react';
2
+
3
+ import { Header } from './Header';
4
+ import './page.css';
5
+
6
+ export const Page = () => {
7
+ const [user, setUser] = React.useState();
8
+
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
+ />
17
+
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
+ );
69
+ };
@@ -0,0 +1,25 @@
1
+ import { within, userEvent } from '@storybook/testing-library';
2
+
3
+ import { Page } from './Page';
4
+
5
+ export default {
6
+ title: 'Example/Page',
7
+ component: Page,
8
+ parameters: {
9
+ // More on how to position stories at: https://storybook.js.org/docs/7.0/react/configure/story-layout
10
+ layout: 'fullscreen',
11
+ },
12
+ };
13
+
14
+ export const LoggedOut = {};
15
+
16
+ // More on interaction testing: https://storybook.js.org/docs/7.0/react/writing-tests/interaction-testing
17
+ export const LoggedIn = {
18
+ play: async ({ canvasElement }) => {
19
+ const canvas = within(canvasElement);
20
+ const loginButton = await canvas.getByRole('button', {
21
+ name: /Log in/i,
22
+ });
23
+ await userEvent.click(loginButton);
24
+ },
25
+ };
@@ -0,0 +1,44 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+
3
+ import { Button } from './Button';
4
+
5
+ // More on how to set up stories at: https://storybook.js.org/docs/7.0/react/writing-stories/introduction
6
+ const meta = {
7
+ title: 'Example/Button',
8
+ component: Button,
9
+ tags: ['docsPage'],
10
+ argTypes: {
11
+ backgroundColor: { control: 'color' },
12
+ },
13
+ } satisfies Meta<typeof Button>;
14
+
15
+ export default meta;
16
+ type Story = StoryObj<typeof meta>;
17
+
18
+ // More on writing stories with args: https://storybook.js.org/docs/7.0/react/writing-stories/args
19
+ export const Primary: Story = {
20
+ args: {
21
+ primary: true,
22
+ label: 'Button',
23
+ },
24
+ };
25
+
26
+ export const Secondary: Story = {
27
+ args: {
28
+ label: 'Button',
29
+ },
30
+ };
31
+
32
+ export const Large: Story = {
33
+ args: {
34
+ size: 'large',
35
+ label: 'Button',
36
+ },
37
+ };
38
+
39
+ export const Small: Story = {
40
+ args: {
41
+ size: 'small',
42
+ label: 'Button',
43
+ },
44
+ };
@@ -0,0 +1,48 @@
1
+ import React from 'react';
2
+ import './button.css';
3
+
4
+ interface ButtonProps {
5
+ /**
6
+ * Is this the principal call to action on the page?
7
+ */
8
+ primary?: boolean;
9
+ /**
10
+ * What background color to use
11
+ */
12
+ backgroundColor?: string;
13
+ /**
14
+ * How large should the button be?
15
+ */
16
+ size?: 'small' | 'medium' | 'large';
17
+ /**
18
+ * Button contents
19
+ */
20
+ label: string;
21
+ /**
22
+ * Optional click handler
23
+ */
24
+ onClick?: () => void;
25
+ }
26
+
27
+ /**
28
+ * Primary UI component for user interaction
29
+ */
30
+ export const Button = ({
31
+ primary = false,
32
+ size = 'medium',
33
+ backgroundColor,
34
+ label,
35
+ ...props
36
+ }: ButtonProps) => {
37
+ const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
38
+ return (
39
+ <button
40
+ type="button"
41
+ className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
42
+ style={{ backgroundColor }}
43
+ {...props}
44
+ >
45
+ {label}
46
+ </button>
47
+ );
48
+ };
@@ -0,0 +1,26 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { Header } from './Header';
3
+
4
+ const meta = {
5
+ title: 'Example/Header',
6
+ component: Header,
7
+ // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/react/writing-docs/docs-page
8
+ tags: ['docsPage'],
9
+ parameters: {
10
+ // More on how to position stories at: https://storybook.js.org/docs/7.0/react/configure/story-layout
11
+ layout: 'fullscreen',
12
+ },
13
+ } satisfies Meta<typeof Header>;
14
+
15
+ export default meta;
16
+ type Story = StoryObj<typeof meta>;
17
+
18
+ export const LoggedIn: Story = {
19
+ args: {
20
+ user: {
21
+ name: 'Jane Doe',
22
+ },
23
+ },
24
+ };
25
+
26
+ export const LoggedOut: Story = {};
@@ -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
+ 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="wrapper">
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,29 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { within, userEvent } from '@storybook/testing-library';
3
+
4
+ import { Page } from './Page';
5
+
6
+ const meta = {
7
+ title: 'Example/Page',
8
+ component: Page,
9
+ parameters: {
10
+ // More on how to position stories at: https://storybook.js.org/docs/7.0/react/configure/story-layout
11
+ layout: 'fullscreen',
12
+ },
13
+ } satisfies Meta<typeof Page>;
14
+
15
+ export default meta;
16
+ type Story = StoryObj<typeof meta>;
17
+
18
+ export const LoggedOut: Story = {};
19
+
20
+ // More on interaction testing: https://storybook.js.org/docs/7.0/react/writing-tests/interaction-testing
21
+ export const LoggedIn: Story = {
22
+ play: async ({ canvasElement }) => {
23
+ const canvas = within(canvasElement);
24
+ const loginButton = await canvas.getByRole('button', {
25
+ name: /Log in/i,
26
+ });
27
+ await userEvent.click(loginButton);
28
+ },
29
+ };
@@ -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.VFC = () => {
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>
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
+ };