@bothub-chat/ui
Version:
Bothub UI Components
2 lines (1 loc) • 546 B
JavaScript
const t=({triggerRect:t,dropdownWidth:i,dropdownHeight:e,position:n,offset:o,viewportPadding:r=8,flip:h=!0,matchTriggerWidth:d=!1})=>{let a;switch(n){case"right":a=t.right-i;break;case"center":a=t.left+(t.width-i)/2;break;default:a=t.left}const w=window.innerWidth-i-r;a=Math.max(r,Math.min(a,w));let c=t.bottom+o;if(h&&e>0){const i=window.innerHeight-t.bottom-o,n=t.top-o;e>i&&n>i&&(c=t.top-e-o)}const g=window.innerHeight-e-r;return c=Math.max(r,Math.min(c,g)),Object.assign({top:c,left:a},d?{minWidth:t.width}:{})};export{t as getMenuCoords};