@stevendejong/storybook-stylesheet-toggle 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Storybook contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # Storybook Addon Stylesheet Toggle
2
+ Simple toggle to load stylesheets
@@ -0,0 +1,3 @@
1
+ declare const _default: {};
2
+
3
+ export { _default as default };
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ var e={};
4
+
5
+ module.exports = e;
6
+ //# sourceMappingURL=out.js.map
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["src_default"],"mappings":"AACA,IAAOA,EAAQ,CAAC","sourcesContent":["// make it work with --isolatedModules\nexport default {};\n"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,5 @@
1
+ var e={};
2
+
3
+ export { e as default };
4
+ //# sourceMappingURL=out.js.map
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"names":["src_default"],"mappings":"AACA,IAAOA,EAAQ,CAAC","sourcesContent":["// make it work with --isolatedModules\nexport default {};\n"]}
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var r = require('react');
4
+ var managerApi = require('@storybook/manager-api');
5
+ var components = require('@storybook/components');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var r__default = /*#__PURE__*/_interopDefault(r);
10
+
11
+ var l="stylesheetToggle",n=`${l}/tool`,e="stylesheetToggle";var c={default:""};var A=({stylesheets:o})=>{let[a]=managerApi.useGlobals(),u=[!0,"true"].includes(a[e]);if(o===null)return null;let g={...c,...o},s=localStorage.getItem(e,"default"),f=t=>{localStorage.setItem(e,t),window.location.reload();},i=[];for(let[t,S]of Object.entries(g))i.push({id:t,title:t,onClick:()=>f(t),active:!s&&t==="default"||s===t});return r__default.default.createElement(components.WithTooltip,{placement:"top",trigger:"click",tooltip:r__default.default.createElement(components.TooltipLinkList,{links:i}),closeOnOutsideClick:!0},r__default.default.createElement(components.IconButton,{key:n,active:u,title:"Activate Stylesheet"},r__default.default.createElement(components.Icons,{icon:"paintbrush"})))},p=A;managerApi.addons.register(l,()=>{managerApi.addons.add(l,{title:"Stylesheet Toggle",type:managerApi.types.TOOL,render:()=>{let o=managerApi.useParameter(e,null);return r__default.default.createElement(p,{stylesheets:o})}});});
12
+ //# sourceMappingURL=out.js.map
13
+ //# sourceMappingURL=manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manager.tsx","../src/constants.ts","../src/Tool.tsx","../src/defaults.ts"],"names":["React","addons","types","useParameter","ADDON_ID","TOOL_ID","PARAM_KEY","useGlobals","Icons","IconButton","WithTooltip","TooltipLinkList","defaultStylesheets","Tool","stylesheets","globals","isActive","mapping","active","toggleStylesheet","sheet","items","name","url","Tool_default"],"mappings":"AAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,SAAAC,EAAO,gBAAAC,MAAoB,yBCDrC,IAAMC,EAAW,mBACXC,EAAU,GAAGD,SACbE,EAAY,mBCFzB,OAAON,MAAW,QAClB,OAAS,cAAAO,MAAkB,yBAC3B,OAAS,SAAAC,EAAO,cAAAC,EAAY,eAAAC,EAAa,mBAAAC,MAAuB,wBCFzD,IAAMC,EAA8C,CACzD,QAAW,EACb,EDKA,IAAMC,EAAO,CAAC,CAAE,YAAAC,CAAY,IAA+B,CACzD,GAAM,CAACC,CAAO,EAAIR,EAAW,EACvBS,EAAW,CAAC,GAAM,MAAM,EAAE,SAASD,EAAQT,CAAS,CAAC,EAE3D,GAAIQ,IAAgB,KAClB,OAAO,KAGT,IAAMG,EAAU,CACd,GAAGL,EACH,GAAGE,CACL,EAEMI,EAAS,aAAa,QAAQZ,EAAW,SAAS,EAElDa,EAAoBC,GAAkB,CAC1C,aAAa,QAAQd,EAAWc,CAAK,EACrC,OAAO,SAAS,OAAO,CACzB,EAEMC,EAAQ,CAAC,EACf,OAAW,CAACC,EAAMC,CAAG,IAAK,OAAO,QAAQN,CAAO,EAC9CI,EAAM,KAAK,CACT,GAAIC,EACJ,MAAOA,EACP,QAAS,IAAMH,EAAiBG,CAAI,EACpC,OAAU,CAACJ,GAAUI,IAAS,WAAcJ,IAAWI,CACzD,CAAC,EAGH,OACEtB,EAAA,cAACU,EAAA,CACC,UAAU,MACV,QAAQ,QACR,QAASV,EAAA,cAACW,EAAA,CAAgB,MAAOU,EAAO,EACxC,oBAAmB,IAEnBrB,EAAA,cAACS,EAAA,CACC,IAAKJ,EACL,OAAQW,EACR,MAAM,uBAENhB,EAAA,cAACQ,EAAA,CAAM,KAAK,aAAa,CAC3B,CACF,CAEJ,EAEOgB,EAAQX,EFlDfZ,EAAO,SAASG,EAAU,IAAM,CAC9BH,EAAO,IAAIG,EAAU,CACnB,MAAO,oBACP,KAAMF,EAAM,KACZ,OAAQ,IAAM,CACZ,IAAMY,EAAcX,EAClBG,EACA,IACF,EAEA,OAAON,EAAA,cAACwB,EAAA,CAAK,YAAaV,EAAa,CACzC,CACF,CAAC,CACH,CAAC","sourcesContent":["import React from \"react\";\nimport { addons, types, useParameter } from \"@storybook/manager-api\";\nimport { ADDON_ID, PARAM_KEY } from \"./constants\";\nimport Tool from './Tool'\n\naddons.register(ADDON_ID, () => {\n addons.add(ADDON_ID, {\n title: 'Stylesheet Toggle',\n type: types.TOOL,\n render: () => {\n const stylesheets = useParameter(\n PARAM_KEY,\n null,\n );\n\n return <Tool stylesheets={stylesheets} />\n },\n });\n});\n","export const ADDON_ID = \"stylesheetToggle\";\nexport const TOOL_ID = `${ADDON_ID}/tool`;\nexport const PARAM_KEY = `stylesheetToggle`;\n\n","import React from \"react\";\nimport { useGlobals } from \"@storybook/manager-api\";\nimport { Icons, IconButton, WithTooltip, TooltipLinkList } from '@storybook/components';\nimport { PARAM_KEY, TOOL_ID } from \"./constants\";\nimport { defaultStylesheets } from './defaults'\n\n\nconst Tool = ({ stylesheets }: {[key: string]: string}) => {\n const [globals] = useGlobals();\n const isActive = [true, \"true\"].includes(globals[PARAM_KEY]);\n\n if (stylesheets === null) {\n return null;\n }\n\n const mapping = {\n ...defaultStylesheets,\n ...stylesheets,\n };\n\n const active = localStorage.getItem(PARAM_KEY, 'default');\n\n const toggleStylesheet = (sheet: string) => {\n localStorage.setItem(PARAM_KEY, sheet)\n window.location.reload()\n }\n\n const items = [];\n for (const [name, url] of Object.entries(mapping)) {\n items.push({\n id: name,\n title: name,\n onClick: () => toggleStylesheet(name),\n active: ((!active && name === 'default') || active === name)\n })\n }\n\n return (\n <WithTooltip\n placement=\"top\"\n trigger=\"click\"\n tooltip={<TooltipLinkList links={items} />}\n closeOnOutsideClick\n >\n <IconButton\n key={TOOL_ID}\n active={isActive}\n title=\"Activate Stylesheet\"\n >\n <Icons icon=\"paintbrush\" />\n </IconButton>\n </WithTooltip>\n );\n};\n\nexport default Tool\n","export const defaultStylesheets: {[key: string]: string} = {\n \"default\": ''\n}\n"]}
@@ -0,0 +1,7 @@
1
+ import r from 'react';
2
+ import { addons, types, useParameter, useGlobals } from '@storybook/manager-api';
3
+ import { WithTooltip, TooltipLinkList, IconButton, Icons } from '@storybook/components';
4
+
5
+ var l="stylesheetToggle",n=`${l}/tool`,e="stylesheetToggle";var c={default:""};var A=({stylesheets:o})=>{let[a]=useGlobals(),u=[!0,"true"].includes(a[e]);if(o===null)return null;let g={...c,...o},s=localStorage.getItem(e,"default"),f=t=>{localStorage.setItem(e,t),window.location.reload();},i=[];for(let[t,S]of Object.entries(g))i.push({id:t,title:t,onClick:()=>f(t),active:!s&&t==="default"||s===t});return r.createElement(WithTooltip,{placement:"top",trigger:"click",tooltip:r.createElement(TooltipLinkList,{links:i}),closeOnOutsideClick:!0},r.createElement(IconButton,{key:n,active:u,title:"Activate Stylesheet"},r.createElement(Icons,{icon:"paintbrush"})))},p=A;addons.register(l,()=>{addons.add(l,{title:"Stylesheet Toggle",type:types.TOOL,render:()=>{let o=useParameter(e,null);return r.createElement(p,{stylesheets:o})}});});
6
+ //# sourceMappingURL=out.js.map
7
+ //# sourceMappingURL=manager.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manager.tsx","../src/constants.ts","../src/Tool.tsx","../src/defaults.ts"],"names":["React","addons","types","useParameter","ADDON_ID","TOOL_ID","PARAM_KEY","useGlobals","Icons","IconButton","WithTooltip","TooltipLinkList","defaultStylesheets","Tool","stylesheets","globals","isActive","mapping","active","toggleStylesheet","sheet","items","name","url","Tool_default"],"mappings":"AAAA,OAAOA,MAAW,QAClB,OAAS,UAAAC,EAAQ,SAAAC,EAAO,gBAAAC,MAAoB,yBCDrC,IAAMC,EAAW,mBACXC,EAAU,GAAGD,SACbE,EAAY,mBCFzB,OAAON,MAAW,QAClB,OAAS,cAAAO,MAAkB,yBAC3B,OAAS,SAAAC,EAAO,cAAAC,EAAY,eAAAC,EAAa,mBAAAC,MAAuB,wBCFzD,IAAMC,EAA8C,CACzD,QAAW,EACb,EDKA,IAAMC,EAAO,CAAC,CAAE,YAAAC,CAAY,IAA+B,CACzD,GAAM,CAACC,CAAO,EAAIR,EAAW,EACvBS,EAAW,CAAC,GAAM,MAAM,EAAE,SAASD,EAAQT,CAAS,CAAC,EAE3D,GAAIQ,IAAgB,KAClB,OAAO,KAGT,IAAMG,EAAU,CACd,GAAGL,EACH,GAAGE,CACL,EAEMI,EAAS,aAAa,QAAQZ,EAAW,SAAS,EAElDa,EAAoBC,GAAkB,CAC1C,aAAa,QAAQd,EAAWc,CAAK,EACrC,OAAO,SAAS,OAAO,CACzB,EAEMC,EAAQ,CAAC,EACf,OAAW,CAACC,EAAMC,CAAG,IAAK,OAAO,QAAQN,CAAO,EAC9CI,EAAM,KAAK,CACT,GAAIC,EACJ,MAAOA,EACP,QAAS,IAAMH,EAAiBG,CAAI,EACpC,OAAU,CAACJ,GAAUI,IAAS,WAAcJ,IAAWI,CACzD,CAAC,EAGH,OACEtB,EAAA,cAACU,EAAA,CACC,UAAU,MACV,QAAQ,QACR,QAASV,EAAA,cAACW,EAAA,CAAgB,MAAOU,EAAO,EACxC,oBAAmB,IAEnBrB,EAAA,cAACS,EAAA,CACC,IAAKJ,EACL,OAAQW,EACR,MAAM,uBAENhB,EAAA,cAACQ,EAAA,CAAM,KAAK,aAAa,CAC3B,CACF,CAEJ,EAEOgB,EAAQX,EFlDfZ,EAAO,SAASG,EAAU,IAAM,CAC9BH,EAAO,IAAIG,EAAU,CACnB,MAAO,oBACP,KAAMF,EAAM,KACZ,OAAQ,IAAM,CACZ,IAAMY,EAAcX,EAClBG,EACA,IACF,EAEA,OAAON,EAAA,cAACwB,EAAA,CAAK,YAAaV,EAAa,CACzC,CACF,CAAC,CACH,CAAC","sourcesContent":["import React from \"react\";\nimport { addons, types, useParameter } from \"@storybook/manager-api\";\nimport { ADDON_ID, PARAM_KEY } from \"./constants\";\nimport Tool from './Tool'\n\naddons.register(ADDON_ID, () => {\n addons.add(ADDON_ID, {\n title: 'Stylesheet Toggle',\n type: types.TOOL,\n render: () => {\n const stylesheets = useParameter(\n PARAM_KEY,\n null,\n );\n\n return <Tool stylesheets={stylesheets} />\n },\n });\n});\n","export const ADDON_ID = \"stylesheetToggle\";\nexport const TOOL_ID = `${ADDON_ID}/tool`;\nexport const PARAM_KEY = `stylesheetToggle`;\n\n","import React from \"react\";\nimport { useGlobals } from \"@storybook/manager-api\";\nimport { Icons, IconButton, WithTooltip, TooltipLinkList } from '@storybook/components';\nimport { PARAM_KEY, TOOL_ID } from \"./constants\";\nimport { defaultStylesheets } from './defaults'\n\n\nconst Tool = ({ stylesheets }: {[key: string]: string}) => {\n const [globals] = useGlobals();\n const isActive = [true, \"true\"].includes(globals[PARAM_KEY]);\n\n if (stylesheets === null) {\n return null;\n }\n\n const mapping = {\n ...defaultStylesheets,\n ...stylesheets,\n };\n\n const active = localStorage.getItem(PARAM_KEY, 'default');\n\n const toggleStylesheet = (sheet: string) => {\n localStorage.setItem(PARAM_KEY, sheet)\n window.location.reload()\n }\n\n const items = [];\n for (const [name, url] of Object.entries(mapping)) {\n items.push({\n id: name,\n title: name,\n onClick: () => toggleStylesheet(name),\n active: ((!active && name === 'default') || active === name)\n })\n }\n\n return (\n <WithTooltip\n placement=\"top\"\n trigger=\"click\"\n tooltip={<TooltipLinkList links={items} />}\n closeOnOutsideClick\n >\n <IconButton\n key={TOOL_ID}\n active={isActive}\n title=\"Activate Stylesheet\"\n >\n <Icons icon=\"paintbrush\" />\n </IconButton>\n </WithTooltip>\n );\n};\n\nexport default Tool\n","export const defaultStylesheets: {[key: string]: string} = {\n \"default\": ''\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import { ProjectAnnotations, Renderer } from '@storybook/types';
2
+
3
+ declare const preview: ProjectAnnotations<Renderer>;
4
+
5
+ export { preview as default };
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var previewApi = require('@storybook/preview-api');
4
+
5
+ var t="stylesheetToggle";var c={default:""};var y=(o,r)=>{let [s]=previewApi.useGlobals(),n=s[t],{theme:e}=r.globals,l=r.parameters[t];({...c,...l});let i=localStorage.getItem(t,"default"),m=l[i];return previewApi.useEffect(()=>{g(m);},[n,e]),o()};function g(o){let r=document.querySelector("#stylesheetToggle"),s=document.querySelector("#storybook-root"),n=document.querySelector("body"),e=document.createElement("link");console.log("stylesheet",o),e.setAttribute("id","stylesheetToggle"),e.setAttribute("rel","stylesheet"),e.setAttribute("href",o),r?.remove(),n.insertBefore(e,s);}var f={decorators:[y],globals:{[t]:!1}},k=f;
6
+
7
+ module.exports = k;
8
+ //# sourceMappingURL=out.js.map
9
+ //# sourceMappingURL=preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants.ts","../src/withGlobals.ts","../src/defaults.ts","../src/preview.ts"],"names":["ADDON_ID","TOOL_ID","PARAM_KEY","useEffect","useGlobals","defaultStylesheets","withGlobals","StoryFn","context","globals","stylesheetToggle","theme","stylesheets","mapping","active","stylesheet","injectStylesheet","previousStylesheet","beforeElement","bodyElement","stylesheetElement","preview","preview_default"],"mappings":"AAAO,IAAMA,EAAW,mBACXC,EAAU,GAAGD,SACbE,EAAY,mBCGzB,OAAS,aAAAC,EAAW,cAAAC,MAAkB,yBCL/B,IAAMC,EAA8C,CACzD,QAAW,EACb,EDQO,IAAMC,EAAc,CACzBC,EACAC,IACG,CACH,GAAM,CAACC,CAAO,EAAIL,EAAW,EACvBM,EAAmBD,EAAQP,CAAS,EAEpC,CAAE,MAAAS,CAAM,EAAIH,EAAQ,QACpBI,EAAcJ,EAAQ,WAAWN,CAAS,EAC1CW,EAAU,CACd,GAAGR,EACH,GAAGO,CACL,EACME,EAAS,aAAa,QAAQZ,EAAW,SAAS,EAClDa,EAAaH,EAAYE,CAAM,EAErC,OAAAX,EAAU,IAAM,CACda,EAAiBD,CAAU,CAC7B,EAAG,CAACL,EAAkBC,CAAK,CAAC,EAErBJ,EAAQ,CACjB,EAEA,SAASS,EAAiBD,EAAoB,CAC5C,IAAME,EAAqB,SAAS,cAAc,mBAAmB,EAC/DC,EAAgB,SAAS,cAAc,iBAAiB,EACxDC,EAAc,SAAS,cAAc,MAAM,EAC3CC,EAAoB,SAAS,cAAc,MAAM,EAEvD,QAAQ,IAAI,aAAcL,CAAU,EAEpCK,EAAkB,aAAa,KAAM,kBAAkB,EACvDA,EAAkB,aAAa,MAAO,YAAY,EAClDA,EAAkB,aAAa,OAAQL,CAAU,EAEjDE,GAAoB,OAAO,EAC3BE,EAAY,aAAaC,EAAmBF,CAAa,CAC3D,CE1CA,IAAMG,EAAwC,CAC5C,WAAY,CAACf,CAAW,EACxB,QAAS,CACP,CAACJ,CAAS,EAAG,EACf,CACF,EAEOoB,EAAQD","sourcesContent":["export const ADDON_ID = \"stylesheetToggle\";\nexport const TOOL_ID = `${ADDON_ID}/tool`;\nexport const PARAM_KEY = `stylesheetToggle`;\n\n","import type {\n Renderer,\n PartialStoryFn as StoryFunction,\n StoryContext,\n} from \"@storybook/types\";\nimport { useEffect, useGlobals } from \"@storybook/preview-api\";\nimport { PARAM_KEY } from \"./constants\";\nimport { defaultStylesheets } from './defaults'\n\n\nexport const withGlobals = (\n StoryFn: StoryFunction<Renderer>,\n context: StoryContext<Renderer>\n) => {\n const [globals] = useGlobals();\n const stylesheetToggle = globals[PARAM_KEY];\n \n const { theme } = context.globals;\n const stylesheets = context.parameters[PARAM_KEY];\n const mapping = {\n ...defaultStylesheets,\n ...stylesheets,\n };\n const active = localStorage.getItem(PARAM_KEY, 'default');\n const stylesheet = stylesheets[active]\n\n useEffect(() => {\n injectStylesheet(stylesheet);\n }, [stylesheetToggle, theme]);\n\n return StoryFn();\n};\n\nfunction injectStylesheet(stylesheet: string) {\n const previousStylesheet = document.querySelector('#stylesheetToggle');\n const beforeElement = document.querySelector('#storybook-root');\n const bodyElement = document.querySelector('body');\n const stylesheetElement = document.createElement('link');\n\n console.log('stylesheet', stylesheet)\n\n stylesheetElement.setAttribute('id', 'stylesheetToggle');\n stylesheetElement.setAttribute('rel', 'stylesheet');\n stylesheetElement.setAttribute('href', stylesheet);\n\n previousStylesheet?.remove();\n bodyElement.insertBefore(stylesheetElement, beforeElement);\n}\n","export const defaultStylesheets: {[key: string]: string} = {\n \"default\": ''\n}\n","import type { Renderer, ProjectAnnotations } from \"@storybook/types\";\nimport { PARAM_KEY } from \"./constants\";\nimport { withGlobals } from \"./withGlobals\";\n\n\nconst preview: ProjectAnnotations<Renderer> = {\n decorators: [withGlobals],\n globals: {\n [PARAM_KEY]: false,\n },\n};\n\nexport default preview;\n"]}
@@ -0,0 +1,7 @@
1
+ import { useGlobals, useEffect } from '@storybook/preview-api';
2
+
3
+ var t="stylesheetToggle";var c={default:""};var y=(o,r)=>{let [s]=useGlobals(),n=s[t],{theme:e}=r.globals,l=r.parameters[t];({...c,...l});let i=localStorage.getItem(t,"default"),m=l[i];return useEffect(()=>{g(m);},[n,e]),o()};function g(o){let r=document.querySelector("#stylesheetToggle"),s=document.querySelector("#storybook-root"),n=document.querySelector("body"),e=document.createElement("link");console.log("stylesheet",o),e.setAttribute("id","stylesheetToggle"),e.setAttribute("rel","stylesheet"),e.setAttribute("href",o),r?.remove(),n.insertBefore(e,s);}var f={decorators:[y],globals:{[t]:!1}},k=f;
4
+
5
+ export { k as default };
6
+ //# sourceMappingURL=out.js.map
7
+ //# sourceMappingURL=preview.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants.ts","../src/withGlobals.ts","../src/defaults.ts","../src/preview.ts"],"names":["ADDON_ID","TOOL_ID","PARAM_KEY","useEffect","useGlobals","defaultStylesheets","withGlobals","StoryFn","context","globals","stylesheetToggle","theme","stylesheets","mapping","active","stylesheet","injectStylesheet","previousStylesheet","beforeElement","bodyElement","stylesheetElement","preview","preview_default"],"mappings":"AAAO,IAAMA,EAAW,mBACXC,EAAU,GAAGD,SACbE,EAAY,mBCGzB,OAAS,aAAAC,EAAW,cAAAC,MAAkB,yBCL/B,IAAMC,EAA8C,CACzD,QAAW,EACb,EDQO,IAAMC,EAAc,CACzBC,EACAC,IACG,CACH,GAAM,CAACC,CAAO,EAAIL,EAAW,EACvBM,EAAmBD,EAAQP,CAAS,EAEpC,CAAE,MAAAS,CAAM,EAAIH,EAAQ,QACpBI,EAAcJ,EAAQ,WAAWN,CAAS,EAC1CW,EAAU,CACd,GAAGR,EACH,GAAGO,CACL,EACME,EAAS,aAAa,QAAQZ,EAAW,SAAS,EAClDa,EAAaH,EAAYE,CAAM,EAErC,OAAAX,EAAU,IAAM,CACda,EAAiBD,CAAU,CAC7B,EAAG,CAACL,EAAkBC,CAAK,CAAC,EAErBJ,EAAQ,CACjB,EAEA,SAASS,EAAiBD,EAAoB,CAC5C,IAAME,EAAqB,SAAS,cAAc,mBAAmB,EAC/DC,EAAgB,SAAS,cAAc,iBAAiB,EACxDC,EAAc,SAAS,cAAc,MAAM,EAC3CC,EAAoB,SAAS,cAAc,MAAM,EAEvD,QAAQ,IAAI,aAAcL,CAAU,EAEpCK,EAAkB,aAAa,KAAM,kBAAkB,EACvDA,EAAkB,aAAa,MAAO,YAAY,EAClDA,EAAkB,aAAa,OAAQL,CAAU,EAEjDE,GAAoB,OAAO,EAC3BE,EAAY,aAAaC,EAAmBF,CAAa,CAC3D,CE1CA,IAAMG,EAAwC,CAC5C,WAAY,CAACf,CAAW,EACxB,QAAS,CACP,CAACJ,CAAS,EAAG,EACf,CACF,EAEOoB,EAAQD","sourcesContent":["export const ADDON_ID = \"stylesheetToggle\";\nexport const TOOL_ID = `${ADDON_ID}/tool`;\nexport const PARAM_KEY = `stylesheetToggle`;\n\n","import type {\n Renderer,\n PartialStoryFn as StoryFunction,\n StoryContext,\n} from \"@storybook/types\";\nimport { useEffect, useGlobals } from \"@storybook/preview-api\";\nimport { PARAM_KEY } from \"./constants\";\nimport { defaultStylesheets } from './defaults'\n\n\nexport const withGlobals = (\n StoryFn: StoryFunction<Renderer>,\n context: StoryContext<Renderer>\n) => {\n const [globals] = useGlobals();\n const stylesheetToggle = globals[PARAM_KEY];\n \n const { theme } = context.globals;\n const stylesheets = context.parameters[PARAM_KEY];\n const mapping = {\n ...defaultStylesheets,\n ...stylesheets,\n };\n const active = localStorage.getItem(PARAM_KEY, 'default');\n const stylesheet = stylesheets[active]\n\n useEffect(() => {\n injectStylesheet(stylesheet);\n }, [stylesheetToggle, theme]);\n\n return StoryFn();\n};\n\nfunction injectStylesheet(stylesheet: string) {\n const previousStylesheet = document.querySelector('#stylesheetToggle');\n const beforeElement = document.querySelector('#storybook-root');\n const bodyElement = document.querySelector('body');\n const stylesheetElement = document.createElement('link');\n\n console.log('stylesheet', stylesheet)\n\n stylesheetElement.setAttribute('id', 'stylesheetToggle');\n stylesheetElement.setAttribute('rel', 'stylesheet');\n stylesheetElement.setAttribute('href', stylesheet);\n\n previousStylesheet?.remove();\n bodyElement.insertBefore(stylesheetElement, beforeElement);\n}\n","export const defaultStylesheets: {[key: string]: string} = {\n \"default\": ''\n}\n","import type { Renderer, ProjectAnnotations } from \"@storybook/types\";\nimport { PARAM_KEY } from \"./constants\";\nimport { withGlobals } from \"./withGlobals\";\n\n\nconst preview: ProjectAnnotations<Renderer> = {\n decorators: [withGlobals],\n globals: {\n [PARAM_KEY]: false,\n },\n};\n\nexport default preview;\n"]}
package/manager.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./dist/manager";
package/package.json ADDED
@@ -0,0 +1,113 @@
1
+ {
2
+ "name": "@stevendejong/storybook-stylesheet-toggle",
3
+ "version": "0.0.0",
4
+ "description": "Simple toggle to load stylesheets",
5
+ "keywords": [
6
+ "storybook-addons"
7
+ ],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/stevendejongnl/storybook-stylesheet-toggle.git"
11
+ },
12
+ "author": "Steven de Jong <steven@steven-dejong.nl>",
13
+ "license": "MIT",
14
+ "exports": {
15
+ ".": {
16
+ "require": "./dist/index.js",
17
+ "import": "./dist/index.mjs",
18
+ "types": "./dist/index.d.ts"
19
+ },
20
+ "./manager": {
21
+ "require": "./dist/manager.js",
22
+ "import": "./dist/manager.mjs",
23
+ "types": "./dist/manager.d.ts"
24
+ },
25
+ "./preview": {
26
+ "require": "./dist/preview.js",
27
+ "import": "./dist/preview.mjs",
28
+ "types": "./dist/preview.d.ts"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "main": "dist/index.js",
33
+ "module": "dist/index.mjs",
34
+ "types": "dist/index.d.ts",
35
+ "files": [
36
+ "dist/**/*",
37
+ "README.md",
38
+ "*.js",
39
+ "*.d.ts"
40
+ ],
41
+ "scripts": {
42
+ "clean": "rimraf ./dist",
43
+ "prebuild": "yarn clean",
44
+ "build": "tsup",
45
+ "build:watch": "yarn build --watch",
46
+ "test": "echo \"Error: no test specified\" && exit 1",
47
+ "start": "run-p build:watch 'storybook --quiet'",
48
+ "prerelease": "zx scripts/prepublish-checks.mjs",
49
+ "release": "yarn build && auto shipit",
50
+ "storybook": "storybook dev -p 6006",
51
+ "build-storybook": "storybook build"
52
+ },
53
+ "devDependencies": {
54
+ "@storybook/addon-essentials": "^7.4.5",
55
+ "@storybook/addon-interactions": "^7.4.5",
56
+ "@storybook/addon-links": "^7.4.5",
57
+ "@storybook/addon-mdx-gfm": "^7.4.5",
58
+ "@storybook/react": "^7.4.5",
59
+ "@storybook/react-vite": "^7.4.5",
60
+ "@storybook/testing-library": "^0.2.1",
61
+ "@types/node": "^18.15.0",
62
+ "@types/react": "^18.0.34",
63
+ "@vitejs/plugin-react": "^3.1.0",
64
+ "auto": "^10.3.0",
65
+ "boxen": "^5.0.1",
66
+ "dedent": "^0.7.0",
67
+ "npm-run-all": "^4.1.5",
68
+ "prettier": "^2.3.1",
69
+ "prompts": "^2.4.2",
70
+ "prop-types": "^15.8.1",
71
+ "react": "^18.0.0",
72
+ "react-dom": "^18.0.0",
73
+ "rimraf": "^3.0.2",
74
+ "storybook": "^7.4.5",
75
+ "tsup": "^6.6.3",
76
+ "typescript": "^4.9.5",
77
+ "vite": "^4.1.4",
78
+ "zx": "^1.14.1"
79
+ },
80
+ "peerDependencies": {
81
+ "@storybook/blocks": "^7.0.0",
82
+ "@storybook/components": "^7.0.0",
83
+ "@storybook/core-events": "^7.0.0",
84
+ "@storybook/manager-api": "^7.0.0",
85
+ "@storybook/preview-api": "^7.0.0",
86
+ "@storybook/theming": "^7.0.0",
87
+ "@storybook/types": "^7.0.0",
88
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
89
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
90
+ },
91
+ "peerDependenciesMeta": {
92
+ "react": {
93
+ "optional": true
94
+ },
95
+ "react-dom": {
96
+ "optional": true
97
+ }
98
+ },
99
+ "resolutions": {
100
+ "jackspeak": "2.1.1"
101
+ },
102
+ "publishConfig": {
103
+ "access": "public",
104
+ "registry": "https://registry.npmjs.org"
105
+ },
106
+ "storybook": {
107
+ "displayName": "Stylesheet Toggle",
108
+ "supportedFrameworks": [
109
+ "web-components"
110
+ ],
111
+ "icon": "https://user-images.githubusercontent.com/321738/63501763-88dbf600-c4cc-11e9-96cd-94adadc2fd72.png"
112
+ }
113
+ }
package/preview.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./dist/preview";