@storybook/web-components 7.0.0-alpha.8 → 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.
- package/dist/chunk-UOPG23OB.mjs +5 -0
- package/dist/config.d.ts +11 -13
- package/dist/config.js +3 -3
- package/dist/config.mjs +1 -1
- package/dist/index.d.ts +19 -19
- package/dist/index.js +3 -3
- package/dist/index.mjs +1 -1
- package/dist/types-cbbc479a.d.ts +10 -0
- package/jest.config.js +7 -0
- package/package.json +21 -20
- package/template/cli/.eslintrc.json +5 -0
- package/template/cli/js/Button.js +21 -0
- package/template/cli/js/Button.stories.js +44 -0
- package/template/cli/js/Header.js +45 -0
- package/template/cli/js/Header.stories.js +18 -0
- package/template/cli/js/Page.js +61 -0
- package/template/cli/js/Page.stories.js +20 -0
- package/template/cli/ts/Button.stories.ts +49 -0
- package/template/cli/ts/Button.ts +43 -0
- package/template/cli/ts/Header.stories.ts +23 -0
- package/template/cli/ts/Header.ts +56 -0
- package/template/cli/ts/Page.stories.ts +26 -0
- package/template/cli/ts/Page.ts +72 -0
- package/template/components/Button.js +71 -0
- package/template/components/Form.js +81 -0
- package/template/components/Html.js +34 -0
- package/template/components/Pre.js +42 -0
- package/template/components/button.css +30 -0
- package/template/components/index.js +14 -0
- package/template/stories/custom-elements-experimental.json +95 -0
- package/template/stories/custom-elements.json +162 -0
- package/template/stories/demo-wc-card/DemoWcCard.js +101 -0
- package/template/stories/demo-wc-card/demoWcCardStyle.css.js +97 -0
- package/template/stories/demo-wc-card/index.js +5 -0
- package/template/stories/demo-wc-card.stories.js +16 -0
- package/template/stories/preview.js +6 -0
- package/LICENSE +0 -21
- package/dist/chunk-LW7MJT4D.mjs +0 -5
- package/dist/types-7ab3c005.d.ts +0 -17
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import global3 from"global";import global from"global";var{window:globalWindow}=global;globalWindow.STORYBOOK_ENV="web-components";import{start}from"@storybook/preview-api";import global2 from"global";import{dedent}from"ts-dedent";import{render as litRender}from"lit-html";import{isTemplateResult}from"lit-html/directive-helpers.js";import{simulatePageLoad,simulateDOMContentLoaded}from"@storybook/preview-api";var{Node}=global2,render=(args,context)=>{let{id,component}=context;if(!component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);let element=document.createElement(component);return Object.entries(args).forEach(([key,val])=>{element[key]=val}),element};function renderToCanvas({storyFn,kind,name,showMain,showError,forceRemount},canvasElement){let element=storyFn();if(showMain(),isTemplateResult(element)){(forceRemount||!canvasElement.querySelector('[id="root-inner"]'))&&(canvasElement.innerHTML='<div id="root-inner"></div>');let renderTo=canvasElement.querySelector('[id="root-inner"]');litRender(element,renderTo),simulatePageLoad(canvasElement)}else if(typeof element=="string")canvasElement.innerHTML=element,simulatePageLoad(canvasElement);else if(element instanceof Node){if(canvasElement.firstChild===element&&!forceRemount)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`
|
|
2
|
+
Did you forget to return the HTML snippet from the story?
|
|
3
|
+
Use "() => <your snippet or node>" or when defining the story.
|
|
4
|
+
`})}var FRAMEWORK="web-components",api=start(renderToCanvas),storiesOf=(kind,m)=>api.clientApi.storiesOf(kind,m).addParameters({framework:FRAMEWORK}),configure=(...args)=>api.configure(FRAMEWORK,...args),forceReRender=api.forceReRender,raw=api.clientApi.raw;function isValidComponent(tagName){if(!tagName)return!1;if(typeof tagName=="string")return!0;throw new Error('Provided component needs to be a string. e.g. component: "my-element"')}function isValidMetaData(customElements){if(!customElements)return!1;if(customElements.tags&&Array.isArray(customElements.tags)||customElements.modules&&Array.isArray(customElements.modules))return!0;throw new Error(`You need to setup valid meta data in your config.js via setCustomElements().
|
|
5
|
+
See the readme of addon-docs for web components for more details.`)}function setCustomElements(customElements){window.__STORYBOOK_CUSTOM_ELEMENTS__=customElements}function setCustomElementsManifest(customElements){window.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__=customElements}function getCustomElements(){return window.__STORYBOOK_CUSTOM_ELEMENTS__||window.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__}var{window:window2,EventSource}=global3;module&&module.hot&&module.hot.decline&&(module.hot.decline(),new EventSource("__webpack_hmr").addEventListener("message",function(event){try{let{action}=JSON.parse(event.data);action==="built"&&window2.location.reload()}catch{}}));export{render,renderToCanvas,storiesOf,configure,forceReRender,raw,isValidComponent,isValidMetaData,setCustomElements,setCustomElementsManifest,getCustomElements};
|
package/dist/config.d.ts
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import * as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { PartialStoryFn, StoryContext } from '@storybook/csf';
|
|
6
|
-
import { W as WebComponentsFramework } from './types-7ab3c005.js';
|
|
7
|
-
import { RenderContext } from '@storybook/store';
|
|
1
|
+
import * as lib_docs_tools_dist from 'lib/docs-tools/dist';
|
|
2
|
+
import * as lib_types_dist from 'lib/types/dist';
|
|
3
|
+
import { PartialStoryFn, StoryContext, ArgsStoryFn, RenderContext } from '@storybook/types';
|
|
4
|
+
import { W as WebComponentsRenderer } from './types-cbbc479a.js';
|
|
8
5
|
import 'lit-html';
|
|
9
6
|
|
|
10
|
-
declare function sourceDecorator(storyFn: PartialStoryFn<
|
|
7
|
+
declare function sourceDecorator(storyFn: PartialStoryFn<WebComponentsRenderer>, context: StoryContext<WebComponentsRenderer>): WebComponentsRenderer['storyResult'];
|
|
11
8
|
|
|
12
9
|
declare const decorators: (typeof sourceDecorator)[];
|
|
13
|
-
declare const argTypesEnhancers: (<
|
|
10
|
+
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>)[];
|
|
14
11
|
|
|
15
|
-
declare
|
|
12
|
+
declare const render: ArgsStoryFn<WebComponentsRenderer>;
|
|
13
|
+
declare function renderToCanvas({ storyFn, kind, name, showMain, showError, forceRemount }: RenderContext<WebComponentsRenderer>, canvasElement: WebComponentsRenderer['canvasElement']): void;
|
|
16
14
|
|
|
17
15
|
declare const parameters: {
|
|
18
16
|
docs: {
|
|
19
17
|
extractArgTypes: (tagName: string) => {
|
|
20
|
-
[x: string]:
|
|
18
|
+
[x: string]: lib_types_dist.InputType;
|
|
21
19
|
};
|
|
22
20
|
extractComponentDescription: (tagName: string) => string;
|
|
23
21
|
inlineStories: boolean;
|
|
24
22
|
source: {
|
|
25
|
-
type:
|
|
23
|
+
type: lib_docs_tools_dist.SourceType;
|
|
26
24
|
language: string;
|
|
27
25
|
};
|
|
28
26
|
};
|
|
29
27
|
framework: "web-components";
|
|
30
28
|
};
|
|
31
29
|
|
|
32
|
-
export { argTypesEnhancers, decorators, parameters,
|
|
30
|
+
export { argTypesEnhancers, decorators, parameters, render, renderToCanvas };
|
package/dist/config.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
1
|
+
var V=Object.create;var f=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var H=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var B=(e,r)=>{for(var t in r)f(e,t,{get:r[t],enumerable:!0})},b=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of $(r))!K.call(e,n)&&n!==t&&f(e,n,{get:()=>r[n],enumerable:!(o=Y(r,n))||o.enumerable});return e};var y=(e,r,t)=>(t=e!=null?V(H(e)):{},b(r||!e||!e.__esModule?f(t,"default",{value:e,enumerable:!0}):t,e)),j=e=>b(f({},"__esModule",{value:!0}),e);var se={};B(se,{argTypesEnhancers:()=>U,decorators:()=>N,parameters:()=>ne,render:()=>h,renderToCanvas:()=>u});module.exports=j(se);var l=require("@storybook/docs-tools");var S=require("@storybook/client-logger");var x=y(require("global"));var R=y(require("global")),{window:q}=R.default;q.STORYBOOK_ENV="web-components";var M=require("@storybook/preview-api");var w=y(require("global")),_=require("ts-dedent"),A=require("lit-html"),E=require("lit-html/directive-helpers.js"),d=require("@storybook/preview-api"),{Node:J}=w.default,h=(e,r)=>{let{id:t,component:o}=r;if(!o)throw new Error(`Unable to render story ${t} as the component annotation is missing from the default export`);let n=document.createElement(o);return Object.entries(e).forEach(([i,s])=>{n[i]=s}),n};function u({storyFn:e,kind:r,name:t,showMain:o,showError:n,forceRemount:i},s){let a=e();if(o(),(0,E.isTemplateResult)(a)){(i||!s.querySelector('[id="root-inner"]'))&&(s.innerHTML='<div id="root-inner"></div>');let P=s.querySelector('[id="root-inner"]');(0,A.render)(a,P),(0,d.simulatePageLoad)(s)}else if(typeof a=="string")s.innerHTML=a,(0,d.simulatePageLoad)(s);else if(a instanceof J){if(s.firstChild===a&&!i)return;s.innerHTML="",s.appendChild(a),(0,d.simulateDOMContentLoaded)()}else n({title:`Expecting an HTML snippet or DOM node from the story: "${t}" of "${r}".`,description:_.dedent`
|
|
2
2
|
Did you forget to return the HTML snippet from the story?
|
|
3
3
|
Use "() => <your snippet or node>" or when defining the story.
|
|
4
|
-
`})}
|
|
5
|
-
See the readme of addon-docs for web components for more details.`)}
|
|
4
|
+
`})}var O=(0,M.start)(u);var de=O.forceReRender,me=O.clientApi.raw;function g(e){if(!e)return!1;if(typeof e=="string")return!0;throw new Error('Provided component needs to be a string. e.g. component: "my-element"')}function C(e){if(!e)return!1;if(e.tags&&Array.isArray(e.tags)||e.modules&&Array.isArray(e.modules))return!0;throw new Error(`You need to setup valid meta data in your config.js via setCustomElements().
|
|
5
|
+
See the readme of addon-docs for web components for more details.`)}function T(){return window.__STORYBOOK_CUSTOM_ELEMENTS__||window.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__}var{window:X,EventSource:Z}=x.default;module&&module.hot&&module.hot.decline&&(module.hot.decline(),new Z("__webpack_hmr").addEventListener("message",function(t){try{let{action:o}=JSON.parse(t.data);o==="built"&&X.location.reload()}catch{}}));function D(e,r){var o,n;let t=r==="properties"?{name:((o=e.type)==null?void 0:o.text)||e.type}:{name:"void"};return{name:e.name,required:!1,description:e.description,type:t,table:{category:r,type:{summary:((n=e.type)==null?void 0:n.text)||e.type},defaultValue:{summary:e.default!==void 0?e.default:e.defaultValue}}}}function z(e){let r=e.name.replace(/(-|_|:|\.|\s)+(.)?/g,(t,o,n)=>n?n.toUpperCase():"").replace(/^([A-Z])/,t=>t.toLowerCase());return r=`on${r.charAt(0).toUpperCase()+r.substr(1)}`,[{name:r,action:{name:e.name},table:{disable:!0}},D(e,"events")]}function p(e,r){return e&&e.filter(t=>t&&t.name).reduce((t,o)=>{if(o.kind==="method")return t;switch(r){case"events":z(o).forEach(n=>{t[n.name]=n});break;default:t[o.name]=D(o,r);break}return t},{})}var G=(e,r)=>{if(!g(e)||!C(r))return null;let t=r.tags.find(o=>o.name.toUpperCase()===e.toUpperCase());return t||S.logger.warn(`Component not found in custom-elements.json: ${e}`),t},Q=(e,r)=>{var o;if(!g(e)||!C(r))return null;let t;return(o=r==null?void 0:r.modules)==null||o.forEach(n=>{var i;(i=n==null?void 0:n.declarations)==null||i.forEach(s=>{s.tagName===e&&(t=s)})}),t||S.logger.warn(`Component not found in custom-elements.json: ${e}`),t},I=(e,r)=>(r==null?void 0:r.version)==="experimental"?G(e,r):Q(e,r),ee=(e,r)=>{let t=I(e,r);return t&&{...p(t.attributes,"attributes"),...p(t.members,"properties"),...p(t.properties,"properties"),...p(t.events,"events"),...p(t.slots,"slots"),...p(t.cssProperties,"css custom properties"),...p(t.cssParts,"css shadow parts")}},L=e=>{let r=T();return ee(e,r)},W=e=>{let r=I(e,T());return r&&r.description};var v=require("lit-html"),c=require("@storybook/preview-api"),m=require("@storybook/docs-tools"),re=/<!--\?lit\$[0-9]+\$-->|<!--\??-->/g;function te(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)===m.SourceType.DYNAMIC?!1:!t||(r==null?void 0:r.code)||(r==null?void 0:r.type)===m.SourceType.CODE}function oe(e,r){let{transformSource:t}=r.parameters.docs??{};return typeof t!="function"?e:t(e,r)}function k(e,r){var n,i;let t=(i=(n=r==null?void 0:r.parameters.docs)==null?void 0:n.source)!=null&&i.excludeDecorators?r.originalStoryFn(r.args,r):e(),o;if((0,c.useEffect)(()=>{o&&c.addons.getChannel().emit(m.SNIPPET_RENDERED,r.id,o)}),!te(r)){let s=window.document.createElement("div");(0,v.render)(t,s),o=oe(s.innerHTML.replace(re,""),r)}return t}var N=[k],F={docs:{extractArgTypes:L,extractComponentDescription:W,inlineStories:!0,source:{type:l.SourceType.DYNAMIC,language:"html"}}},U=[l.enhanceArgTypes];var ne={framework:"web-components",...F};0&&(module.exports={argTypesEnhancers,decorators,parameters,render,renderToCanvas});
|
package/dist/config.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{getCustomElements,isValidComponent,isValidMetaData,render,renderToCanvas}from"./chunk-UOPG23OB.mjs";import{SourceType as SourceType2,enhanceArgTypes}from"@storybook/docs-tools";import{logger}from"@storybook/client-logger";function mapItem(item,category){let type=category==="properties"?{name:item.type?.text||item.type}:{name:"void"};return{name:item.name,required:!1,description:item.description,type,table:{category,type:{summary:item.type?.text||item.type},defaultValue:{summary:item.default!==void 0?item.default:item.defaultValue}}}}function mapEvent(item){let name=item.name.replace(/(-|_|:|\.|\s)+(.)?/g,(_match,_separator,chr)=>chr?chr.toUpperCase():"").replace(/^([A-Z])/,match=>match.toLowerCase());return name=`on${name.charAt(0).toUpperCase()+name.substr(1)}`,[{name,action:{name:item.name},table:{disable:!0}},mapItem(item,"events")]}function mapData(data,category){return data&&data.filter(item=>item&&item.name).reduce((acc,item)=>{if(item.kind==="method")return acc;switch(category){case"events":mapEvent(item).forEach(argType=>{acc[argType.name]=argType});break;default:acc[item.name]=mapItem(item,category);break}return acc},{})}var getMetaDataExperimental=(tagName,customElements)=>{if(!isValidComponent(tagName)||!isValidMetaData(customElements))return null;let metaData=customElements.tags.find(tag=>tag.name.toUpperCase()===tagName.toUpperCase());return metaData||logger.warn(`Component not found in custom-elements.json: ${tagName}`),metaData},getMetaDataV1=(tagName,customElements)=>{if(!isValidComponent(tagName)||!isValidMetaData(customElements))return null;let metadata;return customElements?.modules?.forEach(_module=>{_module?.declarations?.forEach(declaration=>{declaration.tagName===tagName&&(metadata=declaration)})}),metadata||logger.warn(`Component not found in custom-elements.json: ${tagName}`),metadata},getMetaData=(tagName,manifest)=>manifest?.version==="experimental"?getMetaDataExperimental(tagName,manifest):getMetaDataV1(tagName,manifest),extractArgTypesFromElements=(tagName,customElements)=>{let metaData=getMetaData(tagName,customElements);return metaData&&{...mapData(metaData.attributes,"attributes"),...mapData(metaData.members,"properties"),...mapData(metaData.properties,"properties"),...mapData(metaData.events,"events"),...mapData(metaData.slots,"slots"),...mapData(metaData.cssProperties,"css custom properties"),...mapData(metaData.cssParts,"css shadow parts")}},extractArgTypes=tagName=>{let cem=getCustomElements();return extractArgTypesFromElements(tagName,cem)},extractComponentDescription=tagName=>{let metaData=getMetaData(tagName,getCustomElements());return metaData&&metaData.description};import{render as render2}from"lit-html";import{addons,useEffect}from"@storybook/preview-api";import{SNIPPET_RENDERED,SourceType}from"@storybook/docs-tools";var LIT_EXPRESSION_COMMENTS=/<!--\?lit\$[0-9]+\$-->|<!--\??-->/g;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 applyTransformSource(source,context){let{transformSource}=context.parameters.docs??{};return typeof transformSource!="function"?source:transformSource(source,context)}function sourceDecorator(storyFn,context){let story=context?.parameters.docs?.source?.excludeDecorators?context.originalStoryFn(context.args,context):storyFn(),source;if(useEffect(()=>{source&&addons.getChannel().emit(SNIPPET_RENDERED,context.id,source)}),!skipSourceRender(context)){let container=window.document.createElement("div");render2(story,container),source=applyTransformSource(container.innerHTML.replace(LIT_EXPRESSION_COMMENTS,""),context)}return story}var decorators=[sourceDecorator],parameters={docs:{extractArgTypes,extractComponentDescription,inlineStories:!0,source:{type:SourceType2.DYNAMIC,language:"html"}}},argTypesEnhancers=[enhanceArgTypes];var parameters2={framework:"web-components",...parameters};export{argTypesEnhancers,decorators,parameters2 as parameters,render,renderToCanvas};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Args, ComponentAnnotations, AnnotatedStoryFn, StoryAnnotations } from '@storybook/
|
|
2
|
-
|
|
3
|
-
import {
|
|
1
|
+
import { Args, ComponentAnnotations, AnnotatedStoryFn, StoryAnnotations, StrictArgs, DecoratorFunction, LoaderFunction, StoryContext as StoryContext$1, Addon_ClientStoryApi, Addon_Loadable } from '@storybook/types';
|
|
2
|
+
export { ArgTypes, Args, Parameters, StrictArgs } from '@storybook/types';
|
|
3
|
+
import { W as WebComponentsRenderer } from './types-cbbc479a.js';
|
|
4
|
+
export { W as WebComponentsRenderer } from './types-cbbc479a.js';
|
|
4
5
|
import 'lit-html';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -8,42 +9,41 @@ import 'lit-html';
|
|
|
8
9
|
*
|
|
9
10
|
* @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
+
type Meta<TArgs = Args> = ComponentAnnotations<WebComponentsRenderer, TArgs>;
|
|
12
13
|
/**
|
|
13
14
|
* Story function that represents a CSFv2 component example.
|
|
14
15
|
*
|
|
15
16
|
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
+
type StoryFn<TArgs = Args> = AnnotatedStoryFn<WebComponentsRenderer, TArgs>;
|
|
18
19
|
/**
|
|
19
20
|
* Story function that represents a CSFv3 component example.
|
|
20
21
|
*
|
|
21
22
|
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
type StoryObj<TArgs = Args> = StoryAnnotations<WebComponentsRenderer, TArgs>;
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
+
* @deprecated Use `StoryFn` instead.
|
|
27
|
+
* Use `StoryObj` if you want to migrate to CSF3, which uses objects instead of functions to represent stories.
|
|
28
|
+
* You can read more about the CSF3 format here: https://storybook.js.org/blog/component-story-format-3-0/
|
|
29
|
+
*
|
|
30
|
+
* Story function that represents a CSFv2 component example.
|
|
26
31
|
*
|
|
27
32
|
* @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
|
|
28
33
|
*/
|
|
29
|
-
|
|
34
|
+
type Story<TArgs = Args> = StoryFn<TArgs>;
|
|
35
|
+
type Decorator<TArgs = StrictArgs> = DecoratorFunction<WebComponentsRenderer, TArgs>;
|
|
36
|
+
type Loader<TArgs = StrictArgs> = LoaderFunction<WebComponentsRenderer, TArgs>;
|
|
37
|
+
type StoryContext<TArgs = StrictArgs> = StoryContext$1<WebComponentsRenderer, TArgs>;
|
|
30
38
|
|
|
31
|
-
interface ClientApi extends
|
|
32
|
-
|
|
33
|
-
configure(loader: Loadable, module: NodeModule): void;
|
|
34
|
-
getStorybook(): IStorybookSection[];
|
|
35
|
-
clearDecorators(): void;
|
|
39
|
+
interface ClientApi extends Addon_ClientStoryApi<WebComponentsRenderer['storyResult']> {
|
|
40
|
+
configure(loader: Addon_Loadable, module: NodeModule): void;
|
|
36
41
|
forceReRender(): void;
|
|
37
42
|
raw: () => any;
|
|
38
43
|
}
|
|
39
44
|
declare const storiesOf: ClientApi['storiesOf'];
|
|
40
45
|
declare const configure: ClientApi['configure'];
|
|
41
|
-
declare const addDecorator: ClientApi['addDecorator'];
|
|
42
|
-
declare const addParameters: ClientApi['addParameters'];
|
|
43
|
-
declare const clearDecorators: ClientApi['clearDecorators'];
|
|
44
|
-
declare const setAddon: ClientApi['setAddon'];
|
|
45
46
|
declare const forceReRender: ClientApi['forceReRender'];
|
|
46
|
-
declare const getStorybook: ClientApi['getStorybook'];
|
|
47
47
|
declare const raw: ClientApi['raw'];
|
|
48
48
|
|
|
49
49
|
declare function isValidComponent(tagName: string): boolean;
|
|
@@ -55,4 +55,4 @@ declare function setCustomElements(customElements: any): void;
|
|
|
55
55
|
declare function setCustomElementsManifest(customElements: any): void;
|
|
56
56
|
declare function getCustomElements(): any;
|
|
57
57
|
|
|
58
|
-
export {
|
|
58
|
+
export { Decorator, Loader, Meta, Story, StoryContext, StoryFn, StoryObj, configure, forceReRender, getCustomElements, isValidComponent, isValidMetaData, raw, setCustomElements, setCustomElementsManifest, storiesOf };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
1
|
+
var S=Object.create;var p=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,h=Object.prototype.hasOwnProperty;var x=(e,o)=>{for(var r in o)p(e,r,{get:o[r],enumerable:!0})},l=(e,o,r,n)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of A(o))!h.call(e,i)&&i!==r&&p(e,i,{get:()=>o[i],enumerable:!(n=b(o,i))||n.enumerable});return e};var a=(e,o,r)=>(r=e!=null?S(M(e)):{},l(o||!e||!e.__esModule?p(r,"default",{value:e,enumerable:!0}):r,e)),E=e=>l(p({},"__esModule",{value:!0}),e);var V={};x(V,{configure:()=>H,forceReRender:()=>K,getCustomElements:()=>v,isValidComponent:()=>Y,isValidMetaData:()=>B,raw:()=>U,setCustomElements:()=>F,setCustomElementsManifest:()=>k,storiesOf:()=>W});module.exports=E(V);var g=a(require("global"));var c=a(require("global")),{window:L}=c.default;L.STORYBOOK_ENV="web-components";var O=require("@storybook/preview-api");var u=a(require("global")),y=require("ts-dedent"),_=require("lit-html"),C=require("lit-html/directive-helpers.js"),s=require("@storybook/preview-api"),{Node:N}=u.default;function w({storyFn:e,kind:o,name:r,showMain:n,showError:i,forceRemount:m},t){let d=e();if(n(),(0,C.isTemplateResult)(d)){(m||!t.querySelector('[id="root-inner"]'))&&(t.innerHTML='<div id="root-inner"></div>');let T=t.querySelector('[id="root-inner"]');(0,_.render)(d,T),(0,s.simulatePageLoad)(t)}else if(typeof d=="string")t.innerHTML=d,(0,s.simulatePageLoad)(t);else if(d instanceof N){if(t.firstChild===d&&!m)return;t.innerHTML="",t.appendChild(d),(0,s.simulateDOMContentLoaded)()}else i({title:`Expecting an HTML snippet or DOM node from the story: "${r}" of "${o}".`,description:y.dedent`
|
|
2
2
|
Did you forget to return the HTML snippet from the story?
|
|
3
3
|
Use "() => <your snippet or node>" or when defining the story.
|
|
4
|
-
`})}
|
|
5
|
-
See the readme of addon-docs for web components for more details.`)}
|
|
4
|
+
`})}var R="web-components",f=(0,O.start)(w),W=(e,o)=>f.clientApi.storiesOf(e,o).addParameters({framework:R}),H=(...e)=>f.configure(R,...e),K=f.forceReRender,U=f.clientApi.raw;function Y(e){if(!e)return!1;if(typeof e=="string")return!0;throw new Error('Provided component needs to be a string. e.g. component: "my-element"')}function B(e){if(!e)return!1;if(e.tags&&Array.isArray(e.tags)||e.modules&&Array.isArray(e.modules))return!0;throw new Error(`You need to setup valid meta data in your config.js via setCustomElements().
|
|
5
|
+
See the readme of addon-docs for web components for more details.`)}function F(e){window.__STORYBOOK_CUSTOM_ELEMENTS__=e}function k(e){window.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__=e}function v(){return window.__STORYBOOK_CUSTOM_ELEMENTS__||window.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__}var{window:D,EventSource:P}=g.default;module&&module.hot&&module.hot.decline&&(module.hot.decline(),new P("__webpack_hmr").addEventListener("message",function(r){try{let{action:n}=JSON.parse(r.data);n==="built"&&D.location.reload()}catch{}}));0&&(module.exports={configure,forceReRender,getCustomElements,isValidComponent,isValidMetaData,raw,setCustomElements,setCustomElementsManifest,storiesOf});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{configure,forceReRender,getCustomElements,isValidComponent,isValidMetaData,raw,setCustomElements,setCustomElementsManifest,storiesOf}from"./chunk-UOPG23OB.mjs";export{configure,forceReRender,getCustomElements,isValidComponent,isValidMetaData,raw,setCustomElements,setCustomElementsManifest,storiesOf};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WebRenderer } from '@storybook/types';
|
|
2
|
+
import { TemplateResult, SVGTemplateResult } from 'lit-html';
|
|
3
|
+
|
|
4
|
+
type StoryFnHtmlReturnType = string | Node | TemplateResult | SVGTemplateResult;
|
|
5
|
+
interface WebComponentsRenderer extends WebRenderer {
|
|
6
|
+
component: string;
|
|
7
|
+
storyResult: StoryFnHtmlReturnType;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { WebComponentsRenderer as W };
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/web-components",
|
|
3
|
-
"version": "7.0.0-
|
|
3
|
+
"version": "7.0.0-beta.0",
|
|
4
4
|
"description": "Storybook web-components renderer",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lit-html",
|
|
@@ -43,31 +43,29 @@
|
|
|
43
43
|
"types": "dist/index.d.ts",
|
|
44
44
|
"files": [
|
|
45
45
|
"dist/**/*",
|
|
46
|
+
"template/**/*",
|
|
46
47
|
"README.md",
|
|
47
48
|
"*.js",
|
|
48
49
|
"*.d.ts"
|
|
49
50
|
],
|
|
50
51
|
"scripts": {
|
|
51
|
-
"
|
|
52
|
+
"check": "../../../scripts/node_modules/.bin/tsc --noEmit",
|
|
53
|
+
"prep": "../../../scripts/prepare/bundle.ts"
|
|
52
54
|
},
|
|
53
55
|
"dependencies": {
|
|
54
|
-
"@storybook/
|
|
55
|
-
"@storybook/
|
|
56
|
-
"@storybook/
|
|
57
|
-
"@storybook/
|
|
58
|
-
"@storybook/
|
|
59
|
-
"@storybook/
|
|
60
|
-
"@storybook/preview-web": "7.0.0-alpha.8",
|
|
61
|
-
"@storybook/store": "7.0.0-alpha.8",
|
|
62
|
-
"core-js": "^3.8.2",
|
|
56
|
+
"@storybook/client-logger": "7.0.0-beta.0",
|
|
57
|
+
"@storybook/core-client": "7.0.0-beta.0",
|
|
58
|
+
"@storybook/docs-tools": "7.0.0-beta.0",
|
|
59
|
+
"@storybook/manager-api": "7.0.0-beta.0",
|
|
60
|
+
"@storybook/preview-api": "7.0.0-beta.0",
|
|
61
|
+
"@storybook/types": "7.0.0-beta.0",
|
|
63
62
|
"global": "^4.4.0",
|
|
64
|
-
"react": "16.14.0",
|
|
65
|
-
"react-dom": "16.14.0",
|
|
66
63
|
"ts-dedent": "^2.0.0"
|
|
67
64
|
},
|
|
68
65
|
"devDependencies": {
|
|
69
|
-
"
|
|
70
|
-
"lit-html": "2.0.2"
|
|
66
|
+
"lit": "2.3.1",
|
|
67
|
+
"lit-html": "2.0.2",
|
|
68
|
+
"typescript": "~4.9.3"
|
|
71
69
|
},
|
|
72
70
|
"peerDependencies": {
|
|
73
71
|
"lit-html": "^1.4.1 || ^2.0.0"
|
|
@@ -78,9 +76,12 @@
|
|
|
78
76
|
"publishConfig": {
|
|
79
77
|
"access": "public"
|
|
80
78
|
},
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
"bundler": {
|
|
80
|
+
"entries": [
|
|
81
|
+
"./src/index.ts",
|
|
82
|
+
"./src/config.ts"
|
|
83
|
+
],
|
|
84
|
+
"platform": "browser"
|
|
85
|
+
},
|
|
86
|
+
"gitHead": "2e4ddde6a0a291266d91fe6a5ecda767bf119e70"
|
|
86
87
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { html } from 'lit-html';
|
|
2
|
+
import { styleMap } from 'lit-html/directives/style-map.js';
|
|
3
|
+
import './button.css';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Primary UI component for user interaction
|
|
7
|
+
*/
|
|
8
|
+
export const Button = ({ primary, backgroundColor = null, size, label, onClick }) => {
|
|
9
|
+
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
10
|
+
|
|
11
|
+
return html`
|
|
12
|
+
<button
|
|
13
|
+
type="button"
|
|
14
|
+
class=${['storybook-button', `storybook-button--${size || 'medium'}`, mode].join(' ')}
|
|
15
|
+
style=${styleMap({ backgroundColor })}
|
|
16
|
+
@click=${onClick}
|
|
17
|
+
>
|
|
18
|
+
${label}
|
|
19
|
+
</button>
|
|
20
|
+
`;
|
|
21
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Button } from './Button';
|
|
2
|
+
|
|
3
|
+
// More on how to set up stories at: https://storybook.js.org/docs/7.0/web-components/writing-stories/introduction
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Example/Button',
|
|
6
|
+
tags: ['docsPage'],
|
|
7
|
+
render: (args) => Button(args),
|
|
8
|
+
argTypes: {
|
|
9
|
+
backgroundColor: { control: 'color' },
|
|
10
|
+
onClick: { action: 'onClick' },
|
|
11
|
+
size: {
|
|
12
|
+
control: { type: 'select' },
|
|
13
|
+
options: ['small', 'medium', 'large'],
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// More on writing stories with args: https://storybook.js.org/docs/7.0/web-components/writing-stories/args
|
|
19
|
+
export const Primary = {
|
|
20
|
+
args: {
|
|
21
|
+
primary: true,
|
|
22
|
+
label: 'Button',
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const Secondary = {
|
|
27
|
+
args: {
|
|
28
|
+
label: 'Button',
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const Large = {
|
|
33
|
+
args: {
|
|
34
|
+
size: 'large',
|
|
35
|
+
label: 'Button',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const Small = {
|
|
40
|
+
args: {
|
|
41
|
+
size: 'small',
|
|
42
|
+
label: 'Button',
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { html } from 'lit-html';
|
|
2
|
+
|
|
3
|
+
import { Button } from './Button';
|
|
4
|
+
import './header.css';
|
|
5
|
+
|
|
6
|
+
export const Header = ({ user, onLogin, onLogout, onCreateAccount }) => html`
|
|
7
|
+
<header>
|
|
8
|
+
<div class="wrapper">
|
|
9
|
+
<div>
|
|
10
|
+
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
|
11
|
+
<g fill="none" fillRule="evenodd">
|
|
12
|
+
<path
|
|
13
|
+
d="M10 0h12a10 10 0 0110 10v12a10 10 0 01-10 10H10A10 10 0 010 22V10A10 10 0 0110 0z"
|
|
14
|
+
fill="#FFF"
|
|
15
|
+
/>
|
|
16
|
+
<path
|
|
17
|
+
d="M5.3 10.6l10.4 6v11.1l-10.4-6v-11zm11.4-6.2l9.7 5.5-9.7 5.6V4.4z"
|
|
18
|
+
fill="#555AB9"
|
|
19
|
+
/>
|
|
20
|
+
<path
|
|
21
|
+
d="M27.2 10.6v11.2l-10.5 6V16.5l10.5-6zM15.7 4.4v11L6 10l9.7-5.5z"
|
|
22
|
+
fill="#91BAF8"
|
|
23
|
+
/>
|
|
24
|
+
</g>
|
|
25
|
+
</svg>
|
|
26
|
+
<h1>Acme</h1>
|
|
27
|
+
</div>
|
|
28
|
+
<div>
|
|
29
|
+
${user
|
|
30
|
+
? Button({ size: 'small', onClick: onLogout, label: 'Log out' })
|
|
31
|
+
: html`${Button({
|
|
32
|
+
size: 'small',
|
|
33
|
+
onClick: onLogin,
|
|
34
|
+
label: 'Log in',
|
|
35
|
+
})}
|
|
36
|
+
${Button({
|
|
37
|
+
primary: true,
|
|
38
|
+
size: 'small',
|
|
39
|
+
onClick: onCreateAccount,
|
|
40
|
+
label: 'Sign up',
|
|
41
|
+
})}`}
|
|
42
|
+
</div>
|
|
43
|
+
</div>
|
|
44
|
+
</header>
|
|
45
|
+
`;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Header } from './Header';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
title: 'Example/Header',
|
|
5
|
+
// This component will have an automatically generated docsPage entry: https://storybook.js.org/web-components/vue/writing-docs/docs-page
|
|
6
|
+
tags: ['docsPage'],
|
|
7
|
+
render: (args) => Header(args),
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const LoggedIn = {
|
|
11
|
+
args: {
|
|
12
|
+
user: {
|
|
13
|
+
name: 'Jane Doe',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const LoggedOut = {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { html } from 'lit-html';
|
|
2
|
+
import { Header } from './Header';
|
|
3
|
+
import './page.css';
|
|
4
|
+
|
|
5
|
+
export const Page = ({ user, onLogin, onLogout, onCreateAccount }) => html`
|
|
6
|
+
<article>
|
|
7
|
+
${Header({
|
|
8
|
+
user,
|
|
9
|
+
onLogin,
|
|
10
|
+
onLogout,
|
|
11
|
+
onCreateAccount,
|
|
12
|
+
})}
|
|
13
|
+
|
|
14
|
+
<section>
|
|
15
|
+
<h2>Pages in Storybook</h2>
|
|
16
|
+
<p>
|
|
17
|
+
We recommend building UIs with a
|
|
18
|
+
<a href="https://componentdriven.org" target="_blank" rel="noopener noreferrer">
|
|
19
|
+
<strong>component-driven</strong> </a
|
|
20
|
+
>process starting with atomic components and ending with pages.
|
|
21
|
+
</p>
|
|
22
|
+
<p>
|
|
23
|
+
Render pages with mock data. This makes it easy to build and review page states without
|
|
24
|
+
needing to navigate to them in your app. Here are some handy patterns for managing page data
|
|
25
|
+
in Storybook:
|
|
26
|
+
</p>
|
|
27
|
+
<ul>
|
|
28
|
+
<li>
|
|
29
|
+
Use a higher-level connected component. Storybook helps you compose such data from the
|
|
30
|
+
"args" of child component stories
|
|
31
|
+
</li>
|
|
32
|
+
<li>
|
|
33
|
+
Assemble data in the page component from your services. You can mock these services out
|
|
34
|
+
using Storybook.
|
|
35
|
+
</li>
|
|
36
|
+
</ul>
|
|
37
|
+
<p>
|
|
38
|
+
Get a guided tutorial on component-driven development at
|
|
39
|
+
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer">
|
|
40
|
+
Storybook tutorials
|
|
41
|
+
</a>
|
|
42
|
+
. Read more in the
|
|
43
|
+
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer"> docs </a>
|
|
44
|
+
.
|
|
45
|
+
</p>
|
|
46
|
+
<div class="tip-wrapper">
|
|
47
|
+
<span class="tip">Tip</span> Adjust the width of the canvas with the
|
|
48
|
+
<svg width="10" height="10" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg">
|
|
49
|
+
<g fill="none" fillRule="evenodd">
|
|
50
|
+
<path
|
|
51
|
+
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
|
|
52
|
+
id="a"
|
|
53
|
+
fill="#999"
|
|
54
|
+
/>
|
|
55
|
+
</g>
|
|
56
|
+
</svg>
|
|
57
|
+
Viewports addon in the toolbar
|
|
58
|
+
</div>
|
|
59
|
+
</section>
|
|
60
|
+
</article>
|
|
61
|
+
`;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Page } from './Page';
|
|
2
|
+
import * as HeaderStories from './Header.stories';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Example/Page',
|
|
6
|
+
render: (args) => Page(args),
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const LoggedIn = {
|
|
10
|
+
args: {
|
|
11
|
+
// More on composing args: https://storybook.js.org/docs/7.0/web-components/writing-stories/args#args-composition
|
|
12
|
+
...HeaderStories.LoggedIn.args,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const LoggedOut = {
|
|
17
|
+
args: {
|
|
18
|
+
...HeaderStories.LoggedOut.args,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/web-components';
|
|
2
|
+
import type { ButtonProps } from './Button';
|
|
3
|
+
import { Button } from './Button';
|
|
4
|
+
|
|
5
|
+
// More on how to set up stories at: https://storybook.js.org/docs/7.0/web-components/writing-stories/introduction
|
|
6
|
+
const meta: Meta<ButtonProps> = {
|
|
7
|
+
title: 'Example/Button',
|
|
8
|
+
tags: ['docsPage'],
|
|
9
|
+
render: (args) => Button(args),
|
|
10
|
+
argTypes: {
|
|
11
|
+
backgroundColor: { control: 'color' },
|
|
12
|
+
onClick: { action: 'onClick' },
|
|
13
|
+
size: {
|
|
14
|
+
control: { type: 'select' },
|
|
15
|
+
options: ['small', 'medium', 'large'],
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default meta;
|
|
21
|
+
type Story = StoryObj<ButtonProps>;
|
|
22
|
+
|
|
23
|
+
// More on writing stories with args: https://storybook.js.org/docs/7.0/web-components/writing-stories/args
|
|
24
|
+
export const Primary: Story = {
|
|
25
|
+
args: {
|
|
26
|
+
primary: true,
|
|
27
|
+
label: 'Button',
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const Secondary: Story = {
|
|
32
|
+
args: {
|
|
33
|
+
label: 'Button',
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const Large: Story = {
|
|
38
|
+
args: {
|
|
39
|
+
size: 'large',
|
|
40
|
+
label: 'Button',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const Small: Story = {
|
|
45
|
+
args: {
|
|
46
|
+
size: 'small',
|
|
47
|
+
label: 'Button',
|
|
48
|
+
},
|
|
49
|
+
};
|