@bothub-chat/ui 2.55.1-develop-d3a19f57-22b1-4ab0-86a6-68b280d7bcd3 → 2.55.1-develop-93a02c77-9894-4548-87fa-3ecdd02abd3d
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useTransition as n}from"@react-spring/web";import{useRef as r,useState as o,useId as i,useMemo as
|
|
1
|
+
import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useTransition as n}from"@react-spring/web";import{useRef as r,useState as o,useId as i,useMemo as c,useCallback as a,useLayoutEffect as l,useEffect as s}from"react";import{LangSwitcherStyled as d,LangSwitcherButton as u,LangSwitcherIcon as v,LangSwitcherItem as m,LangSwitcherList as f,LangSwitcherLabel as g,LangSwitcherInput as p}from"./styled.js";const w=({lang:w,region:b,dataRegions:h,dataLanguages:y,onChange:L})=>{const E=r(null),[j,k]=o(!1),C=i(),x=c(()=>h.find(e=>"object"==typeof e&&e.value===b.value),[h,b]),W=c(()=>y.find(e=>"object"==typeof e&&e.value===w.value),[y,w]),$=a(()=>{k(e=>!e)},[]);l(()=>{if(!j)return;const e=new MutationObserver(()=>{const e=document.getElementById(C),t=null==e?void 0:e.getBoundingClientRect();t&&e&&(t.left<0&&(e.style.transform=`translateX(${-t.left-4}px)`),t.right>window.innerWidth&&(e.style.transform=`translateX(${window.innerWidth-t.right-4}px)`))});return e.observe(E.current,{attributes:!1,childList:!0,subtree:!1}),()=>{e.disconnect()}},[j]);const H=a(()=>{k(!1)},[]),O=a((e,t)=>{"object"==typeof e&&e.value&&L({lang:"lang"===t?e.value:w.value,region:"region"===t?e.value:b.value})},[L]);s(()=>{const e=E.current;if(null!==e){const t=t=>{e.contains(t.target)||k(!1)},n=()=>k(!1);return document.addEventListener("click",t),window.addEventListener("blur",n),()=>{document.removeEventListener("click",t),window.removeEventListener("blur",n)}}},[]),s(()=>{if(!j)return;const e=e=>{const t=E.current,n=e.target;t&&t.contains(n)||H()};return window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("scroll",e,!0)}},[j]),s(()=>{const e=E.current;if(null!==e){const t=t=>{e.contains(t.target)||k(!1)},n=()=>k(!1);return document.addEventListener("click",t),window.addEventListener("blur",n),()=>{document.removeEventListener("click",t),window.removeEventListener("blur",n)}}},[]);const B=n(j,{from:{opacity:0,transform:"scale(0)"},enter:{opacity:j?1:.5,transform:`scale(${j?1:.999})`},leave:{opacity:0,transform:"scale(0.999)"},config:{duration:150}});return e(d,{ref:E,children:[t(u,{onClick:$,disableHoverColor:!0,endIcon:t(v,{$open:j}),children:e(m,{children:["object"==typeof x&&x.icon,"/ ","object"==typeof W&&W.value]})}),B((n,r)=>r&&e(f,{style:n,id:C,children:[t(g,{children:w.label}),t(p,{contentHeight:"fit-content",compactWidth:!0,onOptionClick:e=>O(e,"lang"),value:W,data:y,dataTest:"lang-select"}),t(g,{children:b.label}),t(p,{contentHeight:"fit-content",compactWidth:!0,onOptionClick:e=>O(e,"region"),value:x,data:h,dataTest:"region-select"})]}))]})};export{w as LangSwitcher};
|