storybook-i18n
Version:
Tool to set the locale in Storybook for i18n
2 lines • 1.14 kB
JavaScript
import {addons,types,useGlobals,useChannel}from'storybook/manager-api';import r from'react';import {WithTooltip,TooltipLinkList,IconButton}from'storybook/internal/components';import {GlobeIcon}from'@storybook/icons';var s="storybook/i18n-addon",c="storybook/i18n-addon/tool",a="LOCALE_CHANGED";var T=t=>typeof t=="string"?{title:t}:{title:t.title||"",icon:t.icon,right:t.right},b=(t,e,i)=>t?Object.entries(t).map(([o,n])=>({...T(n),id:o,active:o===e,onClick:()=>i(o)})):[{id:"none",title:"No locales in parameters",active:true,onClick:()=>{}}],h=()=>{let[t,e]=useGlobals(),{locale:i,locales:o}=t,n=useChannel({});return r.createElement(WithTooltip,{closeOnOutsideClick:true,placement:"top",tooltip:({onHide:m})=>r.createElement(TooltipLinkList,{links:b(o,i,l=>{l!==i&&(e({locale:l}),n(a,l)),m();})}),trigger:"click"},r.createElement(IconButton,{key:"i18n-locale",title:"Locale Selector"},r.createElement(GlobeIcon,null)))},p=h;addons.register(s,()=>{addons.add(c,{title:"Storybook i18n",type:types.TOOL,match:({viewMode:t})=>!!t?.match(/^(story|docs)$/),render:p});});//# sourceMappingURL=manager.js.map
//# sourceMappingURL=manager.js.map