@storybook/html 7.0.0-alpha.5 → 7.0.0-alpha.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-SVMFJQBI.mjs +7 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.js +7 -0
- package/dist/config.mjs +1 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.js +7 -0
- package/dist/index.mjs +1 -0
- package/dist/types-becdd26a.d.ts +36 -0
- package/jest.config.js +7 -0
- package/package.json +41 -13
- package/preview.js +1 -1
- package/template/cli/.eslintrc.json +6 -0
- package/template/cli/js/Button.js +21 -0
- package/template/cli/js/Button.stories.js +52 -0
- package/template/cli/js/Header.js +47 -0
- package/template/cli/js/Header.stories.js +28 -0
- package/template/cli/js/Page.js +94 -0
- package/template/cli/js/Page.stories.js +24 -0
- package/template/cli/ts/Button.stories.ts +57 -0
- package/template/cli/ts/Button.ts +51 -0
- package/template/cli/ts/Header.stories.ts +33 -0
- package/template/cli/ts/Header.ts +54 -0
- package/template/cli/ts/Page.stories.ts +27 -0
- package/template/cli/ts/Page.ts +98 -0
- package/template/components/Button.js +9 -0
- package/template/components/Form.js +32 -0
- package/template/components/Html.js +1 -0
- package/template/components/Pre.js +15 -0
- package/template/components/index.js +9 -0
- package/template/stories/README.md +1 -0
- package/template/stories/html-mdx.stories.mdx +21 -0
- package/LICENSE +0 -21
- package/dist/cjs/config.js +0 -36
- package/dist/cjs/docs/config.js +0 -23
- package/dist/cjs/docs/sourceDecorator.js +0 -68
- package/dist/cjs/index.js +0 -84
- package/dist/cjs/preview/config.js +0 -13
- package/dist/cjs/preview/globals.js +0 -10
- package/dist/cjs/preview/index.js +0 -42
- package/dist/cjs/preview/render.js +0 -52
- 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/config.js +0 -6
- package/dist/esm/docs/config.js +0 -12
- package/dist/esm/docs/sourceDecorator.js +0 -53
- package/dist/esm/index.js +0 -4
- package/dist/esm/preview/config.js +0 -1
- package/dist/esm/preview/globals.js +0 -5
- package/dist/esm/preview/index.js +0 -19
- package/dist/esm/preview/render.js +0 -39
- 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/config.d.ts +0 -12
- package/dist/types/docs/config.d.ts +0 -12
- package/dist/types/docs/sourceDecorator.d.ts +0 -3
- package/dist/types/index.d.ts +0 -2
- package/dist/types/preview/config.d.ts +0 -1
- package/dist/types/preview/globals.d.ts +0 -1
- package/dist/types/preview/index.d.ts +0 -24
- package/dist/types/preview/render.d.ts +0 -3
- package/dist/types/preview/types-6-0.d.ts +0 -34
- package/dist/types/preview/types-7-0.d.ts +0 -9
- package/dist/types/preview/types.d.ts +0 -14
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import f from"global";import{dedent as d}from"ts-dedent";import{simulatePageLoad as l,simulateDOMContentLoaded as m}from"@storybook/preview-web";var{Node:u}=f,h=(e,s)=>{let{id:p,component:t}=s;if(typeof t=="string"){let r=t;return Object.keys(e).forEach(o=>{r=r.replace(`{{${o}}}`,e[o])}),r}if(t instanceof HTMLElement){let r=t.cloneNode(!0);return Object.keys(e).forEach(o=>{r.setAttribute(o,typeof e[o]=="string"?e[o]:JSON.stringify(e[o]))}),r}if(typeof t=="function")return t(e,s);throw console.warn(d`
|
|
2
|
+
Storybook's HTML renderer only supports rendering DOM elements and strings.
|
|
3
|
+
Received: ${t}
|
|
4
|
+
`),new Error(`Unable to render story ${p}`)};function M({storyFn:e,kind:s,name:p,showMain:t,showError:r,forceRemount:o},n){let i=e();if(t(),typeof i=="string")n.innerHTML=i,l(n);else if(i instanceof u){if(n.firstChild===i&&o===!1)return;n.innerHTML="",n.appendChild(i),m()}else r({title:`Expecting an HTML snippet or DOM node from the story: "${p}" of "${s}".`,description:d`
|
|
5
|
+
Did you forget to return the HTML snippet from the story?
|
|
6
|
+
Use "() => <your snippet or node>" or when defining the story.
|
|
7
|
+
`})}export{h as a,M as b};
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";var M=Object.create;var d=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var w=(e,r)=>{for(var t in r)d(e,t,{get:r[t],enumerable:!0})},c=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of R(r))!b.call(e,n)&&n!==t&&d(e,n,{get:()=>r[n],enumerable:!(o=E(r,n))||o.enumerable});return e};var A=(e,r,t)=>(t=e!=null?M(L(e)):{},c(r||!e||!e.__esModule?d(t,"default",{value:e,enumerable:!0}):t,e)),F=e=>c(d({},"__esModule",{value:!0}),e);var I={};w(I,{argTypesEnhancers:()=>h,decorators:()=>g,parameters:()=>$,render:()=>H,renderToCanvas:()=>D});module.exports=F(I);var a=require("@storybook/docs-tools");var f=require("@storybook/docs-tools"),m=require("@storybook/addons"),l=require("ts-dedent");function N(e){var o;let r=(o=e==null?void 0:e.parameters.docs)==null?void 0:o.source,t=e==null?void 0:e.parameters.__isArgsStory;return(r==null?void 0:r.type)===f.SourceType.DYNAMIC?!1:!t||(r==null?void 0:r.code)||(r==null?void 0:r.type)===f.SourceType.CODE}function O(e){return(0,l.dedent)(e)}function k(e,r){return((r.parameters.docs??{}).transformSource??O)(e,r)}function S(e,r){var n,s;let t=(s=(n=r==null?void 0:r.parameters.docs)==null?void 0:n.source)!=null&&s.excludeDecorators?r.originalStoryFn(r.args,r):e(),o;return N(r)||(typeof t=="string"?o=t:t instanceof Element&&(o=t.outerHTML),o&&(o=k(o,r))),(0,m.useEffect)(()=>{o&&m.addons.getChannel().emit(f.SNIPPET_RENDERED,r.id,o)}),t}var g=[S],T={docs:{inlineStories:!0,transformSource:void 0,source:{type:a.SourceType.DYNAMIC,language:"html",code:void 0,excludeDecorators:void 0}}},h=[a.enhanceArgTypes];var C=A(require("global")),y=require("ts-dedent"),u=require("@storybook/preview-web"),{Node:_}=C.default,H=(e,r)=>{let{id:t,component:o}=r;if(typeof o=="string"){let n=o;return Object.keys(e).forEach(s=>{n=n.replace(`{{${s}}}`,e[s])}),n}if(o instanceof HTMLElement){let n=o.cloneNode(!0);return Object.keys(e).forEach(s=>{n.setAttribute(s,typeof e[s]=="string"?e[s]:JSON.stringify(e[s]))}),n}if(typeof o=="function")return o(e,r);throw console.warn(y.dedent`
|
|
2
|
+
Storybook's HTML renderer only supports rendering DOM elements and strings.
|
|
3
|
+
Received: ${o}
|
|
4
|
+
`),new Error(`Unable to render story ${t}`)};function D({storyFn:e,kind:r,name:t,showMain:o,showError:n,forceRemount:s},i){let p=e();if(o(),typeof p=="string")i.innerHTML=p,(0,u.simulatePageLoad)(i);else if(p instanceof _){if(i.firstChild===p&&s===!1)return;i.innerHTML="",i.appendChild(p),(0,u.simulateDOMContentLoaded)()}else n({title:`Expecting an HTML snippet or DOM node from the story: "${t}" of "${r}".`,description:y.dedent`
|
|
5
|
+
Did you forget to return the HTML snippet from the story?
|
|
6
|
+
Use "() => <your snippet or node>" or when defining the story.
|
|
7
|
+
`})}var $={framework:"html",...T};0&&(module.exports={argTypesEnhancers,decorators,parameters,render,renderToCanvas});
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as c,b as i}from"./chunk-SVMFJQBI.mjs";import{SourceType as l,enhanceArgTypes as g}from"@storybook/docs-tools";import{SNIPPET_RENDERED as m,SourceType as s}from"@storybook/docs-tools";import{addons as p,useEffect as u}from"@storybook/addons";import{dedent as f}from"ts-dedent";function d(e){let r=e?.parameters.docs?.source,o=e?.parameters.__isArgsStory;return r?.type===s.DYNAMIC?!1:!o||r?.code||r?.type===s.CODE}function y(e){return f(e)}function S(e,r){return((r.parameters.docs??{}).transformSource??y)(e,r)}function n(e,r){let o=r?.parameters.docs?.source?.excludeDecorators?r.originalStoryFn(r.args,r):e(),t;return d(r)||(typeof o=="string"?t=o:o instanceof Element&&(t=o.outerHTML),t&&(t=S(t,r))),u(()=>{t&&p.getChannel().emit(m,r.id,t)}),o}var T=[n],a={docs:{inlineStories:!0,transformSource:void 0,source:{type:l.DYNAMIC,language:"html",code:void 0,excludeDecorators:void 0}}},C=[g];var R={framework:"html",...a};export{C as argTypesEnhancers,T as decorators,R as parameters,c as render,i 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 { H as HtmlRenderer } from './types-becdd26a.js';
|
|
4
|
+
export { H as HtmlRenderer } from './types-becdd26a.js';
|
|
5
|
+
import 'lib/docs-tools/dist';
|
|
6
|
+
import 'lib/types/dist';
|
|
7
|
+
|
|
8
|
+
interface ClientApi extends Addon_ClientStoryApi<HtmlRenderer['storyResult']> {
|
|
9
|
+
configure(loader: Addon_Loadable, module: NodeModule): void;
|
|
10
|
+
forceReRender(): void;
|
|
11
|
+
raw: () => any;
|
|
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
|
+
declare type Meta<TArgs = Args> = ComponentAnnotations<HtmlRenderer, 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
|
+
declare type StoryFn<TArgs = Args> = AnnotatedStoryFn<HtmlRenderer, 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
|
+
declare type StoryObj<TArgs = Args> = StoryAnnotations<HtmlRenderer, 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
|
+
declare type Story<TArgs = Args> = StoryFn<TArgs>;
|
|
46
|
+
declare type Decorator<TArgs = StrictArgs> = DecoratorFunction<HtmlRenderer, TArgs>;
|
|
47
|
+
declare type Loader<TArgs = StrictArgs> = LoaderFunction<HtmlRenderer, TArgs>;
|
|
48
|
+
declare type StoryContext<TArgs = StrictArgs> = StoryContext$1<HtmlRenderer, TArgs>;
|
|
49
|
+
|
|
50
|
+
export { Decorator, Loader, Meta, Story, StoryContext, StoryFn, StoryObj, configure, forceReRender, raw, storiesOf };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";var g=Object.create;var s=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var L=(e,t)=>{for(var r in t)s(e,r,{get:t[r],enumerable:!0})},c=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of b(t))!w.call(e,o)&&o!==r&&s(e,o,{get:()=>t[o],enumerable:!(n=M(t,o))||n.enumerable});return e};var a=(e,t,r)=>(r=e!=null?g(h(e)):{},c(t||!e||!e.__esModule?s(r,"default",{value:e,enumerable:!0}):r,e)),T=e=>c(s({},"__esModule",{value:!0}),e);var D={};L(D,{configure:()=>E,forceReRender:()=>N,raw:()=>$,storiesOf:()=>_});module.exports=T(D);var u=a(require("global")),{window:x}=u.default;x.STORYBOOK_ENV="HTML";var C=require("@storybook/core-client");var y=a(require("global")),m=require("ts-dedent"),f=require("@storybook/preview-web"),{Node:S}=y.default,R=(e,t)=>{let{id:r,component:n}=t;if(typeof n=="string"){let o=n;return Object.keys(e).forEach(i=>{o=o.replace(`{{${i}}}`,e[i])}),o}if(n instanceof HTMLElement){let o=n.cloneNode(!0);return Object.keys(e).forEach(i=>{o.setAttribute(i,typeof e[i]=="string"?e[i]:JSON.stringify(e[i]))}),o}if(typeof n=="function")return n(e,t);throw console.warn(m.dedent`
|
|
2
|
+
Storybook's HTML renderer only supports rendering DOM elements and strings.
|
|
3
|
+
Received: ${n}
|
|
4
|
+
`),new Error(`Unable to render story ${r}`)};function A({storyFn:e,kind:t,name:r,showMain:n,showError:o,forceRemount:i},d){let p=e();if(n(),typeof p=="string")d.innerHTML=p,(0,f.simulatePageLoad)(d);else if(p instanceof S){if(d.firstChild===p&&i===!1)return;d.innerHTML="",d.appendChild(p),(0,f.simulateDOMContentLoaded)()}else o({title:`Expecting an HTML snippet or DOM node from the story: "${r}" of "${t}".`,description:m.dedent`
|
|
5
|
+
Did you forget to return the HTML snippet from the story?
|
|
6
|
+
Use "() => <your snippet or node>" or when defining the story.
|
|
7
|
+
`})}var H="html",l=(0,C.start)(A,{render:R}),_=(e,t)=>l.clientApi.storiesOf(e,t).addParameters({framework:H}),E=(...e)=>l.configure(H,...e),N=l.forceReRender,$=l.clientApi.raw;var O;(O=module==null?void 0:module.hot)==null||O.decline();0&&(module.exports={configure,forceReRender,raw,storiesOf});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as r,b as t}from"./chunk-SVMFJQBI.mjs";import d from"global";var{window:p}=d;p.STORYBOOK_ENV="HTML";import{start as l}from"@storybook/core-client";var n="html",e=l(t,{render:r}),m=(o,i)=>e.clientApi.storiesOf(o,i).addParameters({framework:n}),c=(...o)=>e.configure(n,...o),R=e.forceReRender,A=e.clientApi.raw;module?.hot?.decline();export{c as configure,R as forceReRender,A as raw,m as storiesOf};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { PartialStoryFn, ArgsStoryFn, Store_RenderContext, WebRenderer, StoryContext as StoryContext$1 } from '@storybook/types';
|
|
2
|
+
import * as lib_docs_tools_dist from 'lib/docs-tools/dist';
|
|
3
|
+
import * as lib_types_dist from 'lib/types/dist';
|
|
4
|
+
|
|
5
|
+
declare function sourceDecorator(storyFn: PartialStoryFn<HtmlRenderer>, context: StoryContext): StoryFnHtmlReturnType;
|
|
6
|
+
|
|
7
|
+
declare const decorators: (typeof sourceDecorator)[];
|
|
8
|
+
declare const argTypesEnhancers: (<TRenderer extends lib_types_dist.Renderer>(context: lib_types_dist.StoryContextForEnhancers<TRenderer, lib_types_dist.Args>) => lib_types_dist.StrictArgTypes<lib_types_dist.Args>)[];
|
|
9
|
+
|
|
10
|
+
declare const render: ArgsStoryFn<HtmlRenderer>;
|
|
11
|
+
declare function renderToCanvas({ storyFn, kind, name, showMain, showError, forceRemount }: Store_RenderContext<HtmlRenderer>, canvasElement: HtmlRenderer['canvasElement']): void;
|
|
12
|
+
|
|
13
|
+
declare const parameters: {
|
|
14
|
+
docs: {
|
|
15
|
+
inlineStories: boolean;
|
|
16
|
+
transformSource: unknown;
|
|
17
|
+
source: {
|
|
18
|
+
type: lib_docs_tools_dist.SourceType;
|
|
19
|
+
language: string;
|
|
20
|
+
code: unknown;
|
|
21
|
+
excludeDecorators: unknown;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
framework: "html";
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare type StoryFnHtmlReturnType = string | Node;
|
|
28
|
+
interface HtmlRenderer extends WebRenderer {
|
|
29
|
+
component: string | HTMLElement | ArgsStoryFn<HtmlRenderer>;
|
|
30
|
+
storyResult: StoryFnHtmlReturnType;
|
|
31
|
+
}
|
|
32
|
+
declare type StoryContext = StoryContext$1<HtmlRenderer> & {
|
|
33
|
+
parameters: StoryContext$1<HtmlRenderer>['parameters'] & typeof parameters;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { HtmlRenderer as H, argTypesEnhancers as a, render as b, decorators as d, parameters as p, renderToCanvas as r };
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/html",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.50",
|
|
4
4
|
"description": "Storybook HTML renderer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -19,31 +19,52 @@
|
|
|
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
|
-
"@storybook/
|
|
40
|
-
"@storybook/
|
|
41
|
-
"core-js": "^3.8.2",
|
|
54
|
+
"@storybook/addons": "7.0.0-alpha.50",
|
|
55
|
+
"@storybook/core-client": "7.0.0-alpha.50",
|
|
56
|
+
"@storybook/docs-tools": "7.0.0-alpha.50",
|
|
57
|
+
"@storybook/preview-web": "7.0.0-alpha.50",
|
|
58
|
+
"@storybook/store": "7.0.0-alpha.50",
|
|
59
|
+
"@storybook/types": "7.0.0-alpha.50",
|
|
42
60
|
"global": "^4.4.0",
|
|
43
61
|
"react": "16.14.0",
|
|
44
62
|
"react-dom": "16.14.0",
|
|
45
63
|
"ts-dedent": "^2.0.0"
|
|
46
64
|
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"typescript": "~4.6.3"
|
|
67
|
+
},
|
|
47
68
|
"peerDependencies": {
|
|
48
69
|
"@babel/core": "*"
|
|
49
70
|
},
|
|
@@ -53,5 +74,12 @@
|
|
|
53
74
|
"publishConfig": {
|
|
54
75
|
"access": "public"
|
|
55
76
|
},
|
|
56
|
-
"
|
|
77
|
+
"bundler": {
|
|
78
|
+
"entries": [
|
|
79
|
+
"./src/index.ts",
|
|
80
|
+
"./src/config.ts"
|
|
81
|
+
],
|
|
82
|
+
"platform": "browser"
|
|
83
|
+
},
|
|
84
|
+
"gitHead": "77184d039091f4782dc4540df6d271a24fb3e242"
|
|
57
85
|
}
|
package/preview.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './dist/
|
|
1
|
+
export * from './dist/config';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import './button.css';
|
|
2
|
+
|
|
3
|
+
export const createButton = ({
|
|
4
|
+
primary = false,
|
|
5
|
+
size = 'medium',
|
|
6
|
+
backgroundColor,
|
|
7
|
+
label,
|
|
8
|
+
onClick,
|
|
9
|
+
}) => {
|
|
10
|
+
const btn = document.createElement('button');
|
|
11
|
+
btn.type = 'button';
|
|
12
|
+
btn.innerText = label;
|
|
13
|
+
btn.addEventListener('click', onClick);
|
|
14
|
+
|
|
15
|
+
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
16
|
+
btn.className = ['storybook-button', `storybook-button--${size}`, mode].join(' ');
|
|
17
|
+
|
|
18
|
+
btn.style.backgroundColor = backgroundColor;
|
|
19
|
+
|
|
20
|
+
return btn;
|
|
21
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { createButton } from './Button';
|
|
2
|
+
|
|
3
|
+
// More on default export: https://storybook.js.org/docs/html/writing-stories/introduction#default-export
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Example/Button',
|
|
6
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/html/writing-docs/docs-page
|
|
7
|
+
tags: ['docsPage'],
|
|
8
|
+
// More on component templates: https://storybook.js.org/docs/html/writing-stories/introduction#using-args
|
|
9
|
+
render: ({ label, ...args }) => {
|
|
10
|
+
// You can either use a function to create DOM elements or use a plain html string!
|
|
11
|
+
// return `<div>${label}</div>`;
|
|
12
|
+
return createButton({ label, ...args });
|
|
13
|
+
},
|
|
14
|
+
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
|
15
|
+
argTypes: {
|
|
16
|
+
backgroundColor: { control: 'color' },
|
|
17
|
+
label: { control: 'text' },
|
|
18
|
+
onClick: { action: 'onClick' },
|
|
19
|
+
primary: { control: 'boolean' },
|
|
20
|
+
size: {
|
|
21
|
+
control: { type: 'select' },
|
|
22
|
+
options: ['small', 'medium', 'large'],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const Primary = {
|
|
28
|
+
args: {
|
|
29
|
+
primary: true,
|
|
30
|
+
label: 'Button',
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const Secondary = {
|
|
35
|
+
args: {
|
|
36
|
+
label: 'Button',
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const Large = {
|
|
41
|
+
args: {
|
|
42
|
+
size: 'large',
|
|
43
|
+
label: 'Button',
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const Small = {
|
|
48
|
+
args: {
|
|
49
|
+
size: 'small',
|
|
50
|
+
label: 'Button',
|
|
51
|
+
},
|
|
52
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import './header.css';
|
|
2
|
+
import { createButton } from './Button';
|
|
3
|
+
|
|
4
|
+
export const createHeader = ({ user, onLogout, onLogin, onCreateAccount }) => {
|
|
5
|
+
const header = document.createElement('header');
|
|
6
|
+
|
|
7
|
+
const wrapper = document.createElement('div');
|
|
8
|
+
wrapper.className = 'wrapper';
|
|
9
|
+
|
|
10
|
+
const logo = `<div>
|
|
11
|
+
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
|
12
|
+
<g fill="none" fillRule="evenodd">
|
|
13
|
+
<path
|
|
14
|
+
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
|
15
|
+
fill="#FFF" />
|
|
16
|
+
<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
|
+
<path d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" fill="#91BAF8" />
|
|
20
|
+
</g>
|
|
21
|
+
</svg>
|
|
22
|
+
<h1>Acme</h1>
|
|
23
|
+
</div>`;
|
|
24
|
+
|
|
25
|
+
wrapper.insertAdjacentHTML('afterbegin', logo);
|
|
26
|
+
|
|
27
|
+
const account = document.createElement('div');
|
|
28
|
+
if (user) {
|
|
29
|
+
const welcomeMessage = `<span class="welcome">Welcome, <b>${user.name}</b>!</span>`;
|
|
30
|
+
account.innerHTML = welcomeMessage;
|
|
31
|
+
account.appendChild(createButton({ size: 'small', label: 'Log out', onClick: onLogout }));
|
|
32
|
+
} else {
|
|
33
|
+
account.appendChild(createButton({ size: 'small', label: 'Log in', onClick: onLogin }));
|
|
34
|
+
account.appendChild(
|
|
35
|
+
createButton({
|
|
36
|
+
size: 'small',
|
|
37
|
+
label: 'Sign up',
|
|
38
|
+
onClick: onCreateAccount,
|
|
39
|
+
primary: true,
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
wrapper.appendChild(account);
|
|
44
|
+
header.appendChild(wrapper);
|
|
45
|
+
|
|
46
|
+
return header;
|
|
47
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createHeader } from './Header';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
title: 'Example/Header',
|
|
5
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/html/writing-docs/docs-page
|
|
6
|
+
tags: ['docsPage'],
|
|
7
|
+
render: (args) => createHeader(args),
|
|
8
|
+
parameters: {
|
|
9
|
+
// More on Story layout: https://storybook.js.org/docs/html/configure/story-layout
|
|
10
|
+
layout: 'fullscreen',
|
|
11
|
+
},
|
|
12
|
+
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
|
13
|
+
argTypes: {
|
|
14
|
+
onLogin: { action: 'onLogin' },
|
|
15
|
+
onLogout: { action: 'onLogout' },
|
|
16
|
+
onCreateAccount: { action: 'onCreateAccount' },
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const LoggedIn = {
|
|
21
|
+
args: {
|
|
22
|
+
user: {
|
|
23
|
+
name: 'Jane Doe',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const LoggedOut = {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import './page.css';
|
|
2
|
+
import { createHeader } from './Header';
|
|
3
|
+
|
|
4
|
+
export const createPage = () => {
|
|
5
|
+
const article = document.createElement('article');
|
|
6
|
+
let user = null;
|
|
7
|
+
let header = null;
|
|
8
|
+
|
|
9
|
+
const rerenderHeader = () => {
|
|
10
|
+
const wrapper = document.getElementsByTagName('article')[0];
|
|
11
|
+
wrapper.replaceChild(createHeaderElement(), wrapper.firstChild);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const onLogin = () => {
|
|
15
|
+
user = { name: 'Jane Doe' };
|
|
16
|
+
rerenderHeader();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const onLogout = () => {
|
|
20
|
+
user = null;
|
|
21
|
+
rerenderHeader();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const onCreateAccount = () => {
|
|
25
|
+
user = { name: 'Jane Doe' };
|
|
26
|
+
rerenderHeader();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const createHeaderElement = () => {
|
|
30
|
+
return createHeader({ onLogin, onLogout, onCreateAccount, user });
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
header = createHeaderElement();
|
|
34
|
+
article.appendChild(header);
|
|
35
|
+
|
|
36
|
+
const section = `
|
|
37
|
+
<section>
|
|
38
|
+
<h2>Pages in Storybook</h2>
|
|
39
|
+
<p>
|
|
40
|
+
We recommend building UIs with a
|
|
41
|
+
<a
|
|
42
|
+
href="https://blog.hichroma.com/component-driven-development-ce1109d56c8e"
|
|
43
|
+
target="_blank"
|
|
44
|
+
rel="noopener noreferrer">
|
|
45
|
+
<strong>component-driven</strong>
|
|
46
|
+
</a>
|
|
47
|
+
process starting with atomic components and ending with pages.
|
|
48
|
+
</p>
|
|
49
|
+
<p>
|
|
50
|
+
Render pages with mock data. This makes it easy to build and review page states without
|
|
51
|
+
needing to navigate to them in your app. Here are some handy patterns for managing page data
|
|
52
|
+
in Storybook:
|
|
53
|
+
</p>
|
|
54
|
+
<ul>
|
|
55
|
+
<li>
|
|
56
|
+
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
57
|
+
"args" of child component stories
|
|
58
|
+
</li>
|
|
59
|
+
<li>
|
|
60
|
+
Assemble data in the page component from your services. You can mock these services out
|
|
61
|
+
using Storybook.
|
|
62
|
+
</li>
|
|
63
|
+
</ul>
|
|
64
|
+
<p>
|
|
65
|
+
Get a guided tutorial on component-driven development at
|
|
66
|
+
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
|
|
67
|
+
Storybook tutorials
|
|
68
|
+
</a>
|
|
69
|
+
. Read more in the
|
|
70
|
+
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">docs</a>
|
|
71
|
+
.
|
|
72
|
+
</p>
|
|
73
|
+
<div class="tip-wrapper">
|
|
74
|
+
<span class="tip">Tip</span>
|
|
75
|
+
Adjust the width of the canvas with the
|
|
76
|
+
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
|
77
|
+
<g fill="none" fillRule="evenodd">
|
|
78
|
+
<path
|
|
79
|
+
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0
|
|
80
|
+
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
|
|
81
|
+
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"
|
|
82
|
+
id="a"
|
|
83
|
+
fill="#999" />
|
|
84
|
+
</g>
|
|
85
|
+
</svg>
|
|
86
|
+
Viewports addon in the toolbar
|
|
87
|
+
</div>
|
|
88
|
+
</section>
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
article.insertAdjacentHTML('beforeend', section);
|
|
92
|
+
|
|
93
|
+
return article;
|
|
94
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { within, userEvent } from '@storybook/testing-library';
|
|
2
|
+
import { createPage } from './Page';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Example/Page',
|
|
6
|
+
render: () => createPage(),
|
|
7
|
+
parameters: {
|
|
8
|
+
// More on Story layout: https://storybook.js.org/docs/html/configure/story-layout
|
|
9
|
+
layout: 'fullscreen',
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const LoggedOut = {};
|
|
14
|
+
|
|
15
|
+
// More on interaction testing: https://storybook.js.org/docs/html/writing-tests/interaction-testing
|
|
16
|
+
export const LoggedIn = {
|
|
17
|
+
play: async ({ canvasElement }) => {
|
|
18
|
+
const canvas = within(canvasElement);
|
|
19
|
+
const loginButton = await canvas.getByRole('button', {
|
|
20
|
+
name: /Log in/i,
|
|
21
|
+
});
|
|
22
|
+
await userEvent.click(loginButton);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { StoryObj, Meta } from '@storybook/html';
|
|
2
|
+
import type { ButtonProps } from './Button';
|
|
3
|
+
import { createButton } from './Button';
|
|
4
|
+
|
|
5
|
+
// More on how to set up stories at: https://storybook.js.org/docs/html/writing-stories/introduction#default-export
|
|
6
|
+
const meta: Meta<ButtonProps> = {
|
|
7
|
+
title: 'Example/Button',
|
|
8
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/html/writing-docs/docs-page
|
|
9
|
+
tags: ['docsPage'],
|
|
10
|
+
render: (args) => {
|
|
11
|
+
// You can either use a function to create DOM elements or use a plain html string!
|
|
12
|
+
// return `<div>${label}</div>`;
|
|
13
|
+
return createButton(args);
|
|
14
|
+
},
|
|
15
|
+
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
|
16
|
+
argTypes: {
|
|
17
|
+
backgroundColor: { control: 'color' },
|
|
18
|
+
label: { control: 'text' },
|
|
19
|
+
onClick: { action: 'onClick' },
|
|
20
|
+
primary: { control: 'boolean' },
|
|
21
|
+
size: {
|
|
22
|
+
control: { type: 'select' },
|
|
23
|
+
options: ['small', 'medium', 'large'],
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default meta;
|
|
29
|
+
type Story = StoryObj<ButtonProps>;
|
|
30
|
+
|
|
31
|
+
// More on component templates: https://storybook.js.org/docs/html/writing-stories/introduction#using-args
|
|
32
|
+
export const Primary: Story = {
|
|
33
|
+
args: {
|
|
34
|
+
primary: true,
|
|
35
|
+
label: 'Button',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const Secondary: Story = {
|
|
40
|
+
args: {
|
|
41
|
+
label: 'Button',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const Large: Story = {
|
|
46
|
+
args: {
|
|
47
|
+
size: 'large',
|
|
48
|
+
label: 'Button',
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const Small: Story = {
|
|
53
|
+
args: {
|
|
54
|
+
size: 'small',
|
|
55
|
+
label: 'Button',
|
|
56
|
+
},
|
|
57
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import './button.css';
|
|
2
|
+
|
|
3
|
+
export interface ButtonProps {
|
|
4
|
+
/**
|
|
5
|
+
* Is this the principal call to action on the page?
|
|
6
|
+
*/
|
|
7
|
+
primary?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* What background color to use
|
|
10
|
+
*/
|
|
11
|
+
backgroundColor?: string;
|
|
12
|
+
/**
|
|
13
|
+
* How large should the button be?
|
|
14
|
+
*/
|
|
15
|
+
size?: 'small' | 'medium' | 'large';
|
|
16
|
+
/**
|
|
17
|
+
* Button contents
|
|
18
|
+
*/
|
|
19
|
+
label: string;
|
|
20
|
+
/**
|
|
21
|
+
* Optional click handler
|
|
22
|
+
*/
|
|
23
|
+
onClick?: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Primary UI component for user interaction
|
|
28
|
+
*/
|
|
29
|
+
export const createButton = ({
|
|
30
|
+
primary = false,
|
|
31
|
+
size = 'medium',
|
|
32
|
+
backgroundColor,
|
|
33
|
+
label,
|
|
34
|
+
onClick,
|
|
35
|
+
}: ButtonProps) => {
|
|
36
|
+
const btn = document.createElement('button');
|
|
37
|
+
btn.type = 'button';
|
|
38
|
+
btn.innerText = label;
|
|
39
|
+
if (onClick) {
|
|
40
|
+
btn.addEventListener('click', onClick);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
44
|
+
btn.className = ['storybook-button', `storybook-button--${size}`, mode].join(' ');
|
|
45
|
+
|
|
46
|
+
if (backgroundColor) {
|
|
47
|
+
btn.style.backgroundColor = backgroundColor;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return btn;
|
|
51
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/html';
|
|
2
|
+
import type { HeaderProps } from './Header';
|
|
3
|
+
import { createHeader } from './Header';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<HeaderProps> = {
|
|
6
|
+
title: 'Example/Header',
|
|
7
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/html/writing-docs/docs-page
|
|
8
|
+
tags: ['docsPage'],
|
|
9
|
+
render: (args) => createHeader(args),
|
|
10
|
+
parameters: {
|
|
11
|
+
// More on Story layout: https://storybook.js.org/docs/html/configure/story-layout
|
|
12
|
+
layout: 'fullscreen',
|
|
13
|
+
},
|
|
14
|
+
// More on argTypes: https://storybook.js.org/docs/html/api/argtypes
|
|
15
|
+
argTypes: {
|
|
16
|
+
onLogin: { action: 'onLogin' },
|
|
17
|
+
onLogout: { action: 'onLogout' },
|
|
18
|
+
onCreateAccount: { action: 'onCreateAccount' },
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default meta;
|
|
23
|
+
type Story = StoryObj<HeaderProps>;
|
|
24
|
+
|
|
25
|
+
export const LoggedIn: Story = {
|
|
26
|
+
args: {
|
|
27
|
+
user: {
|
|
28
|
+
name: 'John Doe',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const LoggedOut: Story = {};
|