@storybook/react 7.0.0-alpha.54 → 7.0.0-alpha.55
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/dist/config.d.ts +3 -3
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1 -1
- package/dist/{types-7d102855.d.ts → types-0a347bb9.d.ts} +0 -0
- package/package.json +8 -8
- package/template/cli/ts/Button.stories.ts +3 -3
- package/template/cli/ts/Header.stories.ts +3 -3
- package/template/cli/ts/Page.stories.ts +3 -3
- package/template/cli/ts-legacy/Button.stories.ts +45 -0
- package/template/cli/ts-legacy/Button.tsx +48 -0
- package/template/cli/ts-legacy/Header.stories.ts +24 -0
- package/template/cli/ts-legacy/Header.tsx +56 -0
- package/template/cli/ts-legacy/Page.stories.ts +29 -0
- package/template/cli/ts-legacy/Page.tsx +73 -0
- package/template/stories/docgen-components/8428-js-static-prop-types/docgen.snapshot +3 -1
package/dist/config.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as lib_docs_tools_dist from 'lib/docs-tools/dist';
|
|
2
|
-
import { R as ReactRenderer, S as StoryFnReactReturnType } from './types-
|
|
2
|
+
import { R as ReactRenderer, S as StoryFnReactReturnType } from './types-0a347bb9.js';
|
|
3
3
|
import * as lib_types_dist from 'lib/types/dist';
|
|
4
|
-
import { ArgsStoryFn,
|
|
4
|
+
import { ArgsStoryFn, RenderContext } from '@storybook/types';
|
|
5
5
|
import 'react';
|
|
6
6
|
|
|
7
7
|
declare const decorators: ((storyFn: lib_types_dist.PartialStoryFn<ReactRenderer, lib_types_dist.Args>, context: lib_types_dist.StoryContext<ReactRenderer, lib_types_dist.Args>) => StoryFnReactReturnType)[];
|
|
8
8
|
declare const argTypesEnhancers: (<TRenderer extends lib_types_dist.Renderer>(context: lib_types_dist.StoryContextForEnhancers<TRenderer, lib_types_dist.Args>) => lib_types_dist.StrictArgTypes<lib_types_dist.Args>)[];
|
|
9
9
|
|
|
10
10
|
declare const render: ArgsStoryFn<ReactRenderer>;
|
|
11
|
-
declare function renderToCanvas({ storyContext, unboundStoryFn, showMain, showException, forceRemount, }:
|
|
11
|
+
declare function renderToCanvas({ storyContext, unboundStoryFn, showMain, showException, forceRemount, }: RenderContext<ReactRenderer>, canvasElement: ReactRenderer['canvasElement']): Promise<() => void>;
|
|
12
12
|
|
|
13
13
|
declare const parameters: {
|
|
14
14
|
docs: {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as _storybook_types from '@storybook/types';
|
|
2
|
-
import { Addon_ClientStoryApi, Addon_Loadable, Args, ComponentAnnotations, AnnotatedStoryFn, ArgsStoryFn, ArgsFromMeta, StoryAnnotations, DecoratorFunction, StrictArgs, LoaderFunction, StoryContext as StoryContext$1, ProjectAnnotations,
|
|
2
|
+
import { Addon_ClientStoryApi, Addon_Loadable, Args, ComponentAnnotations, AnnotatedStoryFn, ArgsStoryFn, ArgsFromMeta, StoryAnnotations, DecoratorFunction, StrictArgs, LoaderFunction, StoryContext as StoryContext$1, ProjectAnnotations, ComposedStory, Store_CSFExports, StoriesWithPartialProps } from '@storybook/types';
|
|
3
3
|
export { ArgTypes, Args, Parameters, StrictArgs } from '@storybook/types';
|
|
4
|
-
import { R as ReactRenderer, S as StoryFnReactReturnType } from './types-
|
|
5
|
-
export { R as ReactRenderer } from './types-
|
|
4
|
+
import { R as ReactRenderer, S as StoryFnReactReturnType } from './types-0a347bb9.js';
|
|
5
|
+
export { R as ReactRenderer } from './types-0a347bb9.js';
|
|
6
6
|
import { ComponentType, ComponentProps, JSXElementConstructor } from 'react';
|
|
7
7
|
import { Simplify, SetOptional } from 'type-fest';
|
|
8
8
|
|
|
@@ -156,11 +156,11 @@ declare function setGlobalConfig(projectAnnotations: ProjectAnnotations<ReactRen
|
|
|
156
156
|
* @param [projectAnnotations] - e.g. (import * as projectAnnotations from '../.storybook/preview') this can be applied automatically if you use `setProjectAnnotations` in your setup files.
|
|
157
157
|
* @param [exportsName] - in case your story does not contain a name and you want it to have a name.
|
|
158
158
|
*/
|
|
159
|
-
declare function composeStory<TArgs extends Args = Args>(story:
|
|
159
|
+
declare function composeStory<TArgs extends Args = Args>(story: ComposedStory<ReactRenderer, TArgs>, componentAnnotations: Meta<TArgs | any>, projectAnnotations?: ProjectAnnotations<ReactRenderer>, exportsName?: string): {
|
|
160
160
|
(extraArgs: Partial<TArgs>): StoryFnReactReturnType;
|
|
161
161
|
storyName: string;
|
|
162
162
|
args: Args;
|
|
163
|
-
play: _storybook_types.
|
|
163
|
+
play: _storybook_types.ComposedStoryPlayFn;
|
|
164
164
|
parameters: _storybook_types.Parameters;
|
|
165
165
|
};
|
|
166
166
|
/**
|
|
@@ -188,6 +188,6 @@ declare function composeStory<TArgs extends Args = Args>(story: Store_ComposedSt
|
|
|
188
188
|
* @param csfExports - e.g. (import * as stories from './Button.stories')
|
|
189
189
|
* @param [projectAnnotations] - e.g. (import * as projectAnnotations from '../.storybook/preview') this can be applied automatically if you use `setProjectAnnotations` in your setup files.
|
|
190
190
|
*/
|
|
191
|
-
declare function composeStories<TModule extends Store_CSFExports<ReactRenderer>>(csfExports: TModule, projectAnnotations?: ProjectAnnotations<ReactRenderer>): Omit<
|
|
191
|
+
declare function composeStories<TModule extends Store_CSFExports<ReactRenderer>>(csfExports: TModule, projectAnnotations?: ProjectAnnotations<ReactRenderer>): Omit<StoriesWithPartialProps<ReactRenderer, TModule>, keyof Store_CSFExports<_storybook_types.Renderer>>;
|
|
192
192
|
|
|
193
193
|
export { ComponentMeta, ComponentStory, ComponentStoryFn, ComponentStoryObj, Decorator, DecoratorFn, Loader, Meta, Story, StoryContext, StoryFn, StoryObj, composeStories, composeStory, configure, forceReRender, raw, setGlobalConfig, setProjectAnnotations, storiesOf };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var k=Object.create;var d=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var L=(e,t)=>{for(var o in t)d(e,o,{get:t[o],enumerable:!0})},A=(e,t,o,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of W(t))!_.call(e,s)&&s!==o&&d(e,s,{get:()=>t[s],enumerable:!(r=D(t,s))||r.enumerable});return e};var p=(e,t,o)=>(o=e!=null?k(U(e)):{},A(t||!e||!e.__esModule?d(o,"default",{value:e,enumerable:!0}):o,e)),N=e=>A(d({},"__esModule",{value:!0}),e);var Z={};L(Z,{composeStories:()=>X,composeStory:()=>v,configure:()=>q,forceReRender:()=>z,raw:()=>H,setGlobalConfig:()=>J,setProjectAnnotations:()=>M,storiesOf:()=>$});module.exports=N(Z);var g=p(require("global")),{window:C}=g.default;C&&(C.STORYBOOK_ENV="react");var P=require("@storybook/preview-api");var S=p(require("global")),n=p(require("react")),i=p(require("react-dom")),{FRAMEWORK_OPTIONS:a}=S.default,m=new Map,R=(e,t)=>{let{id:o,component:r}=t;if(!r)throw new Error(`Unable to render story ${o} as the component annotation is missing from the default export`);return n.default.createElement(r,{...e})},G=({callback:e,children:t})=>{let o=(0,n.useRef)();return(0,n.useLayoutEffect)(()=>{o.current!==e&&(o.current=e,e())},[e]),t},V=async(e,t)=>{let o=await Y(t);return new Promise(r=>{o?o.render(n.default.createElement(G,{callback:()=>r(null)},e)):i.default.render(e,t,()=>r(null))})},B=i.version&&(i.version.startsWith("18")||i.version.startsWith("0.0.0")),O=(a==null?void 0:a.legacyRootApi)!==!0,w=O&&B,h=e=>{let t=m.get(e);t&&w?(t.unmount(),m.delete(e)):i.default.unmountComponentAtNode(e)},Y=async e=>{if(!w)return null;let t=m.get(e);return t||(t=(await import("react-dom/client")).default.createRoot(e),m.set(e,t)),t},u=class extends n.Component{constructor(){super(...arguments);this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}componentDidMount(){let{hasError:o}=this.state,{showMain:r}=this.props;o||r()}componentDidCatch(o){let{showException:r}=this.props;r(o)}render(){let{hasError:o}=this.state,{children:r}=this.props;return o?null:r}},x=a!=null&&a.strictMode?n.StrictMode:n.Fragment;async function E({storyContext:e,unboundStoryFn:t,showMain:o,showException:r,forceRemount:s},f){let y=n.default.createElement(u,{showMain:o,showException:r},n.default.createElement(t,{...e})),T=x?n.default.createElement(x,null,y):y;return s&&h(f),await V(T,f),()=>h(f)}var b="react",l=(0,P.start)(E,{render:R}),$=(e,t)=>l.clientApi.storiesOf(e,t).addParameters({framework:b}),q=(...e)=>l.configure(b,...e),z=l.forceReRender,H=l.clientApi.raw;var c=require("@storybook/preview-api"),j=require("@storybook/client-logger");function M(e){(0,c.setProjectAnnotations)(e)}function J(e){(0,j.deprecate)("setGlobalConfig is deprecated. Use setProjectAnnotations instead."),M(e)}var Q={render:R};function v(e,t,o,r){return(0,c.composeStory)(e,t,o,Q,r)}function X(e,t){return(0,c.composeStories)(e,t,v)}var F;(F=module==null?void 0:module.hot)==null||F.decline();0&&(module.exports={composeStories,composeStory,configure,forceReRender,raw,setGlobalConfig,setProjectAnnotations,storiesOf});
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/react",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.55",
|
|
4
4
|
"description": "Storybook React renderer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"prep": "../../../scripts/prepare/bundle.ts"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@storybook/client-logger": "7.0.0-alpha.
|
|
56
|
-
"@storybook/core-client": "7.0.0-alpha.
|
|
57
|
-
"@storybook/docs-tools": "7.0.0-alpha.
|
|
58
|
-
"@storybook/preview-api": "7.0.0-alpha.
|
|
59
|
-
"@storybook/types": "7.0.0-alpha.
|
|
55
|
+
"@storybook/client-logger": "7.0.0-alpha.55",
|
|
56
|
+
"@storybook/core-client": "7.0.0-alpha.55",
|
|
57
|
+
"@storybook/docs-tools": "7.0.0-alpha.55",
|
|
58
|
+
"@storybook/preview-api": "7.0.0-alpha.55",
|
|
59
|
+
"@storybook/types": "7.0.0-alpha.55",
|
|
60
60
|
"@types/estree": "^0.0.51",
|
|
61
61
|
"@types/node": "^16.0.0",
|
|
62
62
|
"acorn": "^7.4.1",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"@babel/core": "^7.20.2",
|
|
77
77
|
"@types/util-deprecate": "^1.0.0",
|
|
78
78
|
"expect-type": "^0.14.2",
|
|
79
|
-
"jest-specific-snapshot": "^
|
|
79
|
+
"jest-specific-snapshot": "^7.0.0",
|
|
80
80
|
"require-from-string": "^2.0.2",
|
|
81
81
|
"typescript": "^4.9.3"
|
|
82
82
|
},
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
],
|
|
103
103
|
"platform": "browser"
|
|
104
104
|
},
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "55cd2ab63d1f897de59e2471d2f916f7d2c13546"
|
|
106
106
|
}
|
|
@@ -3,17 +3,17 @@ import type { Meta, StoryObj } from '@storybook/react';
|
|
|
3
3
|
import { Button } from './Button';
|
|
4
4
|
|
|
5
5
|
// More on how to set up stories at: https://storybook.js.org/docs/7.0/react/writing-stories/introduction
|
|
6
|
-
const meta
|
|
6
|
+
const meta = {
|
|
7
7
|
title: 'Example/Button',
|
|
8
8
|
component: Button,
|
|
9
9
|
tags: ['docsPage'],
|
|
10
10
|
argTypes: {
|
|
11
11
|
backgroundColor: { control: 'color' },
|
|
12
12
|
},
|
|
13
|
-
}
|
|
13
|
+
} satisfies Meta<typeof Button>;
|
|
14
14
|
|
|
15
15
|
export default meta;
|
|
16
|
-
type Story = StoryObj<typeof
|
|
16
|
+
type Story = StoryObj<typeof meta>;
|
|
17
17
|
|
|
18
18
|
// More on writing stories with args: https://storybook.js.org/docs/7.0/react/writing-stories/args
|
|
19
19
|
export const Primary: Story = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
2
|
import { Header } from './Header';
|
|
3
3
|
|
|
4
|
-
const meta
|
|
4
|
+
const meta = {
|
|
5
5
|
title: 'Example/Header',
|
|
6
6
|
component: Header,
|
|
7
7
|
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/7.0/react/writing-docs/docs-page
|
|
@@ -10,10 +10,10 @@ const meta: Meta<typeof Header> = {
|
|
|
10
10
|
// More on how to position stories at: https://storybook.js.org/docs/7.0/react/configure/story-layout
|
|
11
11
|
layout: 'fullscreen',
|
|
12
12
|
},
|
|
13
|
-
}
|
|
13
|
+
} satisfies Meta<typeof Header>;
|
|
14
14
|
|
|
15
15
|
export default meta;
|
|
16
|
-
type Story = StoryObj<typeof
|
|
16
|
+
type Story = StoryObj<typeof meta>;
|
|
17
17
|
|
|
18
18
|
export const LoggedIn: Story = {
|
|
19
19
|
args: {
|
|
@@ -3,17 +3,17 @@ import { within, userEvent } from '@storybook/testing-library';
|
|
|
3
3
|
|
|
4
4
|
import { Page } from './Page';
|
|
5
5
|
|
|
6
|
-
const meta
|
|
6
|
+
const meta = {
|
|
7
7
|
title: 'Example/Page',
|
|
8
8
|
component: Page,
|
|
9
9
|
parameters: {
|
|
10
10
|
// More on how to position stories at: https://storybook.js.org/docs/7.0/react/configure/story-layout
|
|
11
11
|
layout: 'fullscreen',
|
|
12
12
|
},
|
|
13
|
-
}
|
|
13
|
+
} satisfies Meta<typeof Page>;
|
|
14
14
|
|
|
15
15
|
export default meta;
|
|
16
|
-
type Story = StoryObj<typeof
|
|
16
|
+
type Story = StoryObj<typeof meta>;
|
|
17
17
|
|
|
18
18
|
export const LoggedOut: Story = {};
|
|
19
19
|
|
|
@@ -0,0 +1,45 @@
|
|
|
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/react/writing-stories/introduction#default-export
|
|
6
|
+
const meta: Meta<typeof Button> = {
|
|
7
|
+
title: 'Example/Button',
|
|
8
|
+
component: Button,
|
|
9
|
+
// More on argTypes: https://storybook.js.org/docs/react/api/argtypes
|
|
10
|
+
argTypes: {
|
|
11
|
+
backgroundColor: { control: 'color' },
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default meta;
|
|
16
|
+
type Story = StoryObj<typeof Button>;
|
|
17
|
+
|
|
18
|
+
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
|
|
19
|
+
export const Primary: Story = {
|
|
20
|
+
// More on args: https://storybook.js.org/docs/react/writing-stories/args
|
|
21
|
+
args: {
|
|
22
|
+
primary: true,
|
|
23
|
+
label: 'Button',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const Secondary: Story = {
|
|
28
|
+
args: {
|
|
29
|
+
label: 'Button',
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const Large: Story = {
|
|
34
|
+
args: {
|
|
35
|
+
size: 'large',
|
|
36
|
+
label: 'Button',
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const Small: Story = {
|
|
41
|
+
args: {
|
|
42
|
+
size: 'small',
|
|
43
|
+
label: 'Button',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
@@ -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,24 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import { Header } from './Header';
|
|
3
|
+
|
|
4
|
+
const meta: Meta<typeof Header> = {
|
|
5
|
+
title: 'Example/Header',
|
|
6
|
+
component: Header,
|
|
7
|
+
parameters: {
|
|
8
|
+
// More on Story layout: https://storybook.js.org/docs/react/configure/story-layout
|
|
9
|
+
layout: 'fullscreen',
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default meta;
|
|
14
|
+
type Story = StoryObj<typeof Header>;
|
|
15
|
+
|
|
16
|
+
export const LoggedIn: Story = {
|
|
17
|
+
args: {
|
|
18
|
+
user: {
|
|
19
|
+
name: 'Jane Doe',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
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: Meta<typeof Page> = {
|
|
7
|
+
title: 'Example/Page',
|
|
8
|
+
component: Page,
|
|
9
|
+
parameters: {
|
|
10
|
+
// More on Story layout: https://storybook.js.org/docs/react/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/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="renderers/react/template/cli/ts/Page" 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
|
+
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`react component properties 8428-js-static-prop-types 1`] = `
|
|
4
|
-
"function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
"function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, \\"string\\"); return typeof key === \\"symbol\\" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (typeof input !== \\"object\\" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || \\"default\\"); if (typeof res !== \\"object\\") return res; throw new TypeError(\\"@@toPrimitive must return a primitive value.\\"); } return (hint === \\"string\\" ? String : Number)(input); }
|
|
5
7
|
/* eslint-disable react/no-unused-prop-types */
|
|
6
8
|
/* eslint-disable react/require-default-props */
|
|
7
9
|
import React from 'react';
|