@storybook/html 7.0.0-alpha.6 → 7.0.0-alpha.61
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-ZJLPYI6H.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-fb08647b.d.ts +36 -0
- package/jest.config.js +7 -0
- package/package.json +39 -15
- 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 +50 -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 +55 -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 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
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 _={};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`
|
|
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 I={framework:"html",...T};0&&(module.exports={argTypesEnhancers,decorators,parameters,render,renderToCanvas});
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
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-fb08647b.js';
|
|
4
|
+
export { H as HtmlRenderer } from './types-fb08647b.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
|
+
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
|
+
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
|
+
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
|
+
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>;
|
|
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:()=>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`
|
|
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=(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
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
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.61",
|
|
4
4
|
"description": "Storybook HTML renderer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook"
|
|
@@ -19,31 +19,48 @@
|
|
|
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/
|
|
36
|
-
"@storybook/
|
|
37
|
-
"@storybook/
|
|
38
|
-
"@storybook/
|
|
39
|
-
"@storybook/preview-web": "7.0.0-alpha.6",
|
|
40
|
-
"@storybook/store": "7.0.0-alpha.6",
|
|
41
|
-
"core-js": "^3.8.2",
|
|
54
|
+
"@storybook/core-client": "7.0.0-alpha.61",
|
|
55
|
+
"@storybook/docs-tools": "7.0.0-alpha.61",
|
|
56
|
+
"@storybook/preview-api": "7.0.0-alpha.61",
|
|
57
|
+
"@storybook/types": "7.0.0-alpha.61",
|
|
42
58
|
"global": "^4.4.0",
|
|
43
|
-
"react": "16.14.0",
|
|
44
|
-
"react-dom": "16.14.0",
|
|
45
59
|
"ts-dedent": "^2.0.0"
|
|
46
60
|
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"typescript": "~4.9.3"
|
|
63
|
+
},
|
|
47
64
|
"peerDependencies": {
|
|
48
65
|
"@babel/core": "*"
|
|
49
66
|
},
|
|
@@ -53,5 +70,12 @@
|
|
|
53
70
|
"publishConfig": {
|
|
54
71
|
"access": "public"
|
|
55
72
|
},
|
|
56
|
-
"
|
|
73
|
+
"bundler": {
|
|
74
|
+
"entries": [
|
|
75
|
+
"./src/index.ts",
|
|
76
|
+
"./src/config.ts"
|
|
77
|
+
],
|
|
78
|
+
"platform": "browser"
|
|
79
|
+
},
|
|
80
|
+
"gitHead": "ec1df6fe1b11ad6084b9f3ea4b5f6bee3fca58be"
|
|
57
81
|
}
|
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,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 = {};
|