@bothub-chat/ui 2.55.1-develop-fb3910d9-5aaf-452e-8fc7-536502e2090e → 2.55.1-develop-d3a19f57-22b1-4ab0-86a6-68b280d7bcd3
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 a,useCallback as c,useLayoutEffect as l,useEffect 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 a,useCallback as c,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:h,dataRegions:b,dataLanguages:y,onChange:E})=>{const L=r(null),[j,k]=o(!1),C=i(),x=a(()=>b.find(e=>"object"==typeof e&&e.value===h.value),[b,h]),W=a(()=>y.find(e=>"object"==typeof e&&e.value===w.value),[y,w]),$=c(()=>{k(e=>!e)},[]);l(()=>{var e;const t=()=>{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)`))};if(j)return null===(e=L.current)||void 0===e||e.addEventListener("transitionstart",t),()=>{var e;null===(e=L.current)||void 0===e||e.removeEventListener("transitionstart",t)}},[j]);const H=c(()=>{k(!1)},[]),B=c((e,t)=>{"object"==typeof e&&e.value&&E({lang:"lang"===t?e.value:w.value,region:"region"===t?e.value:h.value})},[E]);s(()=>{const e=L.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=L.current,n=e.target;t&&t.contains(n)||H()};return window.addEventListener("scroll",e,!0),()=>{window.removeEventListener("scroll",e,!0)}},[j]),s(()=>{const e=L.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 I=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:L,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]})}),I((n,r)=>r&&e(f,{style:n,id:C,children:[t(g,{children:w.label}),t(p,{contentHeight:"fit-content",compactWidth:!0,onOptionClick:e=>B(e,"lang"),value:W,data:y,dataTest:"lang-select"}),t(g,{children:h.label}),t(p,{contentHeight:"fit-content",compactWidth:!0,onOptionClick:e=>B(e,"region"),value:x,data:b,dataTest:"region-select"})]}))]})};export{w as LangSwitcher};
|