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

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.
@@ -0,0 +1,7 @@
1
+ import global from"global";import{dedent}from"ts-dedent";import{simulatePageLoad,simulateDOMContentLoaded}from"@storybook/preview-api";var{Node}=global,render=(args,context)=>{let{id,component:Component}=context;if(typeof Component=="string"){let output=Component;return Object.keys(args).forEach(key=>{output=output.replace(`{{${key}}}`,args[key])}),output}if(Component instanceof HTMLElement){let output=Component.cloneNode(!0);return Object.keys(args).forEach(key=>{output.setAttribute(key,typeof args[key]=="string"?args[key]:JSON.stringify(args[key]))}),output}if(typeof Component=="function")return Component(args,context);throw console.warn(dedent`
2
+ Storybook's HTML renderer only supports rendering DOM elements and strings.
3
+ Received: ${Component}
4
+ `),new Error(`Unable to render story ${id}`)};function renderToCanvas({storyFn,kind,name,showMain,showError,forceRemount},canvasElement){let element=storyFn();if(showMain(),typeof element=="string")canvasElement.innerHTML=element,simulatePageLoad(canvasElement);else if(element instanceof Node){if(canvasElement.firstChild===element&&forceRemount===!1)return;canvasElement.innerHTML="",canvasElement.appendChild(element),simulateDOMContentLoaded()}else showError({title:`Expecting an HTML snippet or DOM node from the story: "${name}" of "${kind}".`,description: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
+ `})}export{render,renderToCanvas};
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import 'lib/docs-tools/dist/types';
2
- export { d as decorators, p as parameters, r as renderToDOM } from './types-f5d03672.js';
3
- import '@storybook/csf';
4
- import '@storybook/store';
1
+ import 'lib/docs-tools/dist';
2
+ export { a as argTypesEnhancers, d as decorators, p as parameters, b as render, r as renderToCanvas } from './types-fb08647b.js';
3
+ import '@storybook/types';
4
+ import 'lib/types/dist';
package/dist/config.js CHANGED
@@ -1,4 +1,7 @@
1
- var E=Object.create;var n=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames,y=Object.getOwnPropertySymbols,_=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty,k=Object.prototype.propertyIsEnumerable;var g=(e,r,o)=>r in e?n(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,S=(e,r)=>{for(var o in r||(r={}))D.call(r,o)&&g(e,o,r[o]);if(y)for(var o of y(r))k.call(r,o)&&g(e,o,r[o]);return e};var i=(e,r)=>n(e,"name",{value:r,configurable:!0});var w=(e,r)=>{for(var o in r)n(e,o,{get:r[o],enumerable:!0})},T=(e,r,o,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of R(r))!D.call(e,t)&&t!==o&&n(e,t,{get:()=>r[t],enumerable:!(s=I(r,t))||s.enumerable});return e};var c=(e,r,o)=>(o=e!=null?E(_(e)):{},T(r||!e||!e.__esModule?n(o,"default",{value:e,enumerable:!0}):o,e)),Y=e=>T(n({},"__esModule",{value:!0}),e);var q={};w(q,{decorators:()=>L,parameters:()=>j,renderToDOM:()=>A});module.exports=Y(q);var C=require("@storybook/docs-tools");var a=require("@storybook/docs-tools"),u=require("@storybook/addons"),M=c(require("ts-dedent"));function $(e){var s;let r=(s=e==null?void 0:e.parameters.docs)==null?void 0:s.source,o=e==null?void 0:e.parameters.__isArgsStory;return(r==null?void 0:r.type)===a.SourceType.DYNAMIC?!1:!o||(r==null?void 0:r.code)||(r==null?void 0:r.type)===a.SourceType.CODE}i($,"skipSourceRender");function b(e){return(0,M.default)(e)}i(b,"defaultTransformSource");function F(e,r){return((r.parameters.docs??{}).transformSource??b)(e,r)}i(F,"applyTransformSource");function h(e,r){var t,d;let o=(d=(t=r==null?void 0:r.parameters.docs)==null?void 0:t.source)!=null&&d.excludeDecorators?r.originalStoryFn(r.args,r):e(),s;return $(r)||(typeof o=="string"?s=o:o instanceof Element&&(s=o.outerHTML),s&&(s=F(s,r))),(0,u.useEffect)(()=>{s&&u.addons.getChannel().emit(a.SNIPPET_RENDERED,r.id,s)}),o}i(h,"sourceDecorator");var L=[h],H={docs:{inlineStories:!0,transformSource:void 0,source:{type:C.SourceType.DYNAMIC,language:"html",code:void 0,excludeDecorators:void 0}}};var N=c(require("global")),O=c(require("ts-dedent")),m=require("@storybook/preview-web"),{Node:U}=N.default;function A({storyFn:e,kind:r,name:o,showMain:s,showError:t,forceRemount:d},f){let p=e();if(s(),typeof p=="string")f.innerHTML=p,(0,m.simulatePageLoad)(f);else if(p instanceof U){if(f.firstChild===p&&d===!1)return;f.innerHTML="",f.appendChild(p),(0,m.simulateDOMContentLoaded)()}else t({title:`Expecting an HTML snippet or DOM node from the story: "${o}" of "${r}".`,description:O.default`
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 _={};w(_,{argTypesEnhancers:()=>h,decorators:()=>g,parameters:()=>I,render:()=>H,renderToCanvas:()=>D});module.exports=F(_);var a=require("@storybook/docs-tools");var f=require("@storybook/docs-tools"),m=require("@storybook/preview-api"),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-api"),{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`
2
5
  Did you forget to return the HTML snippet from the story?
3
6
  Use "() => <your snippet or node>" or when defining the story.
4
- `})}i(A,"renderToDOM");var j=S({framework:"html"},H);0&&(module.exports={decorators,parameters,renderToDOM});
7
+ `})}var I={framework:"html",...T};0&&(module.exports={argTypesEnhancers,decorators,parameters,render,renderToCanvas});
package/dist/config.mjs CHANGED
@@ -1 +1 @@
1
- import{a as u,b as f,c}from"./chunk-RJRHENSI.mjs";import{SourceType as A}from"@storybook/docs-tools";import{SNIPPET_RENDERED as l,SourceType as m}from"@storybook/docs-tools";import{addons as S,useEffect as y}from"@storybook/addons";import D from"ts-dedent";function g(e){var o;let r=(o=e==null?void 0:e.parameters.docs)==null?void 0:o.source,s=e==null?void 0:e.parameters.__isArgsStory;return(r==null?void 0:r.type)===m.DYNAMIC?!1:!s||(r==null?void 0:r.code)||(r==null?void 0:r.type)===m.CODE}f(g,"skipSourceRender");function E(e){return D(e)}f(E,"defaultTransformSource");function T(e,r){return((r.parameters.docs??{}).transformSource??E)(e,r)}f(T,"applyTransformSource");function t(e,r){var i,a;let s=(a=(i=r==null?void 0:r.parameters.docs)==null?void 0:i.source)!=null&&a.excludeDecorators?r.originalStoryFn(r.args,r):e(),o;return g(r)||(typeof s=="string"?o=s:s instanceof Element&&(o=s.outerHTML),o&&(o=T(o,r))),y(()=>{o&&S.getChannel().emit(l,r.id,o)}),s}f(t,"sourceDecorator");var C=[t],d={docs:{inlineStories:!0,transformSource:void 0,source:{type:A.DYNAMIC,language:"html",code:void 0,excludeDecorators:void 0}}};var Y=u({framework:"html"},d);export{C as decorators,Y as parameters,c as renderToDOM};
1
+ import{render,renderToCanvas}from"./chunk-ZJLPYI6H.mjs";import{SourceType as SourceType2,enhanceArgTypes}from"@storybook/docs-tools";import{SNIPPET_RENDERED,SourceType}from"@storybook/docs-tools";import{addons,useEffect}from"@storybook/preview-api";import{dedent}from"ts-dedent";function skipSourceRender(context){let sourceParams=context?.parameters.docs?.source,isArgsStory=context?.parameters.__isArgsStory;return sourceParams?.type===SourceType.DYNAMIC?!1:!isArgsStory||sourceParams?.code||sourceParams?.type===SourceType.CODE}function defaultTransformSource(source){return dedent(source)}function applyTransformSource(source,context){return((context.parameters.docs??{}).transformSource??defaultTransformSource)(source,context)}function sourceDecorator(storyFn,context){let story=context?.parameters.docs?.source?.excludeDecorators?context.originalStoryFn(context.args,context):storyFn(),source;return skipSourceRender(context)||(typeof story=="string"?source=story:story instanceof Element&&(source=story.outerHTML),source&&(source=applyTransformSource(source,context))),useEffect(()=>{source&&addons.getChannel().emit(SNIPPET_RENDERED,context.id,source)}),story}var decorators=[sourceDecorator],parameters={docs:{inlineStories:!0,transformSource:void 0,source:{type:SourceType2.DYNAMIC,language:"html",code:void 0,excludeDecorators:void 0}}},argTypesEnhancers=[enhanceArgTypes];var parameters2={framework:"html",...parameters};export{argTypesEnhancers,decorators,parameters2 as parameters,render,renderToCanvas};
package/dist/index.d.ts CHANGED
@@ -1,26 +1,18 @@
1
- import { ClientStoryApi, Loadable } from '@storybook/addons';
2
- import { H as HtmlFramework, I as IStorybookSection } from './types-f5d03672.js';
3
- import { Args, ComponentAnnotations, AnnotatedStoryFn, StoryAnnotations } from '@storybook/csf';
4
- export { ArgTypes, Args, Parameters } from '@storybook/csf';
5
- import 'lib/docs-tools/dist/types';
6
- import '@storybook/store';
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-fb08647b.js';
4
+ export { H as HtmlRenderer } from './types-fb08647b.js';
5
+ import 'lib/docs-tools/dist';
6
+ import 'lib/types/dist';
7
7
 
8
- interface ClientApi extends ClientStoryApi<HtmlFramework['storyResult']> {
9
- setAddon(addon: any): void;
10
- configure(loader: Loadable, module: NodeModule): void;
11
- getStorybook(): IStorybookSection[];
12
- clearDecorators(): void;
8
+ interface ClientApi extends Addon_ClientStoryApi<HtmlRenderer['storyResult']> {
9
+ configure(loader: Addon_Loadable, module: NodeModule): void;
13
10
  forceReRender(): void;
14
11
  raw: () => any;
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<HtmlFramework, TArgs>;
23
+ type Meta<TArgs = Args> = ComponentAnnotations<HtmlRenderer, 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<HtmlFramework, TArgs>;
29
+ type StoryFn<TArgs = Args> = AnnotatedStoryFn<HtmlRenderer, 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<HtmlFramework, TArgs>;
35
+ type StoryObj<TArgs = Args> = StoryAnnotations<HtmlRenderer, 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<HtmlRenderer, TArgs>;
47
+ type Loader<TArgs = StrictArgs> = LoaderFunction<HtmlRenderer, TArgs>;
48
+ type StoryContext<TArgs = StrictArgs> = StoryContext$1<HtmlRenderer, TArgs>;
50
49
 
51
- export { Meta, Story, StoryFn, StoryObj, addDecorator, addParameters, clearDecorators, configure, forceReRender, getStorybook, raw, setAddon, storiesOf };
50
+ export { Decorator, Loader, Meta, Story, StoryContext, StoryFn, StoryObj, configure, forceReRender, raw, storiesOf };
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
- var y=Object.create;var p=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var c=(o,e)=>p(o,"name",{value:e,configurable:!0});var b=(o,e)=>{for(var t in e)p(o,t,{get:e[t],enumerable:!0})},m=(o,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of w(e))!R.call(o,n)&&n!==t&&p(o,n,{get:()=>e[n],enumerable:!(a=T(e,n))||a.enumerable});return o};var l=(o,e,t)=>(t=o!=null?y(L(o)):{},m(e||!o||!o.__esModule?p(t,"default",{value:o,enumerable:!0}):t,o)),H=o=>m(p({},"__esModule",{value:!0}),o);var V={};b(V,{addDecorator:()=>K,addParameters:()=>N,clearDecorators:()=>W,configure:()=>S,forceReRender:()=>B,getStorybook:()=>F,raw:()=>U,setAddon:()=>$,storiesOf:()=>C});module.exports=H(V);var x=l(require("global")),{window:P}=x.default;P.STORYBOOK_ENV="HTML";var M=require("@storybook/core-client");var g=l(require("global")),u=l(require("ts-dedent")),f=require("@storybook/preview-web"),{Node:k}=g.default;function A({storyFn:o,kind:e,name:t,showMain:a,showError:n,forceRemount:D},i){let s=o();if(a(),typeof s=="string")i.innerHTML=s,(0,f.simulatePageLoad)(i);else if(s instanceof k){if(i.firstChild===s&&D===!1)return;i.innerHTML="",i.appendChild(s),(0,f.simulateDOMContentLoaded)()}else n({title:`Expecting an HTML snippet or DOM node from the story: "${t}" of "${e}".`,description:u.default`
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:()=>N,forceReRender:()=>_,raw:()=>$,storiesOf:()=>E});module.exports=T(D);var u=a(require("global")),{window:x}=u.default;x.STORYBOOK_ENV="HTML";var C=require("@storybook/preview-api");var y=a(require("global")),m=require("ts-dedent"),f=require("@storybook/preview-api"),{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`
2
5
  Did you forget to return the HTML snippet from the story?
3
6
  Use "() => <your snippet or node>" or when defining the story.
4
- `})}c(A,"renderToDOM");var O="html",r=(0,M.start)(A),C=c((o,e)=>r.clientApi.storiesOf(o,e).addParameters({framework:O}),"storiesOf"),S=c((...o)=>r.configure(O,...o),"configure"),K=r.clientApi.addDecorator,N=r.clientApi.addParameters,W=r.clientApi.clearDecorators,$=r.clientApi.setAddon,B=r.forceReRender,F=r.clientApi.getStorybook,U=r.clientApi.raw;var h;(h=module==null?void 0:module.hot)==null||h.decline();0&&(module.exports={addDecorator,addParameters,clearDecorators,configure,forceReRender,getStorybook,raw,setAddon,storiesOf});
7
+ `})}var H="html",l=(0,C.start)(A,{render:R}),E=(e,t)=>l.clientApi.storiesOf(e,t).addParameters({framework:H}),N=(...e)=>l.configure(H,...e),_=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 CHANGED
@@ -1 +1 @@
1
- import{b as t,c as n}from"./chunk-RJRHENSI.mjs";import s from"global";var{window:d}=s;d.STORYBOOK_ENV="HTML";import{start as l}from"@storybook/core-client";var i="html",o=l(n),A=t((r,p)=>o.clientApi.storiesOf(r,p).addParameters({framework:i}),"storiesOf"),O=t((...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 a;(a=module==null?void 0:module.hot)==null||a.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{render,renderToCanvas}from"./chunk-ZJLPYI6H.mjs";import global from"global";var{window:globalWindow}=global;globalWindow.STORYBOOK_ENV="HTML";import{start}from"@storybook/preview-api";var FRAMEWORK="html",api=start(renderToCanvas,{render}),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,36 @@
1
+ import { PartialStoryFn, ArgsStoryFn, 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 }: 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
+ type StoryFnHtmlReturnType = string | Node;
28
+ interface HtmlRenderer extends WebRenderer {
29
+ component: string | HTMLElement | ArgsStoryFn<HtmlRenderer>;
30
+ storyResult: StoryFnHtmlReturnType;
31
+ }
32
+ 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
@@ -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/html",
3
- "version": "7.0.0-alpha.7",
3
+ "version": "7.0.0-beta.0",
4
4
  "description": "Storybook HTML renderer",
5
5
  "keywords": [
6
6
  "storybook"
@@ -41,28 +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/docs-tools": "7.0.0-alpha.7",
56
- "@storybook/preview-web": "7.0.0-alpha.7",
57
- "@storybook/store": "7.0.0-alpha.7",
58
- "core-js": "^3.8.2",
54
+ "@storybook/core-client": "7.0.0-beta.0",
55
+ "@storybook/docs-tools": "7.0.0-beta.0",
56
+ "@storybook/preview-api": "7.0.0-beta.0",
57
+ "@storybook/types": "7.0.0-beta.0",
59
58
  "global": "^4.4.0",
60
- "react": "16.14.0",
61
- "react-dom": "16.14.0",
62
59
  "ts-dedent": "^2.0.0"
63
60
  },
64
61
  "devDependencies": {
65
- "@digitak/esrun": "^3.2.2"
62
+ "typescript": "~4.9.3"
66
63
  },
67
64
  "peerDependencies": {
68
65
  "@babel/core": "*"
@@ -73,9 +70,12 @@
73
70
  "publishConfig": {
74
71
  "access": "public"
75
72
  },
76
- "bundlerEntrypoint": [
77
- "./src/index.ts",
78
- "./src/config.ts"
79
- ],
80
- "gitHead": "d334cabd251cd0ed8b845a87707dc84f007d4074"
73
+ "bundler": {
74
+ "entries": [
75
+ "./src/index.ts",
76
+ "./src/config.ts"
77
+ ],
78
+ "platform": "browser"
79
+ },
80
+ "gitHead": "2e4ddde6a0a291266d91fe6a5ecda767bf119e70"
81
81
  }
@@ -0,0 +1,6 @@
1
+ {
2
+ "rules": {
3
+ "no-undef": "off",
4
+ "import/extensions": "off"
5
+ }
6
+ }
@@ -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,50 @@
1
+ import { createButton } from './Button';
2
+
3
+ // More on how to set up stories at: https://storybook.js.org/docs/7.0/html/writing-stories/introduction
4
+ export default {
5
+ title: 'Example/Button',
6
+ tags: ['docsPage'],
7
+ render: ({ label, ...args }) => {
8
+ // You can either use a function to create DOM elements or use a plain html string!
9
+ // return `<div>${label}</div>`;
10
+ return createButton({ label, ...args });
11
+ },
12
+ argTypes: {
13
+ backgroundColor: { control: 'color' },
14
+ label: { control: 'text' },
15
+ onClick: { action: 'onClick' },
16
+ primary: { control: 'boolean' },
17
+ size: {
18
+ control: { type: 'select' },
19
+ options: ['small', 'medium', 'large'],
20
+ },
21
+ },
22
+ };
23
+
24
+ // More on writing stories with args: https://storybook.js.org/docs/7.0/html/writing-stories/args
25
+ export const Primary = {
26
+ args: {
27
+ primary: true,
28
+ label: 'Button',
29
+ },
30
+ };
31
+
32
+ export const Secondary = {
33
+ args: {
34
+ label: 'Button',
35
+ },
36
+ };
37
+
38
+ export const Large = {
39
+ args: {
40
+ size: 'large',
41
+ label: 'Button',
42
+ },
43
+ };
44
+
45
+ export const Small = {
46
+ args: {
47
+ size: 'small',
48
+ label: 'Button',
49
+ },
50
+ };
@@ -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/7.0/html/writing-docs/docs-page
6
+ tags: ['docsPage'],
7
+ render: (args) => createHeader(args),
8
+ parameters: {
9
+ // More on how to position stories at: https://storybook.js.org/docs/7.0/html/configure/story-layout
10
+ layout: 'fullscreen',
11
+ },
12
+ // More on argTypes: https://storybook.js.org/docs/7.0/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 how to position stories at: https://storybook.js.org/docs/7.0/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/7.0/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,55 @@
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
+ tags: ['docsPage'],
9
+ render: (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(args);
13
+ },
14
+ argTypes: {
15
+ backgroundColor: { control: 'color' },
16
+ label: { control: 'text' },
17
+ onClick: { action: 'onClick' },
18
+ primary: { control: 'boolean' },
19
+ size: {
20
+ control: { type: 'select' },
21
+ options: ['small', 'medium', 'large'],
22
+ },
23
+ },
24
+ };
25
+
26
+ export default meta;
27
+ type Story = StoryObj<ButtonProps>;
28
+
29
+ // More on writing stories with args: https://storybook.js.org/docs/7.0/html/writing-stories/args
30
+ export const Primary: Story = {
31
+ args: {
32
+ primary: true,
33
+ label: 'Button',
34
+ },
35
+ };
36
+
37
+ export const Secondary: Story = {
38
+ args: {
39
+ label: 'Button',
40
+ },
41
+ };
42
+
43
+ export const Large: Story = {
44
+ args: {
45
+ size: 'large',
46
+ label: 'Button',
47
+ },
48
+ };
49
+
50
+ export const Small: Story = {
51
+ args: {
52
+ size: 'small',
53
+ label: 'Button',
54
+ },
55
+ };
@@ -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/7.0/html/writing-docs/docs-page
8
+ tags: ['docsPage'],
9
+ render: (args) => createHeader(args),
10
+ parameters: {
11
+ // More on how to position stories at: https://storybook.js.org/docs/7.0/html/configure/story-layout
12
+ layout: 'fullscreen',
13
+ },
14
+ // More on argTypes: https://storybook.js.org/docs/7.0/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 = {};
@@ -0,0 +1,54 @@
1
+ import './header.css';
2
+ import { createButton } from './Button';
3
+
4
+ export interface HeaderProps {
5
+ user?: { name: string };
6
+ onLogin: () => void;
7
+ onLogout: () => void;
8
+ onCreateAccount: () => void;
9
+ }
10
+
11
+ export const createHeader = ({ user, onLogout, onLogin, onCreateAccount }: HeaderProps) => {
12
+ const header = document.createElement('header');
13
+
14
+ const wrapper = document.createElement('div');
15
+ wrapper.className = 'wrapper';
16
+
17
+ const logo = `<div>
18
+ <svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
19
+ <g fill="none" fillRule="evenodd">
20
+ <path
21
+ d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
22
+ fill="#FFF" />
23
+ <path
24
+ d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
25
+ fill="#555AB9" />
26
+ <path d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z" fill="#91BAF8" />
27
+ </g>
28
+ </svg>
29
+ <h1>Acme</h1>
30
+ </div>`;
31
+
32
+ wrapper.insertAdjacentHTML('afterbegin', logo);
33
+
34
+ const account = document.createElement('div');
35
+ if (user) {
36
+ const welcomeMessage = `<span class="welcome">Welcome, <b>${user.name}</b>!</span>`;
37
+ account.innerHTML = welcomeMessage;
38
+ account.appendChild(createButton({ size: 'small', label: 'Log out', onClick: onLogout }));
39
+ } else {
40
+ account.appendChild(createButton({ size: 'small', label: 'Log in', onClick: onLogin }));
41
+ account.appendChild(
42
+ createButton({
43
+ size: 'small',
44
+ label: 'Sign up',
45
+ onClick: onCreateAccount,
46
+ primary: true,
47
+ })
48
+ );
49
+ }
50
+ wrapper.appendChild(account);
51
+ header.appendChild(wrapper);
52
+
53
+ return header;
54
+ };
@@ -0,0 +1,27 @@
1
+ import type { Meta, StoryObj } from '@storybook/html';
2
+ import { within, userEvent } from '@storybook/testing-library';
3
+ import { createPage } from './Page';
4
+
5
+ const meta: Meta = {
6
+ title: 'Example/Page',
7
+ render: () => createPage(),
8
+ parameters: {
9
+ // More on how to position stories at: https://storybook.js.org/docs/7.0/html/configure/story-layout
10
+ layout: 'fullscreen',
11
+ },
12
+ };
13
+
14
+ export default meta;
15
+
16
+ export const LoggedOut: StoryObj = {};
17
+
18
+ // More on interaction testing: https://storybook.js.org/docs/7.0/html/writing-tests/interaction-testing
19
+ export const LoggedIn: StoryObj = {
20
+ play: async ({ canvasElement }) => {
21
+ const canvas = within(canvasElement);
22
+ const loginButton = await canvas.getByRole('button', {
23
+ name: /Log in/i,
24
+ });
25
+ await userEvent.click(loginButton);
26
+ },
27
+ };
@@ -0,0 +1,98 @@
1
+ import './page.css';
2
+ import { createHeader } from './Header';
3
+
4
+ type User = {
5
+ name: string;
6
+ };
7
+
8
+ export const createPage = () => {
9
+ const article = document.createElement('article');
10
+ let user: User | undefined;
11
+ let header: HTMLElement | null = null;
12
+
13
+ const rerenderHeader = () => {
14
+ const wrapper = document.getElementsByTagName('article')[0];
15
+ wrapper.replaceChild(createHeaderElement(), wrapper.firstChild as HTMLElement);
16
+ };
17
+
18
+ const onLogin = () => {
19
+ user = { name: 'Jane Doe' };
20
+ rerenderHeader();
21
+ };
22
+
23
+ const onLogout = () => {
24
+ user = undefined;
25
+ rerenderHeader();
26
+ };
27
+
28
+ const onCreateAccount = () => {
29
+ user = { name: 'Jane Doe' };
30
+ rerenderHeader();
31
+ };
32
+
33
+ const createHeaderElement = () => {
34
+ return createHeader({ onLogin, onLogout, onCreateAccount, user });
35
+ };
36
+
37
+ header = createHeaderElement();
38
+ article.appendChild(header);
39
+
40
+ const section = `
41
+ <section>
42
+ <h2>Pages in Storybook</h2>
43
+ <p>
44
+ We recommend building UIs with a
45
+ <a
46
+ href="https://blog.hichroma.com/component-driven-development-ce1109d56c8e"
47
+ target="_blank"
48
+ rel="noopener noreferrer">
49
+ <strong>component-driven</strong>
50
+ </a>
51
+ process starting with atomic components and ending with pages.
52
+ </p>
53
+ <p>
54
+ Render pages with mock data. This makes it easy to build and review page states without
55
+ needing to navigate to them in your app. Here are some handy patterns for managing page data
56
+ in Storybook:
57
+ </p>
58
+ <ul>
59
+ <li>
60
+ Use a higher-level connected component. Storybook helps you compose such data from the
61
+ "args" of child component stories
62
+ </li>
63
+ <li>
64
+ Assemble data in the page component from your services. You can mock these services out
65
+ using Storybook.
66
+ </li>
67
+ </ul>
68
+ <p>
69
+ Get a guided tutorial on component-driven development at
70
+ <a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
71
+ Storybook tutorials
72
+ </a>
73
+ . Read more in the
74
+ <a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">docs</a>
75
+ .
76
+ </p>
77
+ <div class="tip-wrapper">
78
+ <span class="tip">Tip</span>
79
+ Adjust the width of the canvas with the
80
+ <svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
81
+ <g fill="none" fillRule="evenodd">
82
+ <path
83
+ d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0
84
+ 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
85
+ 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"
86
+ id="a"
87
+ fill="#999" />
88
+ </g>
89
+ </svg>
90
+ Viewports addon in the toolbar
91
+ </div>
92
+ </section>
93
+ `;
94
+
95
+ article.insertAdjacentHTML('beforeend', section);
96
+
97
+ return article;
98
+ };
@@ -0,0 +1,9 @@
1
+ /* eslint-disable no-undef */
2
+ export const Button = (args) => {
3
+ const button = document.createElement('button');
4
+
5
+ button.innerHTML = args.label;
6
+ button.addEventListener('click', args.onClick);
7
+
8
+ return button;
9
+ };
@@ -0,0 +1,32 @@
1
+ /* eslint-disable no-undef */
2
+ export const Form = ({ onSuccess }) => {
3
+ const container = document.createElement('div');
4
+
5
+ const getInnerHTML = ({ complete }) => `
6
+ <form id="interaction-test-form">
7
+ <label>
8
+ Enter Value
9
+ <input type="text" data-testid="value" required />
10
+ </label>
11
+ <button type="submit">Submit</button>
12
+ ${complete ? '<p>Completed!!</p>' : ''}
13
+ </form>
14
+ `;
15
+
16
+ container.innerHTML = getInnerHTML({ complete: false });
17
+
18
+ const form = container.querySelector('form');
19
+ form.addEventListener('submit', (e) => {
20
+ e.preventDefault();
21
+
22
+ setTimeout(() => {
23
+ container.innerHTML = getInnerHTML({ complete: true });
24
+ }, 500);
25
+ setTimeout(() => {
26
+ container.innerHTML = getInnerHTML({ complete: false });
27
+ }, 1500);
28
+ onSuccess(e);
29
+ });
30
+
31
+ return container;
32
+ };
@@ -0,0 +1 @@
1
+ export const Html = `<div>{{content}}</div>`;
@@ -0,0 +1,15 @@
1
+ /* eslint-disable no-undef */
2
+ export const Pre = (args) => {
3
+ const pre = document.createElement('pre');
4
+
5
+ pre.setAttribute('data-testid', 'pre');
6
+ pre.style = args.style;
7
+
8
+ if (args.object) {
9
+ pre.textContent = JSON.stringify(args.object, null, 2);
10
+ } else {
11
+ pre.textContent = args.text;
12
+ }
13
+
14
+ return pre;
15
+ };
@@ -0,0 +1,9 @@
1
+ import globalThis from 'global';
2
+
3
+ import { Button } from './Button';
4
+ import { Pre } from './Pre';
5
+ import { Form } from './Form';
6
+ import { Html } from './Html';
7
+
8
+ globalThis.Components = { Button, Pre, Form, Html };
9
+ globalThis.storybookRenderer = 'html';
@@ -0,0 +1 @@
1
+ Placeholder until we write some render-specific stories
@@ -0,0 +1,21 @@
1
+ import { Meta, Story, Canvas } from '@storybook/addon-docs';
2
+
3
+ <Meta title="html/html-mdx" />
4
+
5
+ ## HTML-specific MDX Stories
6
+
7
+ <Canvas>
8
+ <Story name="Basic" height="100px">
9
+ {'<h1>Hello World</h1>'}
10
+ </Story>
11
+ </Canvas>
12
+
13
+ <Canvas>
14
+ <Story name="Function" height="100px">
15
+ {() => {
16
+ const btn = document.createElement('button');
17
+ btn.innerHTML = 'Hello Button';
18
+ return btn;
19
+ }}
20
+ </Story>
21
+ </Canvas>
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 f=Object.defineProperty;var n=Object.getOwnPropertySymbols;var l=Object.prototype.hasOwnProperty,u=Object.prototype.propertyIsEnumerable;var s=(o,e,t)=>e in o?f(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,T=(o,e)=>{for(var t in e||(e={}))l.call(e,t)&&s(o,t,e[t]);if(n)for(var t of n(e))u.call(e,t)&&s(o,t,e[t]);return o};var p=(o,e)=>f(o,"name",{value:e,configurable:!0});import M from"global";import c from"ts-dedent";import{simulatePageLoad as g,simulateDOMContentLoaded as y}from"@storybook/preview-web";var{Node:L}=M;function $({storyFn:o,kind:e,name:t,showMain:d,showError:a,forceRemount:h},r){let i=o();if(d(),typeof i=="string")r.innerHTML=i,g(r);else if(i instanceof L){if(r.firstChild===i&&h===!1)return;r.innerHTML="",r.appendChild(i),y()}else a({title:`Expecting an HTML snippet or DOM node from the story: "${t}" of "${e}".`,description:c`
2
- Did you forget to return the HTML snippet from the story?
3
- Use "() => <your snippet or node>" or when defining the story.
4
- `})}p($,"renderToDOM");export{T as a,p as b,$ as c};
@@ -1,42 +0,0 @@
1
- import { PartialStoryFn, StoryContext as StoryContext$1 } from '@storybook/csf';
2
- import * as lib_docs_tools_dist_types from 'lib/docs-tools/dist/types';
3
- import { RenderContext } from '@storybook/store';
4
-
5
- declare function sourceDecorator(storyFn: PartialStoryFn<HtmlFramework>, context: StoryContext): StoryFnHtmlReturnType;
6
-
7
- declare const decorators: (typeof sourceDecorator)[];
8
-
9
- declare function renderToDOM({ storyFn, kind, name, showMain, showError, forceRemount }: RenderContext<HtmlFramework>, domElement: Element): void;
10
-
11
- declare const parameters: {
12
- docs: {
13
- inlineStories: boolean;
14
- transformSource: unknown;
15
- source: {
16
- type: lib_docs_tools_dist_types.SourceType;
17
- language: string;
18
- code: unknown;
19
- excludeDecorators: unknown;
20
- };
21
- };
22
- framework: "html";
23
- };
24
-
25
- declare type StoryFnHtmlReturnType = string | Node;
26
- interface IStorybookStory {
27
- name: string;
28
- render: (context: any) => any;
29
- }
30
- interface IStorybookSection {
31
- kind: string;
32
- stories: IStorybookStory[];
33
- }
34
- declare type HtmlFramework = {
35
- component: HTMLElement;
36
- storyResult: StoryFnHtmlReturnType;
37
- };
38
- declare type StoryContext = StoryContext$1<HtmlFramework> & {
39
- parameters: StoryContext$1<HtmlFramework>['parameters'] & typeof parameters;
40
- };
41
-
42
- export { HtmlFramework as H, IStorybookSection as I, decorators as d, parameters as p, renderToDOM as r };