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

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ import*as preact from"preact";import{dedent}from"ts-dedent";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`
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)}export{render2 as render,renderToCanvas};
package/dist/config.d.ts CHANGED
@@ -1,11 +1,15 @@
1
- import { RenderContext } from '@storybook/store';
2
- import { P as PreactFramework } from './types-ed8e97dc.js';
1
+ import { ArgsStoryFn, RenderContext } from '@storybook/types';
2
+ import { P as PreactRenderer } from './types-dbc033aa.js';
3
3
  import 'preact';
4
4
 
5
- declare function renderToDOM({ storyFn, title, name, showMain, showError, forceRemount }: RenderContext<PreactFramework>, domElement: Element): void;
5
+ declare const render: ArgsStoryFn<PreactRenderer>;
6
+ declare function renderToCanvas({ storyFn, title, name, showMain, showError, forceRemount }: RenderContext<PreactRenderer>, canvasElement: PreactRenderer['canvasElement']): void;
6
7
 
7
8
  declare const parameters: {
9
+ docs: {
10
+ inlineStories: boolean;
11
+ };
8
12
  framework: "preact";
9
13
  };
10
14
 
11
- export { parameters, renderToDOM };
15
+ export { parameters, render, renderToCanvas };
package/dist/config.js CHANGED
@@ -1,4 +1,4 @@
1
- var y=Object.create;var p=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var f=(e,r)=>p(e,"name",{value:r,configurable:!0});var w=(e,r)=>{for(var t in r)p(e,t,{get:r[t],enumerable:!0})},s=(e,r,t,c)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of x(r))!D.call(e,n)&&n!==t&&p(e,n,{get:()=>r[n],enumerable:!(c=g(r,n))||c.enumerable});return e};var d=(e,r,t)=>(t=e!=null?y(M(e)):{},s(r||!e||!e.__esModule?p(t,"default",{value:e,enumerable:!0}):t,e)),C=e=>s(p({},"__esModule",{value:!0}),e);var T={};w(T,{parameters:()=>S,renderToDOM:()=>h});module.exports=C(T);var o=d(require("preact")),l=d(require("ts-dedent")),m;function u(e,r){o.Fragment?o.render(e,r):m=o.render(e,r,m)}f(u,"preactRender");var P=f(({showError:e,name:r,title:t,storyFn:c,domElement:n})=>{let a=o.h(c,null);return a||(e({title:`Expecting a Preact element from the story: "${r}" of "${t}".`,description:l.default`
1
+ "use strict";var h=Object.create;var c=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var C=(e,r)=>{for(var t in r)c(e,t,{get:r[t],enumerable:!0})},m=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of P(r))!g.call(e,a)&&a!==t&&c(e,a,{get:()=>r[a],enumerable:!(n=R(r,a))||n.enumerable});return e};var E=(e,r,t)=>(t=e!=null?h(x(e)):{},m(r||!e||!e.__esModule?c(t,"default",{value:e,enumerable:!0}):t,e)),w=e=>m(c({},"__esModule",{value:!0}),e);var T={};C(T,{parameters:()=>v,render:()=>f,renderToCanvas:()=>u});module.exports=w(T);var i={docs:{inlineStories:!0}};var o=E(require("preact")),y=require("ts-dedent"),{h:F}=o,f=(e,r)=>{let{id:t,component:n}=r;if(!n)throw new Error(`Unable to render story ${t} as the component annotation is missing from the default export`);return F(n,{...e})},d;function l(e,r){o.Fragment?o.render(e,r):d=o.render(e,r,d)}var S=({showError:e,name:r,title:t,storyFn:n,canvasElement:a})=>{let s=o.h(n,null);return s||(e({title:`Expecting a Preact element from the story: "${r}" of "${t}".`,description:y.dedent`
2
2
  Did you forget to return the Preact element from the story?
3
3
  Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
4
- `}),null)},"StoryHarness");function h({storyFn:e,title:r,name:t,showMain:c,showError:n,forceRemount:a},i){a&&u(null,i),c(),u(o.h(P,{name:t,title:r,showError:n,storyFn:e,domElement:i}),i)}f(h,"renderToDOM");var S={framework:"preact"};0&&(module.exports={parameters,renderToDOM});
4
+ `}),null)};function u({storyFn:e,title:r,name:t,showMain:n,showError:a,forceRemount:s},p){s&&l(null,p),n(),l(o.h(S,{name:t,title:r,showError:a,storyFn:e,canvasElement:p}),p)}var v={framework:"preact",...i};0&&(module.exports={parameters,render,renderToCanvas});
package/dist/config.mjs CHANGED
@@ -1 +1 @@
1
- import{b as r}from"./chunk-G45LXJLH.mjs";var t={framework:"preact"};export{t as parameters,r as renderToDOM};
1
+ import{render,renderToCanvas}from"./chunk-OHNM7E4P.mjs";var parameters={docs:{inlineStories:!0}};var parameters2={framework:"preact",...parameters};export{parameters2 as parameters,render,renderToCanvas};
package/dist/index.d.ts CHANGED
@@ -1,26 +1,18 @@
1
- import { ClientStoryApi, Loadable } from '@storybook/addons';
2
- import { P as PreactFramework, I as IStorybookSection } from './types-ed8e97dc.js';
3
- import { Args, ComponentAnnotations, AnnotatedStoryFn, StoryAnnotations } from '@storybook/csf';
4
- export { ArgTypes, Args, Parameters, StoryContext } from '@storybook/csf';
1
+ import { Addon_ClientStoryApi, Addon_Loadable, Args, ComponentAnnotations, AnnotatedStoryFn, StoryAnnotations, StrictArgs, DecoratorFunction, LoaderFunction, StoryContext as StoryContext$1 } from '@storybook/types';
2
+ export { ArgTypes, Args, Parameters, StrictArgs } from '@storybook/types';
3
+ import { P as PreactRenderer } from './types-dbc033aa.js';
4
+ export { P as PreactRenderer } from './types-dbc033aa.js';
5
5
  import 'preact';
6
6
 
7
- interface ClientApi extends ClientStoryApi<PreactFramework['storyResult']> {
8
- setAddon(addon: any): void;
9
- configure(loader: Loadable, module: NodeModule): void;
10
- getStorybook(): IStorybookSection[];
11
- clearDecorators(): void;
7
+ interface ClientApi extends Addon_ClientStoryApi<PreactRenderer['storyResult']> {
8
+ configure(loader: Addon_Loadable, module: NodeModule): void;
12
9
  forceReRender(): void;
13
10
  raw: () => any;
14
11
  load: (...args: any[]) => void;
15
12
  }
16
13
  declare const storiesOf: ClientApi['storiesOf'];
17
14
  declare const configure: ClientApi['configure'];
18
- declare const addDecorator: ClientApi['addDecorator'];
19
- declare const addParameters: ClientApi['addParameters'];
20
- declare const clearDecorators: ClientApi['clearDecorators'];
21
- declare const setAddon: ClientApi['setAddon'];
22
15
  declare const forceReRender: ClientApi['forceReRender'];
23
- declare const getStorybook: ClientApi['getStorybook'];
24
16
  declare const raw: ClientApi['raw'];
25
17
 
26
18
  /**
@@ -28,24 +20,31 @@ declare const raw: ClientApi['raw'];
28
20
  *
29
21
  * @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
30
22
  */
31
- declare type Meta<TArgs = Args> = ComponentAnnotations<PreactFramework, TArgs>;
23
+ type Meta<TArgs = Args> = ComponentAnnotations<PreactRenderer, TArgs>;
32
24
  /**
33
25
  * Story function that represents a CSFv2 component example.
34
26
  *
35
27
  * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
36
28
  */
37
- declare type StoryFn<TArgs = Args> = AnnotatedStoryFn<PreactFramework, TArgs>;
29
+ type StoryFn<TArgs = Args> = AnnotatedStoryFn<PreactRenderer, TArgs>;
38
30
  /**
39
31
  * Story function that represents a CSFv3 component example.
40
32
  *
41
33
  * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
42
34
  */
43
- declare type StoryObj<TArgs = Args> = StoryAnnotations<PreactFramework, TArgs>;
35
+ type StoryObj<TArgs = Args> = StoryAnnotations<PreactRenderer, TArgs>;
44
36
  /**
45
- * Story function that represents a CSFv3 component example.
37
+ * @deprecated Use `StoryFn` instead.
38
+ * Use `StoryObj` if you want to migrate to CSF3, which uses objects instead of functions to represent stories.
39
+ * You can read more about the CSF3 format here: https://storybook.js.org/blog/component-story-format-3-0/
40
+ *
41
+ * Story function that represents a CSFv2 component example.
46
42
  *
47
43
  * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
48
44
  */
49
- declare type Story<TArgs = Args> = StoryObj<TArgs>;
45
+ type Story<TArgs = Args> = StoryFn<TArgs>;
46
+ type Decorator<TArgs = StrictArgs> = DecoratorFunction<PreactRenderer, TArgs>;
47
+ type Loader<TArgs = StrictArgs> = LoaderFunction<PreactRenderer, TArgs>;
48
+ type StoryContext<TArgs = StrictArgs> = StoryContext$1<PreactRenderer, TArgs>;
50
49
 
51
- export { ClientApi, Meta, Story, StoryFn, StoryObj, addDecorator, addParameters, clearDecorators, configure, forceReRender, getStorybook, raw, setAddon, storiesOf };
50
+ export { ClientApi, Decorator, Loader, Meta, Story, StoryContext, StoryFn, StoryObj, configure, forceReRender, raw, storiesOf };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var D=Object.create;var a=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var i=(e,r)=>a(e,"name",{value:r,configurable:!0});var k=(e,r)=>{for(var t in r)a(e,t,{get:r[t],enumerable:!0})},m=(e,r,t,p)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of P(r))!b.call(e,n)&&n!==t&&a(e,n,{get:()=>r[n],enumerable:!(p=M(r,n))||p.enumerable});return e};var l=(e,r,t)=>(t=e!=null?D(S(e)):{},m(r||!e||!e.__esModule?a(t,"default",{value:e,enumerable:!0}):t,e)),T=e=>m(a({},"__esModule",{value:!0}),e);var V={};k(V,{addDecorator:()=>W,addParameters:()=>$,clearDecorators:()=>B,configure:()=>K,forceReRender:()=>H,getStorybook:()=>N,raw:()=>U,setAddon:()=>E,storiesOf:()=>F});module.exports=T(V);var u=l(require("global")),{window:x}=u.default;x&&(x.STORYBOOK_ENV="preact");var O=require("@storybook/core-client");var c=l(require("preact")),y=l(require("ts-dedent")),g;function A(e,r){c.Fragment?c.render(e,r):g=c.render(e,r,g)}i(A,"preactRender");var C=i(({showError:e,name:r,title:t,storyFn:p,domElement:n})=>{let s=c.h(p,null);return s||(e({title:`Expecting a Preact element from the story: "${r}" of "${t}".`,description:y.default`
1
+ "use strict";var w=Object.create;var p=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var F=(e,r)=>{for(var t in r)p(e,t,{get:r[t],enumerable:!0})},c=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of h(r))!S.call(e,n)&&n!==t&&p(e,n,{get:()=>r[n],enumerable:!(i=P(r,n))||i.enumerable});return e};var l=(e,r,t)=>(t=e!=null?w(E(e)):{},c(r||!e||!e.__esModule?p(t,"default",{value:e,enumerable:!0}):t,e)),O=e=>c(p({},"__esModule",{value:!0}),e);var M={};F(M,{configure:()=>T,forceReRender:()=>_,raw:()=>k,storiesOf:()=>v});module.exports=O(M);var f=l(require("global")),{window:m}=f.default;m&&(m.STORYBOOK_ENV="preact");var C=require("@storybook/preview-api");var o=l(require("preact")),u=require("ts-dedent"),{h:K}=o;var y;function R(e,r){o.Fragment?o.render(e,r):y=o.render(e,r,y)}var b=({showError:e,name:r,title:t,storyFn:i,canvasElement:n})=>{let a=o.h(i,null);return a||(e({title:`Expecting a Preact element from the story: "${r}" of "${t}".`,description:u.dedent`
2
2
  Did you forget to return the Preact element from the story?
3
3
  Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
4
- `}),null)},"StoryHarness");function h({storyFn:e,title:r,name:t,showMain:p,showError:n,forceRemount:s},f){s&&A(null,f),p(),A(c.h(C,{name:t,title:r,showError:n,storyFn:e,domElement:f}),f)}i(h,"renderToDOM");var R="preact",o=(0,O.start)(h),F=i((e,r)=>o.clientApi.storiesOf(e,r).addParameters({framework:R}),"storiesOf"),K=i((...e)=>o.configure(R,...e),"configure"),W=o.clientApi.addDecorator,$=o.clientApi.addParameters,B=o.clientApi.clearDecorators,E=o.clientApi.setAddon,H=o.forceReRender,N=o.clientApi.getStorybook,U=o.clientApi.raw;var w;(w=module==null?void 0:module.hot)==null||w.decline();0&&(module.exports={addDecorator,addParameters,clearDecorators,configure,forceReRender,getStorybook,raw,setAddon,storiesOf});
4
+ `}),null)};function A({storyFn:e,title:r,name:t,showMain:i,showError:n,forceRemount:a},d){a&&R(null,d),i(),R(o.h(b,{name:t,title:r,showError:n,storyFn:e,canvasElement:d}),d)}var g="preact",s=(0,C.start)(A),v=(e,r)=>s.clientApi.storiesOf(e,r).addParameters({framework:g}),T=(...e)=>s.configure(g,...e),_=s.forceReRender,k=s.clientApi.raw;var x;(x=module==null?void 0:module.hot)==null||x.decline();0&&(module.exports={configure,forceReRender,raw,storiesOf});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{a as e,b as n}from"./chunk-G45LXJLH.mjs";import d from"global";var{window:a}=d;a&&(a.STORYBOOK_ENV="preact");import{start as l}from"@storybook/core-client";var i="preact",o=l(n),A=e((r,s)=>o.clientApi.storiesOf(r,s).addParameters({framework:i}),"storiesOf"),O=e((...r)=>o.configure(i,...r),"configure"),R=o.clientApi.addDecorator,g=o.clientApi.addParameters,w=o.clientApi.clearDecorators,D=o.clientApi.setAddon,b=o.forceReRender,u=o.clientApi.getStorybook,k=o.clientApi.raw;var p;(p=module==null?void 0:module.hot)==null||p.decline();export{R as addDecorator,g as addParameters,w as clearDecorators,O as configure,b as forceReRender,u as getStorybook,k as raw,D as setAddon,A as storiesOf};
1
+ import{renderToCanvas}from"./chunk-OHNM7E4P.mjs";import global from"global";var{window:globalWindow}=global;globalWindow&&(globalWindow.STORYBOOK_ENV="preact");import{start}from"@storybook/preview-api";var FRAMEWORK="preact",api=start(renderToCanvas),storiesOf=(kind,m)=>api.clientApi.storiesOf(kind,m).addParameters({framework:FRAMEWORK}),configure=(...args)=>api.configure(FRAMEWORK,...args),forceReRender=api.forceReRender,raw=api.clientApi.raw;module?.hot?.decline();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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/preact",
3
- "version": "7.0.0-alpha.7",
3
+ "version": "7.0.0-beta.0",
4
4
  "description": "Storybook Preact renderer",
5
5
  "keywords": [
6
6
  "storybook"
@@ -41,27 +41,25 @@
41
41
  "types": "dist/index.d.ts",
42
42
  "files": [
43
43
  "dist/**/*",
44
+ "template/**/*",
44
45
  "README.md",
45
46
  "*.js",
46
47
  "*.d.ts"
47
48
  ],
48
49
  "scripts": {
49
- "prepare": "esrun ../../scripts/prepare/bundle.ts"
50
+ "check": "../../../scripts/node_modules/.bin/tsc --noEmit",
51
+ "prep": "../../../scripts/prepare/bundle.ts"
50
52
  },
51
53
  "dependencies": {
52
- "@storybook/addons": "7.0.0-alpha.7",
53
- "@storybook/core-client": "7.0.0-alpha.7",
54
- "@storybook/csf": "0.0.2--canary.4566f4d.1",
55
- "@storybook/store": "7.0.0-alpha.7",
56
- "core-js": "^3.8.2",
54
+ "@storybook/core-client": "7.0.0-beta.0",
55
+ "@storybook/preview-api": "7.0.0-beta.0",
56
+ "@storybook/types": "7.0.0-beta.0",
57
57
  "global": "^4.4.0",
58
- "react": "16.14.0",
59
- "react-dom": "16.14.0",
60
58
  "ts-dedent": "^2.0.0"
61
59
  },
62
60
  "devDependencies": {
63
- "@digitak/esrun": "^3.2.2",
64
- "preact": "^10.5.13"
61
+ "preact": "^10.5.13",
62
+ "typescript": "~4.9.3"
65
63
  },
66
64
  "peerDependencies": {
67
65
  "preact": "^8.0.0||^10.0.0"
@@ -72,9 +70,12 @@
72
70
  "publishConfig": {
73
71
  "access": "public"
74
72
  },
75
- "bundlerEntrypoint": [
76
- "./src/index.ts",
77
- "./src/config.ts"
78
- ],
79
- "gitHead": "d334cabd251cd0ed8b845a87707dc84f007d4074"
73
+ "bundler": {
74
+ "entries": [
75
+ "./src/index.ts",
76
+ "./src/config.ts"
77
+ ],
78
+ "platform": "browser"
79
+ },
80
+ "gitHead": "2e4ddde6a0a291266d91fe6a5ecda767bf119e70"
80
81
  }
@@ -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/7.0/preact/writing-stories/introduction
4
+ export default {
5
+ title: 'Example/Button',
6
+ component: Button,
7
+ tags: ['docsPage'],
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/7.0/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="wrapper">
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 docsPage entry: https://storybook.js.org/docs/7.0/preact/writing-docs/docs-page
7
+ tags: ['docsPage'],
8
+ parameters: {
9
+ // More on how to position stories at: https://storybook.js.org/docs/7.0/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>
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/7.0/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/7.0/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
+ onChange={(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 globalThis from '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
+ );
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 Kadira Inc. <hello@kadira.io>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1,4 +0,0 @@
1
- var u=Object.defineProperty;var o=(e,r)=>u(e,"name",{value:r,configurable:!0});import*as t from"preact";import d from"ts-dedent";var f;function s(e,r){t.Fragment?t.render(e,r):f=t.render(e,r,f)}o(s,"preactRender");var l=o(({showError:e,name:r,title:c,storyFn:i,domElement:a})=>{let n=t.h(i,null);return n||(e({title:`Expecting a Preact element from the story: "${r}" of "${c}".`,description:d`
2
- Did you forget to return the Preact element from the story?
3
- Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
4
- `}),null)},"StoryHarness");function M({storyFn:e,title:r,name:c,showMain:i,showError:a,forceRemount:n},p){n&&s(null,p),i(),s(t.h(l,{name:c,title:r,showError:a,storyFn:e,domElement:p}),p)}o(M,"renderToDOM");export{o as a,M as b};
@@ -1,17 +0,0 @@
1
- import { AnyComponent } from 'preact';
2
-
3
- declare type StoryFnPreactReturnType = string | Node | preact.JSX.Element;
4
- interface IStorybookStory {
5
- name: string;
6
- render: (context: any) => any;
7
- }
8
- interface IStorybookSection {
9
- kind: string;
10
- stories: IStorybookStory[];
11
- }
12
- declare type PreactFramework = {
13
- component: AnyComponent<any, any>;
14
- storyResult: StoryFnPreactReturnType;
15
- };
16
-
17
- export { IStorybookSection as I, PreactFramework as P };