@storybook/html 0.0.0-pr-23609-sha-f47ef339
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/README.md +1 -0
- package/dist/chunk-JHBKUHDQ.mjs +13 -0
- package/dist/config.d.ts +13 -0
- package/dist/config.js +7 -0
- package/dist/config.mjs +7 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +7 -0
- package/dist/index.mjs +7 -0
- package/dist/types-a021d1c4.d.ts +24 -0
- package/jest.config.js +7 -0
- package/package.json +78 -0
- package/preview.js +1 -0
- package/src/typings.d.ts +1 -0
- 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-3-8/Button.stories.ts +55 -0
- package/template/cli/ts-3-8/Button.ts +51 -0
- package/template/cli/ts-3-8/Header.stories.ts +33 -0
- package/template/cli/ts-3-8/Header.ts +54 -0
- package/template/cli/ts-3-8/Page.stories.ts +27 -0
- package/template/cli/ts-3-8/Page.ts +98 -0
- package/template/cli/ts-4-9/Button.stories.ts +55 -0
- package/template/cli/ts-4-9/Button.ts +51 -0
- package/template/cli/ts-4-9/Header.stories.ts +33 -0
- package/template/cli/ts-4-9/Header.ts +54 -0
- package/template/cli/ts-4-9/Page.stories.ts +27 -0
- package/template/cli/ts-4-9/Page.ts +98 -0
- package/template/components/Button.js +9 -0
- package/template/components/Form.js +34 -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/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Storybook HTML Renderer
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { global } from '@storybook/global';
|
|
2
|
+
import { dedent } from 'ts-dedent';
|
|
3
|
+
import { simulatePageLoad, simulateDOMContentLoaded } from '@storybook/preview-api';
|
|
4
|
+
|
|
5
|
+
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`
|
|
6
|
+
Storybook's HTML renderer only supports rendering DOM elements and strings.
|
|
7
|
+
Received: ${Component}
|
|
8
|
+
`),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`
|
|
9
|
+
Did you forget to return the HTML snippet from the story?
|
|
10
|
+
Use "() => <your snippet or node>" or when defining the story.
|
|
11
|
+
`});}
|
|
12
|
+
|
|
13
|
+
export { render, renderToCanvas };
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { S as StoryFnHtmlReturnType, H as HtmlRenderer, P as Parameters } from './types-a021d1c4.js';
|
|
2
|
+
import { Addon_DecoratorFunction, ArgTypesEnhancer, ArgsStoryFn, RenderContext } from '@storybook/types';
|
|
3
|
+
import '@storybook/docs-tools';
|
|
4
|
+
|
|
5
|
+
declare const decorators: Addon_DecoratorFunction<StoryFnHtmlReturnType>[];
|
|
6
|
+
declare const argTypesEnhancers: ArgTypesEnhancer[];
|
|
7
|
+
|
|
8
|
+
declare const render: ArgsStoryFn<HtmlRenderer>;
|
|
9
|
+
declare function renderToCanvas({ storyFn, kind, name, showMain, showError, forceRemount }: RenderContext<HtmlRenderer>, canvasElement: HtmlRenderer['canvasElement']): void;
|
|
10
|
+
|
|
11
|
+
declare const parameters: Parameters;
|
|
12
|
+
|
|
13
|
+
export { argTypesEnhancers, decorators, parameters, render, renderToCanvas };
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var config_exports={};__export(config_exports,{argTypesEnhancers:()=>argTypesEnhancers,decorators:()=>decorators,parameters:()=>parameters2,render:()=>render,renderToCanvas:()=>renderToCanvas});module.exports=__toCommonJS(config_exports);var import_docs_tools2=require("@storybook/docs-tools");var import_docs_tools=require("@storybook/docs-tools"),import_preview_api=require("@storybook/preview-api");function skipSourceRender(context){var _a;let sourceParams=(_a=context==null?void 0:context.parameters.docs)==null?void 0:_a.source,isArgsStory=context==null?void 0:context.parameters.__isArgsStory;return(sourceParams==null?void 0:sourceParams.type)===import_docs_tools.SourceType.DYNAMIC?!1:!isArgsStory||(sourceParams==null?void 0:sourceParams.code)||(sourceParams==null?void 0:sourceParams.type)===import_docs_tools.SourceType.CODE}function sourceDecorator(storyFn,context){var _a,_b;let story=storyFn(),renderedForSource=(_b=(_a=context==null?void 0:context.parameters.docs)==null?void 0:_a.source)!=null&&_b.excludeDecorators?context.originalStoryFn(context.args,context):story,source;return skipSourceRender(context)||(typeof renderedForSource=="string"?source=renderedForSource:renderedForSource instanceof Element&&(source=renderedForSource.outerHTML)),(0,import_preview_api.useEffect)(()=>{let{id,unmappedArgs}=context;source&&import_preview_api.addons.getChannel().emit(import_docs_tools.SNIPPET_RENDERED,{id,args:unmappedArgs,source})}),story}var decorators=[sourceDecorator],parameters={docs:{story:{inline:!0},source:{type:import_docs_tools2.SourceType.DYNAMIC,language:"html",code:void 0,excludeDecorators:void 0}}},argTypesEnhancers=[import_docs_tools2.enhanceArgTypes];var import_global=require("@storybook/global"),import_ts_dedent=require("ts-dedent"),import_preview_api2=require("@storybook/preview-api"),{Node}=import_global.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(import_ts_dedent.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,(0,import_preview_api2.simulatePageLoad)(canvasElement);else if(element instanceof Node){if(canvasElement.firstChild===element&&forceRemount===!1)return;canvasElement.innerHTML="",canvasElement.appendChild(element),(0,import_preview_api2.simulateDOMContentLoaded)()}else showError({title:`Expecting an HTML snippet or DOM node from the story: "${name}" of "${kind}".`,description:import_ts_dedent.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 parameters2={renderer:"html",...parameters};0&&(module.exports={argTypesEnhancers,decorators,parameters,render,renderToCanvas});
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { render, renderToCanvas } from './chunk-JHBKUHDQ.mjs';
|
|
2
|
+
import { SourceType, enhanceArgTypes, SNIPPET_RENDERED } from '@storybook/docs-tools';
|
|
3
|
+
import { useEffect, addons } from '@storybook/preview-api';
|
|
4
|
+
|
|
5
|
+
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 sourceDecorator(storyFn,context){let story=storyFn(),renderedForSource=context?.parameters.docs?.source?.excludeDecorators?context.originalStoryFn(context.args,context):story,source;return skipSourceRender(context)||(typeof renderedForSource=="string"?source=renderedForSource:renderedForSource instanceof Element&&(source=renderedForSource.outerHTML)),useEffect(()=>{let{id,unmappedArgs}=context;source&&addons.getChannel().emit(SNIPPET_RENDERED,{id,args:unmappedArgs,source});}),story}var decorators=[sourceDecorator],parameters={docs:{story:{inline:!0},source:{type:SourceType.DYNAMIC,language:"html",code:void 0,excludeDecorators:void 0}}},argTypesEnhancers=[enhanceArgTypes];var parameters2={renderer:"html",...parameters};
|
|
6
|
+
|
|
7
|
+
export { argTypesEnhancers, decorators, parameters2 as parameters };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Addon_ClientStoryApi, Addon_Loadable, Args, ComponentAnnotations, AnnotatedStoryFn, StoryAnnotations, StrictArgs, DecoratorFunction, LoaderFunction, StoryContext as StoryContext$1, ProjectAnnotations } from '@storybook/types';
|
|
2
|
+
export { ArgTypes, Args, Parameters, StrictArgs } from '@storybook/types';
|
|
3
|
+
import { H as HtmlRenderer } from './types-a021d1c4.js';
|
|
4
|
+
import '@storybook/docs-tools';
|
|
5
|
+
|
|
6
|
+
interface ClientApi extends Addon_ClientStoryApi<HtmlRenderer['storyResult']> {
|
|
7
|
+
configure(loader: Addon_Loadable, module: NodeModule): void;
|
|
8
|
+
forceReRender(): void;
|
|
9
|
+
raw: () => any;
|
|
10
|
+
}
|
|
11
|
+
declare const storiesOf: ClientApi['storiesOf'];
|
|
12
|
+
declare const configure: ClientApi['configure'];
|
|
13
|
+
declare const forceReRender: ClientApi['forceReRender'];
|
|
14
|
+
declare const raw: ClientApi['raw'];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Metadata to configure the stories for a component.
|
|
18
|
+
*
|
|
19
|
+
* @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
|
|
20
|
+
*/
|
|
21
|
+
type Meta<TArgs = Args> = ComponentAnnotations<HtmlRenderer, TArgs>;
|
|
22
|
+
/**
|
|
23
|
+
* Story function that represents a CSFv2 component example.
|
|
24
|
+
*
|
|
25
|
+
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
|
26
|
+
*/
|
|
27
|
+
type StoryFn<TArgs = Args> = AnnotatedStoryFn<HtmlRenderer, TArgs>;
|
|
28
|
+
/**
|
|
29
|
+
* Story function that represents a CSFv3 component example.
|
|
30
|
+
*
|
|
31
|
+
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
|
32
|
+
*/
|
|
33
|
+
type StoryObj<TArgs = Args> = StoryAnnotations<HtmlRenderer, TArgs>;
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Use `StoryFn` instead.
|
|
36
|
+
* Use `StoryObj` if you want to migrate to CSF3, which uses objects instead of functions to represent stories.
|
|
37
|
+
* You can read more about the CSF3 format here: https://storybook.js.org/blog/component-story-format-3-0/
|
|
38
|
+
*
|
|
39
|
+
* Story function that represents a CSFv2 component example.
|
|
40
|
+
*
|
|
41
|
+
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
|
42
|
+
*/
|
|
43
|
+
type Story<TArgs = Args> = StoryFn<TArgs>;
|
|
44
|
+
type Decorator<TArgs = StrictArgs> = DecoratorFunction<HtmlRenderer, TArgs>;
|
|
45
|
+
type Loader<TArgs = StrictArgs> = LoaderFunction<HtmlRenderer, TArgs>;
|
|
46
|
+
type StoryContext<TArgs = StrictArgs> = StoryContext$1<HtmlRenderer, TArgs>;
|
|
47
|
+
type Preview = ProjectAnnotations<HtmlRenderer>;
|
|
48
|
+
|
|
49
|
+
export { Decorator, HtmlRenderer, Loader, Meta, Preview, Story, StoryContext, StoryFn, StoryObj, configure, forceReRender, raw, storiesOf };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var src_exports={};__export(src_exports,{configure:()=>configure,forceReRender:()=>forceReRender,raw:()=>raw,storiesOf:()=>storiesOf});module.exports=__toCommonJS(src_exports);var import_global=require("@storybook/global"),{window:globalWindow}=import_global.global;globalWindow.STORYBOOK_ENV="HTML";var import_preview_api2=require("@storybook/preview-api");var import_global2=require("@storybook/global"),import_ts_dedent=require("ts-dedent"),import_preview_api=require("@storybook/preview-api"),{Node}=import_global2.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(import_ts_dedent.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,(0,import_preview_api.simulatePageLoad)(canvasElement);else if(element instanceof Node){if(canvasElement.firstChild===element&&forceRemount===!1)return;canvasElement.innerHTML="",canvasElement.appendChild(element),(0,import_preview_api.simulateDOMContentLoaded)()}else showError({title:`Expecting an HTML snippet or DOM node from the story: "${name}" of "${kind}".`,description:import_ts_dedent.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 RENDERER="html",api=(0,import_preview_api2.start)(renderToCanvas,{render}),storiesOf=(kind,m)=>api.clientApi.storiesOf(kind,m).addParameters({renderer:RENDERER}),configure=(...args)=>api.configure(RENDERER,...args),forceReRender=api.forceReRender,raw=api.clientApi.raw;var _a;typeof module<"u"&&((_a=module==null?void 0:module.hot)==null||_a.decline());0&&(module.exports={configure,forceReRender,raw,storiesOf});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { renderToCanvas, render } from './chunk-JHBKUHDQ.mjs';
|
|
2
|
+
import { global } from '@storybook/global';
|
|
3
|
+
import { start } from '@storybook/preview-api';
|
|
4
|
+
|
|
5
|
+
var{window:globalWindow}=global;globalWindow.STORYBOOK_ENV="HTML";var RENDERER="html",api=start(renderToCanvas,{render}),storiesOf=(kind,m)=>api.clientApi.storiesOf(kind,m).addParameters({renderer:RENDERER}),configure=(...args)=>api.configure(RENDERER,...args),forceReRender=api.forceReRender,raw=api.clientApi.raw;typeof module<"u"&&module?.hot?.decline();
|
|
6
|
+
|
|
7
|
+
export { configure, forceReRender, raw, storiesOf };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WebRenderer, ArgsStoryFn } from '@storybook/types';
|
|
2
|
+
import { SourceType } from '@storybook/docs-tools';
|
|
3
|
+
|
|
4
|
+
type StoryFnHtmlReturnType = string | Node;
|
|
5
|
+
interface HtmlRenderer extends WebRenderer {
|
|
6
|
+
component: string | HTMLElement | ArgsStoryFn<HtmlRenderer>;
|
|
7
|
+
storyResult: StoryFnHtmlReturnType;
|
|
8
|
+
}
|
|
9
|
+
interface Parameters {
|
|
10
|
+
renderer: 'html';
|
|
11
|
+
docs?: {
|
|
12
|
+
story: {
|
|
13
|
+
inline: boolean;
|
|
14
|
+
};
|
|
15
|
+
source: {
|
|
16
|
+
type: SourceType.DYNAMIC;
|
|
17
|
+
language: 'html';
|
|
18
|
+
code: any;
|
|
19
|
+
excludeDecorators: any;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { HtmlRenderer as H, Parameters as P, StoryFnHtmlReturnType as S };
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@storybook/html",
|
|
3
|
+
"version": "0.0.0-pr-23609-sha-f47ef339",
|
|
4
|
+
"description": "Storybook HTML renderer",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"storybook"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/storybookjs/storybook/tree/next/code/renderers/html",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/storybookjs/storybook/issues"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/storybookjs/storybook.git",
|
|
15
|
+
"directory": "code/renderers/html"
|
|
16
|
+
},
|
|
17
|
+
"funding": {
|
|
18
|
+
"type": "opencollective",
|
|
19
|
+
"url": "https://opencollective.com/storybook"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"node": "./dist/index.js",
|
|
26
|
+
"require": "./dist/index.js",
|
|
27
|
+
"import": "./dist/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"./preview": {
|
|
30
|
+
"types": "./dist/config.d.ts",
|
|
31
|
+
"require": "./dist/config.js",
|
|
32
|
+
"import": "./dist/config.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"main": "dist/index.js",
|
|
37
|
+
"module": "dist/index.mjs",
|
|
38
|
+
"types": "dist/index.d.ts",
|
|
39
|
+
"files": [
|
|
40
|
+
"dist/**/*",
|
|
41
|
+
"template/**/*",
|
|
42
|
+
"README.md",
|
|
43
|
+
"*.js",
|
|
44
|
+
"*.d.ts"
|
|
45
|
+
],
|
|
46
|
+
"scripts": {
|
|
47
|
+
"check": "../../../scripts/prepare/check.ts",
|
|
48
|
+
"prep": "../../../scripts/prepare/bundle.ts"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@storybook/core-client": "0.0.0-pr-23609-sha-f47ef339",
|
|
52
|
+
"@storybook/docs-tools": "0.0.0-pr-23609-sha-f47ef339",
|
|
53
|
+
"@storybook/global": "^5.0.0",
|
|
54
|
+
"@storybook/preview-api": "0.0.0-pr-23609-sha-f47ef339",
|
|
55
|
+
"@storybook/types": "0.0.0-pr-23609-sha-f47ef339",
|
|
56
|
+
"ts-dedent": "^2.0.0"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"typescript": "~4.9.3"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@babel/core": "*"
|
|
63
|
+
},
|
|
64
|
+
"engines": {
|
|
65
|
+
"node": ">=16.0.0"
|
|
66
|
+
},
|
|
67
|
+
"publishConfig": {
|
|
68
|
+
"access": "public"
|
|
69
|
+
},
|
|
70
|
+
"bundler": {
|
|
71
|
+
"entries": [
|
|
72
|
+
"./src/index.ts",
|
|
73
|
+
"./src/config.ts"
|
|
74
|
+
],
|
|
75
|
+
"platform": "browser"
|
|
76
|
+
},
|
|
77
|
+
"gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae17"
|
|
78
|
+
}
|
package/preview.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/config';
|
package/src/typings.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare var STORYBOOK_ENV: 'HTML';
|
|
@@ -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/html/writing-stories/introduction
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Example/Button',
|
|
6
|
+
tags: ['autodocs'],
|
|
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/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 = 'storybook-header';
|
|
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 Autodocs entry: https://storybook.js.org/docs/html/writing-docs/autodocs
|
|
6
|
+
tags: ['autodocs'],
|
|
7
|
+
render: (args) => createHeader(args),
|
|
8
|
+
parameters: {
|
|
9
|
+
// More on how to position stories at: 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 class="storybook-page">
|
|
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/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,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: ['autodocs'],
|
|
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/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 Autodocs entry: https://storybook.js.org/docs/html/writing-docs/autodocs
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
render: (args) => createHeader(args),
|
|
10
|
+
parameters: {
|
|
11
|
+
// More on how to position stories at: 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: 'Jane 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 = 'storybook-header';
|
|
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/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/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 class="storybook-page">
|
|
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,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 = {
|
|
7
|
+
title: 'Example/Button',
|
|
8
|
+
tags: ['autodocs'],
|
|
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
|
+
} satisfies Meta<ButtonProps>;
|
|
25
|
+
|
|
26
|
+
export default meta;
|
|
27
|
+
type Story = StoryObj<ButtonProps>;
|
|
28
|
+
|
|
29
|
+
// More on writing stories with args: https://storybook.js.org/docs/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 = {
|
|
6
|
+
title: 'Example/Header',
|
|
7
|
+
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/html/writing-docs/autodocs
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
render: (args) => createHeader(args),
|
|
10
|
+
parameters: {
|
|
11
|
+
// More on how to position stories at: 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
|
+
} satisfies Meta<HeaderProps>;
|
|
21
|
+
|
|
22
|
+
export default meta;
|
|
23
|
+
type Story = StoryObj<HeaderProps>;
|
|
24
|
+
|
|
25
|
+
export const LoggedIn: Story = {
|
|
26
|
+
args: {
|
|
27
|
+
user: {
|
|
28
|
+
name: 'Jane 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 = 'storybook-header';
|
|
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 = {
|
|
6
|
+
title: 'Example/Page',
|
|
7
|
+
render: () => createPage(),
|
|
8
|
+
parameters: {
|
|
9
|
+
// More on how to position stories at: https://storybook.js.org/docs/html/configure/story-layout
|
|
10
|
+
layout: 'fullscreen',
|
|
11
|
+
},
|
|
12
|
+
} satisfies Meta;
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
|
|
16
|
+
export const LoggedOut: StoryObj = {};
|
|
17
|
+
|
|
18
|
+
// More on interaction testing: https://storybook.js.org/docs/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 class="storybook-page">
|
|
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,34 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
export const Form = ({ onSuccess }) => {
|
|
3
|
+
const container = document.createElement('div');
|
|
4
|
+
|
|
5
|
+
const getInnerHTML = ({ complete, value }) => `
|
|
6
|
+
<form id="interaction-test-form">
|
|
7
|
+
<label>
|
|
8
|
+
Enter Value
|
|
9
|
+
<input type="text" data-testid="value" value="${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, value: '' });
|
|
17
|
+
|
|
18
|
+
const form = container.querySelector('form');
|
|
19
|
+
form.addEventListener('submit', (e) => {
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
|
|
22
|
+
const { value } = form.querySelector('input'); // Store the current value
|
|
23
|
+
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
container.innerHTML = getInnerHTML({ complete: true, value });
|
|
26
|
+
}, 500);
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
container.innerHTML = getInnerHTML({ complete: false, value });
|
|
29
|
+
}, 1500);
|
|
30
|
+
onSuccess(value);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return container;
|
|
34
|
+
};
|
|
@@ -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 { global as globalThis } from '@storybook/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>
|