@storybook/preact 7.0.0-alpha.5 → 7.0.0-alpha.51
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/chunk-KASU7O3E.mjs +4 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.js +4 -0
- package/dist/config.mjs +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +4 -0
- package/dist/index.mjs +1 -0
- package/dist/types-aea856cd.d.ts +10 -0
- package/jest.config.js +7 -0
- package/package.json +38 -12
- package/preview.js +1 -1
- package/template/cli/.eslintrc.json +7 -0
- package/template/cli/Button.jsx +49 -0
- package/template/cli/Button.stories.jsx +40 -0
- package/template/cli/Header.jsx +58 -0
- package/template/cli/Header.stories.jsx +27 -0
- package/template/cli/Page.jsx +68 -0
- package/template/cli/Page.stories.jsx +25 -0
- package/template/components/Button.jsx +14 -0
- package/template/components/Form.jsx +38 -0
- package/template/components/Html.jsx +10 -0
- package/template/components/Pre.jsx +21 -0
- package/template/components/index.js +9 -0
- package/template/stories/React.js +50 -0
- package/template/stories/react-compat.stories.js +15 -0
- package/LICENSE +0 -21
- package/dist/cjs/index.js +0 -79
- package/dist/cjs/preview/config.js +0 -19
- package/dist/cjs/preview/globals.js +0 -13
- package/dist/cjs/preview/index.js +0 -42
- package/dist/cjs/preview/render.js +0 -73
- package/dist/cjs/preview/types-6-0.js +0 -5
- package/dist/cjs/preview/types-7-0.js +0 -5
- package/dist/cjs/preview/types.js +0 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/preview/config.js +0 -4
- package/dist/esm/preview/globals.js +0 -8
- package/dist/esm/preview/index.js +0 -19
- package/dist/esm/preview/render.js +0 -58
- package/dist/esm/preview/types-6-0.js +0 -1
- package/dist/esm/preview/types-7-0.js +0 -1
- package/dist/esm/preview/types.js +0 -0
- package/dist/types/index.d.ts +0 -2
- package/dist/types/preview/config.d.ts +0 -4
- package/dist/types/preview/globals.d.ts +0 -1
- package/dist/types/preview/index.d.ts +0 -23
- package/dist/types/preview/render.d.ts +0 -3
- package/dist/types/preview/types-6-0.d.ts +0 -35
- package/dist/types/preview/types-7-0.d.ts +0 -9
- package/dist/types/preview/types.d.ts +0 -14
@@ -0,0 +1,4 @@
|
|
1
|
+
import*as e from"preact";import{dedent as m}from"ts-dedent";var{h:d}=e,f=(r,t)=>{let{id:o,component:n}=t;if(!n)throw new Error(`Unable to render story ${o} as the component annotation is missing from the default export`);return d(n,{...r})},p;function i(r,t){e.Fragment?e.render(r,t):p=e.render(r,t,p)}var y=({showError:r,name:t,title:o,storyFn:n,canvasElement:c})=>{let a=e.h(n,null);return a||(r({title:`Expecting a Preact element from the story: "${t}" of "${o}".`,description:m`
|
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 u({storyFn:r,title:t,name:o,showMain:n,showError:c,forceRemount:a},s){a&&i(null,s),n(),i(e.h(y,{name:o,title:t,showError:c,storyFn:r,canvasElement:s}),s)}export{f as a,u as b};
|
package/dist/config.d.ts
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
import { ArgsStoryFn, Store_RenderContext } from '@storybook/types';
|
2
|
+
import { P as PreactRenderer } from './types-aea856cd.js';
|
3
|
+
import 'preact';
|
4
|
+
|
5
|
+
declare const render: ArgsStoryFn<PreactRenderer>;
|
6
|
+
declare function renderToCanvas({ storyFn, title, name, showMain, showError, forceRemount }: Store_RenderContext<PreactRenderer>, canvasElement: PreactRenderer['canvasElement']): void;
|
7
|
+
|
8
|
+
declare const parameters: {
|
9
|
+
docs: {
|
10
|
+
inlineStories: boolean;
|
11
|
+
};
|
12
|
+
framework: "preact";
|
13
|
+
};
|
14
|
+
|
15
|
+
export { parameters, render, renderToCanvas };
|
package/dist/config.js
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
"use strict";var h=Object.create;var c=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var g=(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))!S.call(e,a)&&a!==t&&c(e,a,{get:()=>r[a],enumerable:!(n=R(r,a))||n.enumerable});return e};var C=(e,r,t)=>(t=e!=null?h(x(e)):{},m(r||!e||!e.__esModule?c(t,"default",{value:e,enumerable:!0}):t,e)),E=e=>m(c({},"__esModule",{value:!0}),e);var T={};g(T,{parameters:()=>v,render:()=>f,renderToCanvas:()=>u});module.exports=E(T);var i={docs:{inlineStories:!0}};var o=C(require("preact")),y=require("ts-dedent"),{h:w}=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 w(n,{...e})},d;function l(e,r){o.Fragment?o.render(e,r):d=o.render(e,r,d)}var F=({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
|
+
Did you forget to return the Preact element from the story?
|
3
|
+
Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
|
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(F,{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
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
import{a as e,b as a}from"./chunk-KASU7O3E.mjs";var r={docs:{inlineStories:!0}};var t={framework:"preact",...r};export{t as parameters,e as render,a as renderToCanvas};
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,50 @@
|
|
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-aea856cd.js';
|
4
|
+
export { P as PreactRenderer } from './types-aea856cd.js';
|
5
|
+
import 'preact';
|
6
|
+
|
7
|
+
interface ClientApi extends Addon_ClientStoryApi<PreactRenderer['storyResult']> {
|
8
|
+
configure(loader: Addon_Loadable, module: NodeModule): void;
|
9
|
+
forceReRender(): void;
|
10
|
+
raw: () => any;
|
11
|
+
load: (...args: any[]) => void;
|
12
|
+
}
|
13
|
+
declare const storiesOf: ClientApi['storiesOf'];
|
14
|
+
declare const configure: ClientApi['configure'];
|
15
|
+
declare const forceReRender: ClientApi['forceReRender'];
|
16
|
+
declare const raw: ClientApi['raw'];
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Metadata to configure the stories for a component.
|
20
|
+
*
|
21
|
+
* @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
|
22
|
+
*/
|
23
|
+
type Meta<TArgs = Args> = ComponentAnnotations<PreactRenderer, TArgs>;
|
24
|
+
/**
|
25
|
+
* Story function that represents a CSFv2 component example.
|
26
|
+
*
|
27
|
+
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
28
|
+
*/
|
29
|
+
type StoryFn<TArgs = Args> = AnnotatedStoryFn<PreactRenderer, TArgs>;
|
30
|
+
/**
|
31
|
+
* Story function that represents a CSFv3 component example.
|
32
|
+
*
|
33
|
+
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
34
|
+
*/
|
35
|
+
type StoryObj<TArgs = Args> = StoryAnnotations<PreactRenderer, TArgs>;
|
36
|
+
/**
|
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.
|
42
|
+
*
|
43
|
+
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
44
|
+
*/
|
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>;
|
49
|
+
|
50
|
+
export { ClientApi, Decorator, Loader, Meta, Story, StoryContext, StoryFn, StoryObj, configure, forceReRender, raw, storiesOf };
|
package/dist/index.js
ADDED
@@ -0,0 +1,4 @@
|
|
1
|
+
"use strict";var w=Object.create;var p=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,E=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))!E.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(S(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:()=>v,forceReRender:()=>T,raw:()=>k,storiesOf:()=>b});module.exports=O(M);var f=l(require("global")),{window:m}=f.default;m&&(m.STORYBOOK_ENV="preact");var C=require("@storybook/core-client");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 _=({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
|
+
Did you forget to return the Preact element from the story?
|
3
|
+
Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
|
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(_,{name:t,title:r,showError:n,storyFn:e,canvasElement:d}),d)}var g="preact",s=(0,C.start)(A),b=(e,r)=>s.clientApi.storiesOf(e,r).addParameters({framework:g}),v=(...e)=>s.configure(g,...e),T=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
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
import{b as o}from"./chunk-KASU7O3E.mjs";import d from"global";var{window:t}=d;t&&(t.STORYBOOK_ENV="preact");import{start as p}from"@storybook/core-client";var i="preact",e=p(o),l=(r,n)=>e.clientApi.storiesOf(r,n).addParameters({framework:i}),f=(...r)=>e.configure(i,...r),m=e.forceReRender,R=e.clientApi.raw;module?.hot?.decline();export{f as configure,m as forceReRender,R as raw,l as 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
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storybook/preact",
|
3
|
-
"version": "7.0.0-alpha.
|
3
|
+
"version": "7.0.0-alpha.51",
|
4
4
|
"description": "Storybook Preact renderer",
|
5
5
|
"keywords": [
|
6
6
|
"storybook"
|
@@ -19,31 +19,50 @@
|
|
19
19
|
"url": "https://opencollective.com/storybook"
|
20
20
|
},
|
21
21
|
"license": "MIT",
|
22
|
-
"
|
23
|
-
|
24
|
-
|
22
|
+
"exports": {
|
23
|
+
".": {
|
24
|
+
"require": "./dist/index.js",
|
25
|
+
"import": "./dist/index.mjs",
|
26
|
+
"types": "./dist/index.d.ts"
|
27
|
+
},
|
28
|
+
"./preview": {
|
29
|
+
"require": "./dist/config.js",
|
30
|
+
"import": "./dist/config.mjs",
|
31
|
+
"types": "./dist/config.d.ts"
|
32
|
+
},
|
33
|
+
"./package.json": {
|
34
|
+
"require": "./package.json",
|
35
|
+
"import": "./package.json",
|
36
|
+
"types": "./package.json"
|
37
|
+
}
|
38
|
+
},
|
39
|
+
"main": "dist/index.js",
|
40
|
+
"module": "dist/index.mjs",
|
41
|
+
"types": "dist/index.d.ts",
|
25
42
|
"files": [
|
26
43
|
"dist/**/*",
|
44
|
+
"template/**/*",
|
27
45
|
"README.md",
|
28
46
|
"*.js",
|
29
47
|
"*.d.ts"
|
30
48
|
],
|
31
49
|
"scripts": {
|
32
|
-
"
|
50
|
+
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
|
51
|
+
"prep": "../../../scripts/prepare/bundle.ts"
|
33
52
|
},
|
34
53
|
"dependencies": {
|
35
|
-
"@storybook/addons": "7.0.0-alpha.
|
36
|
-
"@storybook/core-client": "7.0.0-alpha.
|
37
|
-
"@storybook/
|
38
|
-
"@storybook/
|
39
|
-
"core-js": "^3.8.2",
|
54
|
+
"@storybook/addons": "7.0.0-alpha.51",
|
55
|
+
"@storybook/core-client": "7.0.0-alpha.51",
|
56
|
+
"@storybook/store": "7.0.0-alpha.51",
|
57
|
+
"@storybook/types": "7.0.0-alpha.51",
|
40
58
|
"global": "^4.4.0",
|
41
59
|
"react": "16.14.0",
|
42
60
|
"react-dom": "16.14.0",
|
43
61
|
"ts-dedent": "^2.0.0"
|
44
62
|
},
|
45
63
|
"devDependencies": {
|
46
|
-
"preact": "^10.5.13"
|
64
|
+
"preact": "^10.5.13",
|
65
|
+
"typescript": "^4.9.3"
|
47
66
|
},
|
48
67
|
"peerDependencies": {
|
49
68
|
"preact": "^8.0.0||^10.0.0"
|
@@ -54,5 +73,12 @@
|
|
54
73
|
"publishConfig": {
|
55
74
|
"access": "public"
|
56
75
|
},
|
57
|
-
"
|
76
|
+
"bundler": {
|
77
|
+
"entries": [
|
78
|
+
"./src/index.ts",
|
79
|
+
"./src/config.ts"
|
80
|
+
],
|
81
|
+
"platform": "browser"
|
82
|
+
},
|
83
|
+
"gitHead": "4fec76c3f5135854d9834ebc1cf2f1f325696ded"
|
58
84
|
}
|
package/preview.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from './dist/
|
1
|
+
export * from './dist/config';
|
@@ -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,50 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
3
|
+
import PropTypes from 'prop-types';
|
4
|
+
|
5
|
+
export const ReactFunctionalComponent = ({ label }) => {
|
6
|
+
const [clicks, setValue] = React.useState(0);
|
7
|
+
return (
|
8
|
+
<div
|
9
|
+
tabIndex={0}
|
10
|
+
onClick={() => setValue(clicks + 1)}
|
11
|
+
style={{ cursor: 'pointer' }}
|
12
|
+
onKeyDown={() => undefined}
|
13
|
+
role="button"
|
14
|
+
>
|
15
|
+
<div style={{ color: 'red' }}>{label}</div>
|
16
|
+
<div>Clicked {clicks} times.</div>
|
17
|
+
</div>
|
18
|
+
);
|
19
|
+
};
|
20
|
+
|
21
|
+
ReactFunctionalComponent.propTypes = {
|
22
|
+
label: PropTypes.string.isRequired,
|
23
|
+
};
|
24
|
+
|
25
|
+
export class ReactClassComponent extends React.Component {
|
26
|
+
state = {
|
27
|
+
clicks: 0,
|
28
|
+
};
|
29
|
+
|
30
|
+
render() {
|
31
|
+
const { label } = this.props;
|
32
|
+
const { clicks } = this.state;
|
33
|
+
return (
|
34
|
+
<div
|
35
|
+
tabIndex={0}
|
36
|
+
onClick={() => this.setState({ clicks: clicks + 1 })}
|
37
|
+
onKeyDown={() => undefined}
|
38
|
+
style={{ cursor: 'pointer' }}
|
39
|
+
role="button"
|
40
|
+
>
|
41
|
+
<div style={{ color: 'green' }}>{label}</div>
|
42
|
+
<div>Clicked {clicks} times.</div>
|
43
|
+
</div>
|
44
|
+
);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
ReactClassComponent.propTypes = {
|
49
|
+
label: PropTypes.string.isRequired,
|
50
|
+
};
|
@@ -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.
|
package/dist/cjs/index.js
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
var _exportNames = {
|
7
|
-
storiesOf: true,
|
8
|
-
setAddon: true,
|
9
|
-
addDecorator: true,
|
10
|
-
addParameters: true,
|
11
|
-
configure: true,
|
12
|
-
getStorybook: true,
|
13
|
-
forceReRender: true,
|
14
|
-
raw: true
|
15
|
-
};
|
16
|
-
Object.defineProperty(exports, "addDecorator", {
|
17
|
-
enumerable: true,
|
18
|
-
get: function () {
|
19
|
-
return _preview.addDecorator;
|
20
|
-
}
|
21
|
-
});
|
22
|
-
Object.defineProperty(exports, "addParameters", {
|
23
|
-
enumerable: true,
|
24
|
-
get: function () {
|
25
|
-
return _preview.addParameters;
|
26
|
-
}
|
27
|
-
});
|
28
|
-
Object.defineProperty(exports, "configure", {
|
29
|
-
enumerable: true,
|
30
|
-
get: function () {
|
31
|
-
return _preview.configure;
|
32
|
-
}
|
33
|
-
});
|
34
|
-
Object.defineProperty(exports, "forceReRender", {
|
35
|
-
enumerable: true,
|
36
|
-
get: function () {
|
37
|
-
return _preview.forceReRender;
|
38
|
-
}
|
39
|
-
});
|
40
|
-
Object.defineProperty(exports, "getStorybook", {
|
41
|
-
enumerable: true,
|
42
|
-
get: function () {
|
43
|
-
return _preview.getStorybook;
|
44
|
-
}
|
45
|
-
});
|
46
|
-
Object.defineProperty(exports, "raw", {
|
47
|
-
enumerable: true,
|
48
|
-
get: function () {
|
49
|
-
return _preview.raw;
|
50
|
-
}
|
51
|
-
});
|
52
|
-
Object.defineProperty(exports, "setAddon", {
|
53
|
-
enumerable: true,
|
54
|
-
get: function () {
|
55
|
-
return _preview.setAddon;
|
56
|
-
}
|
57
|
-
});
|
58
|
-
Object.defineProperty(exports, "storiesOf", {
|
59
|
-
enumerable: true,
|
60
|
-
get: function () {
|
61
|
-
return _preview.storiesOf;
|
62
|
-
}
|
63
|
-
});
|
64
|
-
|
65
|
-
var _preview = require("./preview");
|
66
|
-
|
67
|
-
var _types = require("./preview/types-6-0");
|
68
|
-
|
69
|
-
Object.keys(_types).forEach(function (key) {
|
70
|
-
if (key === "default" || key === "__esModule") return;
|
71
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
72
|
-
if (key in exports && exports[key] === _types[key]) return;
|
73
|
-
Object.defineProperty(exports, key, {
|
74
|
-
enumerable: true,
|
75
|
-
get: function () {
|
76
|
-
return _types[key];
|
77
|
-
}
|
78
|
-
});
|
79
|
-
});
|
@@ -1,19 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.parameters = void 0;
|
7
|
-
Object.defineProperty(exports, "renderToDOM", {
|
8
|
-
enumerable: true,
|
9
|
-
get: function () {
|
10
|
-
return _render.renderToDOM;
|
11
|
-
}
|
12
|
-
});
|
13
|
-
|
14
|
-
var _render = require("./render");
|
15
|
-
|
16
|
-
const parameters = {
|
17
|
-
framework: 'preact'
|
18
|
-
};
|
19
|
-
exports.parameters = parameters;
|
@@ -1,13 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
var _global = _interopRequireDefault(require("global"));
|
4
|
-
|
5
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
|
-
|
7
|
-
const {
|
8
|
-
window: globalWindow
|
9
|
-
} = _global.default;
|
10
|
-
|
11
|
-
if (globalWindow) {
|
12
|
-
globalWindow.STORYBOOK_ENV = 'preact';
|
13
|
-
}
|
@@ -1,42 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.storiesOf = exports.setAddon = exports.raw = exports.getStorybook = exports.forceReRender = exports.configure = exports.clearDecorators = exports.addParameters = exports.addDecorator = void 0;
|
7
|
-
|
8
|
-
var _coreClient = require("@storybook/core-client");
|
9
|
-
|
10
|
-
require("./globals");
|
11
|
-
|
12
|
-
var _render = require("./render");
|
13
|
-
|
14
|
-
/* eslint-disable prefer-destructuring */
|
15
|
-
const framework = 'preact';
|
16
|
-
const api = (0, _coreClient.start)(_render.renderToDOM);
|
17
|
-
|
18
|
-
const storiesOf = (kind, m) => {
|
19
|
-
return api.clientApi.storiesOf(kind, m).addParameters({
|
20
|
-
framework
|
21
|
-
});
|
22
|
-
};
|
23
|
-
|
24
|
-
exports.storiesOf = storiesOf;
|
25
|
-
|
26
|
-
const configure = (...args) => api.configure(framework, ...args);
|
27
|
-
|
28
|
-
exports.configure = configure;
|
29
|
-
const addDecorator = api.clientApi.addDecorator;
|
30
|
-
exports.addDecorator = addDecorator;
|
31
|
-
const addParameters = api.clientApi.addParameters;
|
32
|
-
exports.addParameters = addParameters;
|
33
|
-
const clearDecorators = api.clientApi.clearDecorators;
|
34
|
-
exports.clearDecorators = clearDecorators;
|
35
|
-
const setAddon = api.clientApi.setAddon;
|
36
|
-
exports.setAddon = setAddon;
|
37
|
-
const forceReRender = api.forceReRender;
|
38
|
-
exports.forceReRender = forceReRender;
|
39
|
-
const getStorybook = api.clientApi.getStorybook;
|
40
|
-
exports.getStorybook = getStorybook;
|
41
|
-
const raw = api.clientApi.raw;
|
42
|
-
exports.raw = raw;
|
@@ -1,73 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.renderToDOM = renderToDOM;
|
7
|
-
|
8
|
-
var preact = _interopRequireWildcard(require("preact"));
|
9
|
-
|
10
|
-
var _tsDedent = _interopRequireDefault(require("ts-dedent"));
|
11
|
-
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
-
|
14
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
15
|
-
|
16
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
17
|
-
|
18
|
-
let renderedStory;
|
19
|
-
|
20
|
-
function preactRender(story, domElement) {
|
21
|
-
// @ts-ignore
|
22
|
-
if (preact.Fragment) {
|
23
|
-
// Preact 10 only:
|
24
|
-
preact.render(story, domElement);
|
25
|
-
} else {
|
26
|
-
renderedStory = preact.render(story, domElement, renderedStory);
|
27
|
-
}
|
28
|
-
}
|
29
|
-
|
30
|
-
const StoryHarness = ({
|
31
|
-
showError,
|
32
|
-
name,
|
33
|
-
title,
|
34
|
-
storyFn,
|
35
|
-
domElement
|
36
|
-
}) => {
|
37
|
-
const content = preact.h(storyFn, null);
|
38
|
-
|
39
|
-
if (!content) {
|
40
|
-
showError({
|
41
|
-
title: `Expecting a Preact element from the story: "${name}" of "${title}".`,
|
42
|
-
description: (0, _tsDedent.default)`
|
43
|
-
Did you forget to return the Preact element from the story?
|
44
|
-
Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
|
45
|
-
`
|
46
|
-
});
|
47
|
-
return null;
|
48
|
-
}
|
49
|
-
|
50
|
-
return content;
|
51
|
-
};
|
52
|
-
|
53
|
-
function renderToDOM({
|
54
|
-
storyFn,
|
55
|
-
title,
|
56
|
-
name,
|
57
|
-
showMain,
|
58
|
-
showError,
|
59
|
-
forceRemount
|
60
|
-
}, domElement) {
|
61
|
-
if (forceRemount) {
|
62
|
-
preactRender(null, domElement);
|
63
|
-
}
|
64
|
-
|
65
|
-
showMain();
|
66
|
-
preactRender(preact.h(StoryHarness, {
|
67
|
-
name,
|
68
|
-
title,
|
69
|
-
showError,
|
70
|
-
storyFn,
|
71
|
-
domElement
|
72
|
-
}), domElement);
|
73
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
"use strict";
|
package/dist/esm/index.js
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
/* eslint-disable prefer-destructuring */
|
2
|
-
import { start } from '@storybook/core-client';
|
3
|
-
import './globals';
|
4
|
-
import { renderToDOM } from './render';
|
5
|
-
const framework = 'preact';
|
6
|
-
const api = start(renderToDOM);
|
7
|
-
export const storiesOf = (kind, m) => {
|
8
|
-
return api.clientApi.storiesOf(kind, m).addParameters({
|
9
|
-
framework
|
10
|
-
});
|
11
|
-
};
|
12
|
-
export const configure = (...args) => api.configure(framework, ...args);
|
13
|
-
export const addDecorator = api.clientApi.addDecorator;
|
14
|
-
export const addParameters = api.clientApi.addParameters;
|
15
|
-
export const clearDecorators = api.clientApi.clearDecorators;
|
16
|
-
export const setAddon = api.clientApi.setAddon;
|
17
|
-
export const forceReRender = api.forceReRender;
|
18
|
-
export const getStorybook = api.clientApi.getStorybook;
|
19
|
-
export const raw = api.clientApi.raw;
|
@@ -1,58 +0,0 @@
|
|
1
|
-
import * as preact from 'preact';
|
2
|
-
import dedent from 'ts-dedent';
|
3
|
-
let renderedStory;
|
4
|
-
|
5
|
-
function preactRender(story, domElement) {
|
6
|
-
// @ts-ignore
|
7
|
-
if (preact.Fragment) {
|
8
|
-
// Preact 10 only:
|
9
|
-
preact.render(story, domElement);
|
10
|
-
} else {
|
11
|
-
renderedStory = preact.render(story, domElement, renderedStory);
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
const StoryHarness = ({
|
16
|
-
showError,
|
17
|
-
name,
|
18
|
-
title,
|
19
|
-
storyFn,
|
20
|
-
domElement
|
21
|
-
}) => {
|
22
|
-
const content = preact.h(storyFn, null);
|
23
|
-
|
24
|
-
if (!content) {
|
25
|
-
showError({
|
26
|
-
title: `Expecting a Preact element from the story: "${name}" of "${title}".`,
|
27
|
-
description: dedent`
|
28
|
-
Did you forget to return the Preact element from the story?
|
29
|
-
Use "() => (<MyComp/>)" or "() => { return <MyComp/>; }" when defining the story.
|
30
|
-
`
|
31
|
-
});
|
32
|
-
return null;
|
33
|
-
}
|
34
|
-
|
35
|
-
return content;
|
36
|
-
};
|
37
|
-
|
38
|
-
export function renderToDOM({
|
39
|
-
storyFn,
|
40
|
-
title,
|
41
|
-
name,
|
42
|
-
showMain,
|
43
|
-
showError,
|
44
|
-
forceRemount
|
45
|
-
}, domElement) {
|
46
|
-
if (forceRemount) {
|
47
|
-
preactRender(null, domElement);
|
48
|
-
}
|
49
|
-
|
50
|
-
showMain();
|
51
|
-
preactRender(preact.h(StoryHarness, {
|
52
|
-
name,
|
53
|
-
title,
|
54
|
-
showError,
|
55
|
-
storyFn,
|
56
|
-
domElement
|
57
|
-
}), domElement);
|
58
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
File without changes
|
package/dist/types/index.d.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export {};
|
@@ -1,23 +0,0 @@
|
|
1
|
-
/// <reference types="webpack-env" />
|
2
|
-
import type { ClientStoryApi, Loadable } from '@storybook/addons';
|
3
|
-
import './globals';
|
4
|
-
import type { IStorybookSection } from './types';
|
5
|
-
import type { PreactFramework } from './types-6-0';
|
6
|
-
export interface ClientApi extends ClientStoryApi<PreactFramework['storyResult']> {
|
7
|
-
setAddon(addon: any): void;
|
8
|
-
configure(loader: Loadable, module: NodeModule): void;
|
9
|
-
getStorybook(): IStorybookSection[];
|
10
|
-
clearDecorators(): void;
|
11
|
-
forceReRender(): void;
|
12
|
-
raw: () => any;
|
13
|
-
load: (...args: any[]) => void;
|
14
|
-
}
|
15
|
-
export declare const storiesOf: ClientApi['storiesOf'];
|
16
|
-
export declare const configure: ClientApi['configure'];
|
17
|
-
export declare const addDecorator: ClientApi['addDecorator'];
|
18
|
-
export declare const addParameters: ClientApi['addParameters'];
|
19
|
-
export declare const clearDecorators: ClientApi['clearDecorators'];
|
20
|
-
export declare const setAddon: ClientApi['setAddon'];
|
21
|
-
export declare const forceReRender: ClientApi['forceReRender'];
|
22
|
-
export declare const getStorybook: ClientApi['getStorybook'];
|
23
|
-
export declare const raw: ClientApi['raw'];
|
@@ -1,35 +0,0 @@
|
|
1
|
-
import type { AnyComponent } from 'preact';
|
2
|
-
import type { Args, ComponentAnnotations, StoryAnnotations, AnnotatedStoryFn } from '@storybook/csf';
|
3
|
-
import type { StoryFnPreactReturnType } from './types';
|
4
|
-
export type { Args, ArgTypes, Parameters, StoryContext } from '@storybook/csf';
|
5
|
-
export declare type PreactFramework = {
|
6
|
-
component: AnyComponent<any, any>;
|
7
|
-
storyResult: StoryFnPreactReturnType;
|
8
|
-
};
|
9
|
-
/**
|
10
|
-
* Metadata to configure the stories for a component.
|
11
|
-
*
|
12
|
-
* @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
|
13
|
-
*/
|
14
|
-
export declare type Meta<TArgs = Args> = ComponentAnnotations<PreactFramework, TArgs>;
|
15
|
-
/**
|
16
|
-
* Story function that represents a CSFv2 component example.
|
17
|
-
*
|
18
|
-
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
19
|
-
*/
|
20
|
-
export declare type StoryFn<TArgs = Args> = AnnotatedStoryFn<PreactFramework, TArgs>;
|
21
|
-
/**
|
22
|
-
* Story function that represents a CSFv3 component example.
|
23
|
-
*
|
24
|
-
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
25
|
-
*/
|
26
|
-
export declare type StoryObj<TArgs = Args> = StoryAnnotations<PreactFramework, TArgs>;
|
27
|
-
/**
|
28
|
-
* Story function that represents a CSFv2 component example.
|
29
|
-
*
|
30
|
-
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
31
|
-
*
|
32
|
-
* NOTE that in Storybook 7.0, this type will be renamed to `StoryFn` and replaced by the current `StoryObj` type.
|
33
|
-
*
|
34
|
-
*/
|
35
|
-
export declare type Story<TArgs = Args> = StoryFn<TArgs>;
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import type { Args } from '@storybook/csf';
|
2
|
-
import type { StoryObj } from './types-6-0';
|
3
|
-
export type { StoryFn, StoryObj, Meta } from './types-6-0';
|
4
|
-
/**
|
5
|
-
* Story function that represents a CSFv3 component example.
|
6
|
-
*
|
7
|
-
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
8
|
-
*/
|
9
|
-
export declare type Story<TArgs = Args> = StoryObj<TArgs>;
|
@@ -1,14 +0,0 @@
|
|
1
|
-
export type { RenderContext } from '@storybook/core-client';
|
2
|
-
export declare type StoryFnPreactReturnType = string | Node | preact.JSX.Element;
|
3
|
-
export interface ShowErrorArgs {
|
4
|
-
title: string;
|
5
|
-
description: string;
|
6
|
-
}
|
7
|
-
export interface IStorybookStory {
|
8
|
-
name: string;
|
9
|
-
render: (context: any) => any;
|
10
|
-
}
|
11
|
-
export interface IStorybookSection {
|
12
|
-
kind: string;
|
13
|
-
stories: IStorybookStory[];
|
14
|
-
}
|