@etchteam/storybook-addon-css-variables-theme
Version:
Switch CSS files to change themes
7 lines (5 loc) • 1.17 kB
JavaScript
import { makeDecorator, addons } from '@storybook/preview-api';
var c="cssVariables",l="No Theme",u="storybookcssvariables:theme:change";function d(e){let t=`${e}=`,o=decodeURIComponent(document.cookie).split(";");for(let s=0;s<o.length;s++){let a=o[s];for(;a.startsWith(" ");)a=a.substring(1);if(a.startsWith(t))return a.substring(t.length,a.length)}return null}function p(e,t,n){let o=new Date;o.setTime(o.getTime()+n*24*60*60*1e3);let s=`expires=${o.toUTCString()}`;document.cookie=`${e}=${t};${s};path=/`;}var r=null;async function b(e,t){let n=t[e];n&&(n.use(),r&&r.unuse(),r=n),r&&e===l&&(r.unuse(),r=null);}function f({id:e,files:t,save:n}){b(e,t),n&&p(c,e,10);let o=new CustomEvent(u,{detail:{theme:e}});document?.dispatchEvent(o);}var w=makeDecorator({name:"CSS Variables Theme",parameterName:c,wrapper:(e,t,{parameters:n})=>{let{files:o,theme:s,defaultTheme:a}=n,g=t.globals[c],C=addons.getChannel(),i=d(c),m=Object.hasOwn(o,i)||i===l?i:null,h=g||s||m||a;return t.globals[c]=h,f({id:h,files:o,save:!s||!m}),C.on(`${c}Change`,({id:E})=>f({id:E,files:o,save:!0})),e(t)}});
export { w as default };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.js.map