@storybook/preact 0.0.0-pr-23609-sha-f47ef339

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/README.md ADDED
@@ -0,0 +1 @@
1
+ # Storybook Preact renderer
@@ -0,0 +1,9 @@
1
+ import * as preact from 'preact';
2
+ import { dedent } from 'ts-dedent';
3
+
4
+ var {h:h2}=preact,render2=(args,context)=>{let{id,component:Component}=context;if(!Component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);return h2(Component,{...args})},renderedStory;function preactRender(story,canvasElement){preact.Fragment?preact.render(story,canvasElement):renderedStory=preact.render(story,canvasElement,renderedStory);}var StoryHarness=({showError,name,title,storyFn,canvasElement})=>{let content=preact.h(storyFn,null);return content||(showError({title:`Expecting a Preact element from the story: "${name}" of "${title}".`,description:dedent`
5
+ Did you forget to return the Preact element from the story?
6
+ Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
7
+ `}),null)};function renderToCanvas({storyFn,title,name,showMain,showError,forceRemount},canvasElement){forceRemount&&preactRender(null,canvasElement),showMain(),preactRender(preact.h(StoryHarness,{name,title,showError,storyFn,canvasElement}),canvasElement);}
8
+
9
+ export { render2 as render, renderToCanvas };
@@ -0,0 +1,10 @@
1
+ import { ArgsStoryFn, RenderContext } from '@storybook/types';
2
+ import { P as PreactRenderer } from './types-dbc033aa.js';
3
+ import 'preact';
4
+
5
+ declare const render: ArgsStoryFn<PreactRenderer>;
6
+ declare function renderToCanvas({ storyFn, title, name, showMain, showError, forceRemount }: RenderContext<PreactRenderer>, canvasElement: PreactRenderer['canvasElement']): void;
7
+
8
+ declare const parameters: {};
9
+
10
+ export { parameters, render, renderToCanvas };
package/dist/config.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var config_exports={};__export(config_exports,{parameters:()=>parameters2,render:()=>render2,renderToCanvas:()=>renderToCanvas});module.exports=__toCommonJS(config_exports);var parameters={docs:{story:{inline:!0}}};var preact=__toESM(require("preact")),import_ts_dedent=require("ts-dedent"),{h:h2}=preact,render2=(args,context)=>{let{id,component:Component}=context;if(!Component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);return h2(Component,{...args})},renderedStory;function preactRender(story,canvasElement){preact.Fragment?preact.render(story,canvasElement):renderedStory=preact.render(story,canvasElement,renderedStory)}var StoryHarness=({showError,name,title,storyFn,canvasElement})=>{let content=preact.h(storyFn,null);return content||(showError({title:`Expecting a Preact element from the story: "${name}" of "${title}".`,description:import_ts_dedent.dedent`
2
+ Did you forget to return the Preact element from the story?
3
+ Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
4
+ `}),null)};function renderToCanvas({storyFn,title,name,showMain,showError,forceRemount},canvasElement){forceRemount&&preactRender(null,canvasElement),showMain(),preactRender(preact.h(StoryHarness,{name,title,showError,storyFn,canvasElement}),canvasElement)}var parameters2={renderer:"preact",...parameters};0&&(module.exports={parameters,render,renderToCanvas});
@@ -0,0 +1,5 @@
1
+ export { render, renderToCanvas } from './chunk-OHNM7E4P.mjs';
2
+
3
+ var parameters={docs:{story:{inline:!0}}};var parameters2={renderer:"preact",...parameters};
4
+
5
+ export { parameters2 as parameters };
@@ -0,0 +1,50 @@
1
+ import { Addon_ClientStoryApi, Addon_Loadable, Args, ComponentAnnotations, AnnotatedStoryFn, StoryAnnotations, StrictArgs, DecoratorFunction, LoaderFunction, StoryContext as StoryContext$1, ProjectAnnotations } from '@storybook/types';
2
+ export { ArgTypes, Args, Parameters, StrictArgs } from '@storybook/types';
3
+ import { P as PreactRenderer } from './types-dbc033aa.js';
4
+ import 'preact';
5
+
6
+ interface ClientApi extends Addon_ClientStoryApi<PreactRenderer['storyResult']> {
7
+ configure(loader: Addon_Loadable, module: NodeModule): void;
8
+ forceReRender(): void;
9
+ raw: () => any;
10
+ load: (...args: any[]) => void;
11
+ }
12
+ declare const storiesOf: ClientApi['storiesOf'];
13
+ declare const configure: ClientApi['configure'];
14
+ declare const forceReRender: ClientApi['forceReRender'];
15
+ declare const raw: ClientApi['raw'];
16
+
17
+ /**
18
+ * Metadata to configure the stories for a component.
19
+ *
20
+ * @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
21
+ */
22
+ type Meta<TArgs = Args> = ComponentAnnotations<PreactRenderer, TArgs>;
23
+ /**
24
+ * Story function that represents a CSFv2 component example.
25
+ *
26
+ * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
27
+ */
28
+ type StoryFn<TArgs = Args> = AnnotatedStoryFn<PreactRenderer, TArgs>;
29
+ /**
30
+ * Story function that represents a CSFv3 component example.
31
+ *
32
+ * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
33
+ */
34
+ type StoryObj<TArgs = Args> = StoryAnnotations<PreactRenderer, TArgs>;
35
+ /**
36
+ * @deprecated Use `StoryFn` instead.
37
+ * Use `StoryObj` if you want to migrate to CSF3, which uses objects instead of functions to represent stories.
38
+ * You can read more about the CSF3 format here: https://storybook.js.org/blog/component-story-format-3-0/
39
+ *
40
+ * Story function that represents a CSFv2 component example.
41
+ *
42
+ * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
43
+ */
44
+ type Story<TArgs = Args> = StoryFn<TArgs>;
45
+ type Decorator<TArgs = StrictArgs> = DecoratorFunction<PreactRenderer, TArgs>;
46
+ type Loader<TArgs = StrictArgs> = LoaderFunction<PreactRenderer, TArgs>;
47
+ type StoryContext<TArgs = StrictArgs> = StoryContext$1<PreactRenderer, TArgs>;
48
+ type Preview = ProjectAnnotations<PreactRenderer>;
49
+
50
+ export { ClientApi, Decorator, Loader, Meta, PreactRenderer, Preview, Story, StoryContext, StoryFn, StoryObj, configure, forceReRender, raw, storiesOf };
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var src_exports={};__export(src_exports,{configure:()=>configure,forceReRender:()=>forceReRender,raw:()=>raw,storiesOf:()=>storiesOf});module.exports=__toCommonJS(src_exports);var import_global=require("@storybook/global"),{window:globalWindow}=import_global.global;globalWindow&&(globalWindow.STORYBOOK_ENV="preact");var import_preview_api=require("@storybook/preview-api");var preact=__toESM(require("preact")),import_ts_dedent=require("ts-dedent"),{h:h2}=preact;var renderedStory;function preactRender(story,canvasElement){preact.Fragment?preact.render(story,canvasElement):renderedStory=preact.render(story,canvasElement,renderedStory)}var StoryHarness=({showError,name,title,storyFn,canvasElement})=>{let content=preact.h(storyFn,null);return content||(showError({title:`Expecting a Preact element from the story: "${name}" of "${title}".`,description:import_ts_dedent.dedent`
2
+ Did you forget to return the Preact element from the story?
3
+ Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
4
+ `}),null)};function renderToCanvas({storyFn,title,name,showMain,showError,forceRemount},canvasElement){forceRemount&&preactRender(null,canvasElement),showMain(),preactRender(preact.h(StoryHarness,{name,title,showError,storyFn,canvasElement}),canvasElement)}var RENDERER="preact",api=(0,import_preview_api.start)(renderToCanvas),storiesOf=(kind,m)=>api.clientApi.storiesOf(kind,m).addParameters({renderer:RENDERER}),configure=(...args)=>api.configure(RENDERER,...args),forceReRender=api.forceReRender,raw=api.clientApi.raw;var _a;typeof module<"u"&&((_a=module==null?void 0:module.hot)==null||_a.decline());0&&(module.exports={configure,forceReRender,raw,storiesOf});
package/dist/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ import { renderToCanvas } from './chunk-OHNM7E4P.mjs';
2
+ import { global } from '@storybook/global';
3
+ import { start } from '@storybook/preview-api';
4
+
5
+ var{window:globalWindow}=global;globalWindow&&(globalWindow.STORYBOOK_ENV="preact");var RENDERER="preact",api=start(renderToCanvas),storiesOf=(kind,m)=>api.clientApi.storiesOf(kind,m).addParameters({renderer:RENDERER}),configure=(...args)=>api.configure(RENDERER,...args),forceReRender=api.forceReRender,raw=api.clientApi.raw;typeof module<"u"&&module?.hot?.decline();
6
+
7
+ export { configure, forceReRender, raw, storiesOf };
@@ -0,0 +1,10 @@
1
+ import { WebRenderer } from '@storybook/types';
2
+ import { AnyComponent } from 'preact';
3
+
4
+ type StoryFnPreactReturnType = string | Node | preact.JSX.Element;
5
+ interface PreactRenderer extends WebRenderer {
6
+ component: AnyComponent<any, any>;
7
+ storyResult: StoryFnPreactReturnType;
8
+ }
9
+
10
+ export { PreactRenderer as P };
package/jest.config.js ADDED
@@ -0,0 +1,7 @@
1
+ const path = require('path');
2
+ const baseConfig = require('../../jest.config.browser');
3
+
4
+ module.exports = {
5
+ ...baseConfig,
6
+ displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
7
+ };
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@storybook/preact",
3
+ "version": "0.0.0-pr-23609-sha-f47ef339",
4
+ "description": "Storybook Preact renderer",
5
+ "keywords": [
6
+ "storybook"
7
+ ],
8
+ "homepage": "https://github.com/storybookjs/storybook/tree/next/code/renderers/preact",
9
+ "bugs": {
10
+ "url": "https://github.com/storybookjs/storybook/issues"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/storybookjs/storybook.git",
15
+ "directory": "code/renderers/preact"
16
+ },
17
+ "funding": {
18
+ "type": "opencollective",
19
+ "url": "https://opencollective.com/storybook"
20
+ },
21
+ "license": "MIT",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "node": "./dist/index.js",
26
+ "require": "./dist/index.js",
27
+ "import": "./dist/index.mjs"
28
+ },
29
+ "./preview": {
30
+ "types": "./dist/config.d.ts",
31
+ "require": "./dist/config.js",
32
+ "import": "./dist/config.mjs"
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "main": "dist/index.js",
37
+ "module": "dist/index.mjs",
38
+ "types": "dist/index.d.ts",
39
+ "files": [
40
+ "dist/**/*",
41
+ "template/**/*",
42
+ "README.md",
43
+ "*.js",
44
+ "*.d.ts"
45
+ ],
46
+ "scripts": {
47
+ "check": "../../../scripts/prepare/check.ts",
48
+ "prep": "../../../scripts/prepare/bundle.ts"
49
+ },
50
+ "dependencies": {
51
+ "@storybook/core-client": "0.0.0-pr-23609-sha-f47ef339",
52
+ "@storybook/global": "^5.0.0",
53
+ "@storybook/preview-api": "0.0.0-pr-23609-sha-f47ef339",
54
+ "@storybook/types": "0.0.0-pr-23609-sha-f47ef339",
55
+ "ts-dedent": "^2.0.0"
56
+ },
57
+ "devDependencies": {
58
+ "preact": "^10.5.13",
59
+ "typescript": "~4.9.3"
60
+ },
61
+ "peerDependencies": {
62
+ "preact": "^8.0.0||^10.0.0"
63
+ },
64
+ "engines": {
65
+ "node": ">=16.0.0"
66
+ },
67
+ "publishConfig": {
68
+ "access": "public"
69
+ },
70
+ "bundler": {
71
+ "entries": [
72
+ "./src/index.ts",
73
+ "./src/config.ts"
74
+ ],
75
+ "platform": "browser"
76
+ },
77
+ "gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae17"
78
+ }
package/preview.js ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/config';
@@ -0,0 +1 @@
1
+ declare var STORYBOOK_ENV: 'preact';
@@ -0,0 +1,7 @@
1
+ {
2
+ "rules": {
3
+ "import/extensions": "off",
4
+ "react/react-in-jsx-scope": "off",
5
+ "import/no-extraneous-dependencies": "off"
6
+ }
7
+ }
@@ -0,0 +1,49 @@
1
+ import PropTypes from 'prop-types';
2
+ import './button.css';
3
+
4
+ /**
5
+ * Primary UI component for user interaction
6
+ */
7
+ export const Button = ({ primary, backgroundColor, size, label, ...props }) => {
8
+ const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
9
+ return (
10
+ <button
11
+ type="button"
12
+ className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
13
+ style={backgroundColor && { backgroundColor }}
14
+ {...props}
15
+ >
16
+ {label}
17
+ </button>
18
+ );
19
+ };
20
+
21
+ Button.propTypes = {
22
+ /**
23
+ * Is this the principal call to action on the page?
24
+ */
25
+ primary: PropTypes.bool,
26
+ /**
27
+ * What background color to use
28
+ */
29
+ backgroundColor: PropTypes.string,
30
+ /**
31
+ * How large should the button be?
32
+ */
33
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
34
+ /**
35
+ * Button contents
36
+ */
37
+ label: PropTypes.string.isRequired,
38
+ /**
39
+ * Optional click handler
40
+ */
41
+ onClick: PropTypes.func,
42
+ };
43
+
44
+ Button.defaultProps = {
45
+ backgroundColor: null,
46
+ primary: false,
47
+ size: 'medium',
48
+ onClick: undefined,
49
+ };
@@ -0,0 +1,40 @@
1
+ import { Button } from './Button';
2
+
3
+ // More on how to set up stories at: https://storybook.js.org/docs/preact/writing-stories/introduction
4
+ export default {
5
+ title: 'Example/Button',
6
+ component: Button,
7
+ tags: ['autodocs'],
8
+ argTypes: {
9
+ backgroundColor: { control: 'color' },
10
+ onClick: { action: 'onClick' },
11
+ },
12
+ };
13
+
14
+ // More on writing stories with args: https://storybook.js.org/docs/preact/writing-stories/args
15
+ export const Primary = {
16
+ args: {
17
+ primary: true,
18
+ label: 'Button',
19
+ },
20
+ };
21
+
22
+ export const Secondary = {
23
+ args: {
24
+ label: 'Button',
25
+ },
26
+ };
27
+
28
+ export const Large = {
29
+ args: {
30
+ size: 'large',
31
+ label: 'Button',
32
+ },
33
+ };
34
+
35
+ export const Small = {
36
+ args: {
37
+ size: 'small',
38
+ label: 'Button',
39
+ },
40
+ };
@@ -0,0 +1,58 @@
1
+ import PropTypes from 'prop-types';
2
+
3
+ import { Button } from './Button';
4
+ import './header.css';
5
+
6
+ export const Header = ({ user, onLogin, onLogout, onCreateAccount }) => (
7
+ <header>
8
+ <div className="storybook-header">
9
+ <div>
10
+ <svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
11
+ <g fill="none" fillRule="evenodd">
12
+ <path
13
+ d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
14
+ fill="#FFF"
15
+ />
16
+ <path
17
+ d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
18
+ fill="#555AB9"
19
+ />
20
+ <path
21
+ d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
22
+ fill="#91BAF8"
23
+ />
24
+ </g>
25
+ </svg>
26
+ <h1>Acme</h1>
27
+ </div>
28
+ <div>
29
+ {user ? (
30
+ <>
31
+ <span className="welcome">
32
+ Welcome, <b>{user.name}</b>!
33
+ </span>
34
+ <Button size="small" onClick={onLogout} label="Log out" />
35
+ </>
36
+ ) : (
37
+ <>
38
+ <Button size="small" onClick={onLogin} label="Log in" />
39
+ <Button primary size="small" onClick={onCreateAccount} label="Sign up" />
40
+ </>
41
+ )}
42
+ </div>
43
+ </div>
44
+ </header>
45
+ );
46
+
47
+ Header.propTypes = {
48
+ user: PropTypes.shape({
49
+ name: PropTypes.string.isRequired,
50
+ }),
51
+ onLogin: PropTypes.func.isRequired,
52
+ onLogout: PropTypes.func.isRequired,
53
+ onCreateAccount: PropTypes.func.isRequired,
54
+ };
55
+
56
+ Header.defaultProps = {
57
+ user: null,
58
+ };
@@ -0,0 +1,27 @@
1
+ import { Header } from './Header';
2
+
3
+ export default {
4
+ title: 'Example/Header',
5
+ component: Header,
6
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/preact/writing-docs/autodocs
7
+ tags: ['autodocs'],
8
+ parameters: {
9
+ // More on how to position stories at: https://storybook.js.org/docs/preact/configure/story-layout
10
+ layout: 'fullscreen',
11
+ },
12
+ argTypes: {
13
+ onLogin: { action: 'onLogin' },
14
+ onLogout: { action: 'onLogout' },
15
+ onCreateAccount: { action: 'onCreateAccount' },
16
+ },
17
+ };
18
+
19
+ export const LoggedIn = {
20
+ args: {
21
+ user: {
22
+ name: 'Jane Doe',
23
+ },
24
+ },
25
+ };
26
+
27
+ export const LoggedOut = {};
@@ -0,0 +1,68 @@
1
+ import { useState } from 'preact/hooks';
2
+ import { Header } from './Header';
3
+ import './page.css';
4
+
5
+ export const Page = () => {
6
+ const [user, setUser] = useState();
7
+
8
+ return (
9
+ <article>
10
+ <Header
11
+ user={user}
12
+ onLogin={() => setUser({ name: 'Jane Doe' })}
13
+ onLogout={() => setUser(undefined)}
14
+ onCreateAccount={() => setUser({ name: 'Jane Doe' })}
15
+ />
16
+
17
+ <section className="storybook-page">
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
29
+ data 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
+ );
68
+ };
@@ -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/preact/configure/story-layout
10
+ layout: 'fullscreen',
11
+ },
12
+ };
13
+
14
+ export const LoggedOut = {};
15
+
16
+ // More on interaction testing: https://storybook.js.org/docs/preact/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,14 @@
1
+ /* eslint-disable react/react-in-jsx-scope */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+ import PropTypes from 'prop-types';
4
+
5
+ export const Button = ({ onClick, label }) => (
6
+ <button type="button" onClick={onClick}>
7
+ {label}
8
+ </button>
9
+ );
10
+
11
+ Button.propTypes = {
12
+ onClick: PropTypes.func.isRequired,
13
+ label: PropTypes.node.isRequired,
14
+ };
@@ -0,0 +1,38 @@
1
+ /* eslint-disable react/react-in-jsx-scope */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+ import PropTypes from 'prop-types';
4
+ import { useState } from 'preact/hooks';
5
+
6
+ export const Form = ({ onSuccess }) => {
7
+ const [value, setValue] = useState('');
8
+ const [complete, setComplete] = useState(false);
9
+
10
+ function onSubmit(event) {
11
+ event.preventDefault();
12
+ onSuccess(value);
13
+
14
+ setTimeout(() => setComplete(true), 500);
15
+ setTimeout(() => setComplete(false), 1500);
16
+ }
17
+
18
+ return (
19
+ <form id="interaction-test-form" onSubmit={onSubmit}>
20
+ <label>
21
+ Enter Value
22
+ <input
23
+ type="text"
24
+ data-testid="value"
25
+ value={value}
26
+ required
27
+ onInput={(event) => setValue(event.target.value)}
28
+ />
29
+ </label>
30
+ <button type="submit">Submit</button>
31
+ {complete && <p>Completed!!</p>}
32
+ </form>
33
+ );
34
+ };
35
+
36
+ Form.propTypes = {
37
+ onSuccess: PropTypes.func.isRequired,
38
+ };
@@ -0,0 +1,10 @@
1
+ /* eslint-disable react/react-in-jsx-scope */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+ import PropTypes from 'prop-types';
4
+
5
+ // eslint-disable-next-line react/no-danger
6
+ export const Html = ({ content }) => <div dangerouslySetInnerHTML={{ __html: content }} />;
7
+
8
+ Html.propTypes = {
9
+ content: PropTypes.string.isRequired,
10
+ };
@@ -0,0 +1,21 @@
1
+ /* eslint-disable react/react-in-jsx-scope */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+ import PropTypes from 'prop-types';
4
+
5
+ export const Pre = ({ style, object, text }) => (
6
+ <pre style={style} data-testid="pre">
7
+ {object ? JSON.stringify(object, null, 2) : text}
8
+ </pre>
9
+ );
10
+
11
+ Pre.propTypes = {
12
+ style: PropTypes.shape({}),
13
+ object: PropTypes.shape({}),
14
+ text: PropTypes.string,
15
+ };
16
+
17
+ Pre.defaultProps = {
18
+ style: {},
19
+ object: null,
20
+ text: '',
21
+ };
@@ -0,0 +1,9 @@
1
+ import { global as globalThis } from '@storybook/global';
2
+
3
+ import { Button } from './Button.jsx';
4
+ import { Pre } from './Pre.jsx';
5
+ import { Form } from './Form.jsx';
6
+ import { Html } from './Html.jsx';
7
+
8
+ globalThis.Components = { Button, Pre, Form, Html };
9
+ globalThis.storybookRenderer = 'preact';
@@ -0,0 +1,51 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+ import React from 'react';
3
+ // eslint-disable-next-line import/no-extraneous-dependencies
4
+ import PropTypes from 'prop-types';
5
+
6
+ export const ReactFunctionalComponent = ({ label }) => {
7
+ const [clicks, setValue] = React.useState(0);
8
+ return (
9
+ <div
10
+ tabIndex={0}
11
+ onClick={() => setValue(clicks + 1)}
12
+ style={{ cursor: 'pointer' }}
13
+ onKeyDown={() => undefined}
14
+ role="button"
15
+ >
16
+ <div style={{ color: 'red' }}>{label}</div>
17
+ <div>Clicked {clicks} times.</div>
18
+ </div>
19
+ );
20
+ };
21
+
22
+ ReactFunctionalComponent.propTypes = {
23
+ label: PropTypes.string.isRequired,
24
+ };
25
+
26
+ export class ReactClassComponent extends React.Component {
27
+ state = {
28
+ clicks: 0,
29
+ };
30
+
31
+ render() {
32
+ const { label } = this.props;
33
+ const { clicks } = this.state;
34
+ return (
35
+ <div
36
+ tabIndex={0}
37
+ onClick={() => this.setState({ clicks: clicks + 1 })}
38
+ onKeyDown={() => undefined}
39
+ style={{ cursor: 'pointer' }}
40
+ role="button"
41
+ >
42
+ <div style={{ color: 'green' }}>{label}</div>
43
+ <div>Clicked {clicks} times.</div>
44
+ </div>
45
+ );
46
+ }
47
+ }
48
+
49
+ ReactClassComponent.propTypes = {
50
+ label: PropTypes.string.isRequired,
51
+ };
@@ -0,0 +1,15 @@
1
+ /* eslint-disable react/react-in-jsx-scope */
2
+ import { ReactFunctionalComponent, ReactClassComponent } from './React';
3
+
4
+ export default {
5
+ component: ReactFunctionalComponent,
6
+ };
7
+
8
+ export const ReactComponentDemo = () => (
9
+ <div>
10
+ <h1>React component demo</h1>
11
+ <ReactFunctionalComponent label="This is a React functional component rendered by Preact" />
12
+ <hr />
13
+ <ReactClassComponent label="This is a React class component rendered by Preact" />
14
+ </div>
15
+ );