Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@leafygreen-ui/popover

Package Overview
Dependencies
Maintainers
3
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leafygreen-ui/popover - npm Package Compare versions

Comparing version 7.1.0 to 7.1.1

6

CHANGELOG.md
# @leafygreen-ui/popover
## 7.1.1
### Patch Changes
- a6360ea1: Fixes issue where Popover used without a portal did not animate from the correct direction when appearing
## 7.1.0

@@ -4,0 +10,0 @@

2

dist/esm/index.js

@@ -1,2 +0,2 @@

import t,{useState as e,useCallback as n,useMemo as r,Fragment as o}from"react";import i from"prop-types";import{Transition as c}from"react-transition-group";import{css as a,cx as l}from"@leafygreen-ui/emotion";import s from"@leafygreen-ui/portal";import{useViewportSize as u,useMutationObserver as f,useObjectDependency as d,usePrevious as p,useIsomorphicLayoutEffect as g}from"@leafygreen-ui/hooks";function h(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function m(){return(m=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function y(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function w(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?y(Object(n),!0).forEach((function(e){h(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function v(t,e){if(null==t)return{};var n,r,o=function(t,e){if(null==t)return{};var n,r,o={},i=Object.keys(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}function E(t,e){return e||(e=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}function P(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var c,a=t[Symbol.iterator]();!(r=(c=a.next()).done)&&(n.push(c.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}(t,e)||j(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(t){return function(t){if(Array.isArray(t))return O(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||j(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function j(t,e){if(t){if("string"==typeof t)return O(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?O(t,e):void 0}}function O(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var S,C,x,D,H,V,R,M,T={Top:"top",Bottom:"bottom",Left:"left",Right:"right",CenterVertical:"center-vertical",CenterHorizontal:"center-horizontal"},B={Start:"start",Middle:"middle",End:"end",Fit:"fit"};function F(t){var e=t.useRelativePositioning,n=t.spacing,r=t.align,o=t.justify,i=t.referenceElViewportPos,c=void 0===i?W:i,a=t.referenceElDocumentPos,l=void 0===a?W:a,s=t.contentElViewportPos,u=void 0===s?W:s,f=t.contentElDocumentPos,d=void 0===f?W:f,p=t.windowHeight,g=void 0===p?window.innerHeight:p,h=t.windowWidth,m=void 0===h?window.innerWidth:h,y={windowWidth:m,windowHeight:g,referenceElViewportPos:c,contentElViewportPos:u,spacing:n},v=function(t,e){var n=e.spacing,r=e.windowWidth,o=e.windowHeight,i=e.contentElViewportPos,c=e.referenceElViewportPos;return[t].concat(b(Q[t])).find((function(t){return[T.Top,T.Bottom,T.CenterVertical].includes(t)?K({top:q({align:t,contentElPos:i,referenceElPos:c,spacing:n}),windowHeight:o,contentHeight:i.height}):!![T.Left,T.Right,T.CenterHorizontal].includes(t)&&J({left:G({align:t,contentElPos:i,referenceElPos:c,spacing:n}),windowWidth:r,contentWidth:i.width})}))||t}(r,y),E=function(t,e,n){var r,o,i=n.spacing,c=n.windowWidth,a=n.windowHeight,l=n.contentElViewportPos,s=n.referenceElViewportPos,u=[t].concat(b(Z[t]));switch(e){case T.Top:case T.Bottom:case T.CenterVertical:return null!==(r=u.find((function(t){return J({contentWidth:t===B.Fit?s.width:l.width,windowWidth:c,left:G({contentElPos:l,referenceElPos:s,spacing:i,align:e,justify:t})})})))&&void 0!==r?r:Z[t][0];case T.Left:case T.Right:case T.CenterHorizontal:return null!==(o=u.find((function(t){return K({contentHeight:t===B.Fit?s.height:l.height,windowHeight:a,top:q({contentElPos:l,referenceElPos:s,spacing:i,align:e,justify:t})})})))&&void 0!==o?o:Z[t][0]}}(o,v,y),P=function(t){var e,n,r=t.align,o=t.justify,i=I[r],c=null!==(e=i.x)&&void 0!==e?e:A[o],a=null!==(n=i.y)&&void 0!==n?n:N[o];return"".concat(c," ").concat(a)}({align:v,justify:E}),j=function(t,e){var n=.8;switch(t){case T.Top:return"translate3d(0, ".concat(e,"px, 0) scale(").concat(n,")");case T.Bottom:return"translate3d(0, -".concat(e,"px, 0) scale(").concat(n,")");case T.Left:return"translate3d(".concat(e,"px, 0, 0) scale(").concat(n,")");case T.Right:return"translate3d(-".concat(e,"px, 0, 0) scale(").concat(n,")");case T.CenterHorizontal:case T.CenterVertical:return"scale(".concat(n,")")}}(v,n);return e?{align:v,justify:E,positionCSS:w({},Y({align:v,justify:E,referenceElDocumentPos:l,contentElDocumentPos:d,spacing:n}),{transformOrigin:P,transform:j})}:{align:v,justify:E,positionCSS:w({},$({align:v,justify:E,referenceElDocumentPos:l,contentElDocumentPos:d,spacing:n,windowHeight:g,windowWidth:m}),{transformOrigin:P,transform:j})}}var W={top:0,bottom:0,left:0,right:0,height:0,width:0};function L(t){if(!t)return W;var e=t.getBoundingClientRect(),n=e.top,r=e.bottom,o=e.left,i=e.right,c=t.offsetHeight,a=t.offsetWidth,l=window,s=l.scrollX,u=l.scrollY;return{top:n+u,bottom:r+u,left:o+s,right:i+s,height:c,width:a}}function z(t){if(!t)return W;var e=t.getBoundingClientRect();return{top:e.top,bottom:e.bottom,left:e.left,right:e.right,height:t.offsetHeight,width:t.offsetWidth}}var N=(h(S={},B.Start,"top"),h(S,B.Middle,"center"),h(S,B.End,"bottom"),h(S,B.Fit,"center"),S),A=(h(C={},B.Start,"left"),h(C,B.Middle,"center"),h(C,B.End,"right"),h(C,B.Fit,"center"),C),I=(h(x={},T.Left,{x:"right"}),h(x,T.Right,{x:"left"}),h(x,T.Top,{y:"bottom"}),h(x,T.Bottom,{y:"top"}),h(x,T.CenterHorizontal,{x:"center"}),h(x,T.CenterVertical,{y:"center"}),x);var k=(h(D={},B.Start,{top:0}),h(D,B.End,{bottom:0}),h(D,B.Middle,(function(t){var e=t.contentElDocumentPos,n=t.referenceElDocumentPos;return{top:"".concat(n.height/2-e.height/2,"px")}})),h(D,B.Fit,{top:0,bottom:0}),D),U=(h(H={},B.Start,{left:0}),h(H,B.End,{right:0}),h(H,B.Middle,(function(t){var e=t.contentElDocumentPos,n=t.referenceElDocumentPos;return{left:"".concat(n.width/2-e.width/2,"px")}})),h(H,B.Fit,{left:0,right:0}),H),X=(h(V={},T.Top,{constant:function(t){var e=t.spacing;return{bottom:"calc(100% + ".concat(e,"px)")}},justifyPositions:U}),h(V,T.Bottom,{constant:function(t){var e=t.spacing;return{top:"calc(100% + ".concat(e,"px)")}},justifyPositions:U}),h(V,T.CenterVertical,{constant:function(t){var e=t.referenceElDocumentPos;return{top:"calc(".concat(e.height/2,"px - 50%)")}},justifyPositions:U}),h(V,T.Left,{constant:function(t){var e=t.spacing;return{right:"calc(100% + ".concat(e,"px)")}},justifyPositions:k}),h(V,T.Right,{constant:function(t){var e=t.spacing;return{left:"calc(100% + ".concat(e,"px)")}},justifyPositions:k}),h(V,T.CenterHorizontal,{constant:function(t){var e=t.referenceElDocumentPos;return{left:"calc(".concat(e.width/2,"px - 50%)")}},justifyPositions:k}),V);function Y(t){var e,n=t.align,r=t.justify,o=t.referenceElDocumentPos,i=t.contentElDocumentPos,c=t.spacing,a=X[n],l=a.justifyPositions[r],s={contentElDocumentPos:i,referenceElDocumentPos:o,spacing:c};return w({},null===(e=a.constant)||void 0===e?void 0:e.call(a,s),{},"function"==typeof l?l(s):l)}function $(t){var e=t.align,n=t.justify,r=t.referenceElDocumentPos,o=t.contentElDocumentPos,i=t.spacing,c=t.windowWidth,a=t.windowHeight,l="".concat(G({align:e,justify:n,referenceElPos:r,contentElPos:o,spacing:i}),"px"),s="".concat(q({align:e,justify:n,referenceElPos:r,contentElPos:o,spacing:i}),"px");return n!==B.Fit?{left:l,top:s}:[T.Left,T.Right,T.CenterHorizontal].includes(e)?{left:l,top:s,bottom:"".concat(a-r.bottom,"px")}:{left:l,top:s,right:"".concat(c-r.right,"px")}}function q(t){var e=t.align,n=t.justify,r=t.contentElPos,o=t.referenceElPos,i=t.spacing;switch(e){case T.Left:case T.Right:case T.CenterHorizontal:switch(n){case B.Start:case B.Fit:return o.top;case B.End:return o.top+o.height-r.height;case B.Middle:default:return o.top-(r.height-o.height)/2}case T.CenterVertical:return o.top-(r.height-o.height)/2;case T.Top:return o.top-r.height-i;case T.Bottom:default:return o.top+o.height+i}}function G(t){var e=t.align,n=t.justify,r=t.contentElPos,o=t.referenceElPos,i=t.spacing;switch(e){case T.Top:case T.Bottom:case T.CenterVertical:switch(n){case B.End:return o.left+o.width-r.width;case B.Middle:return o.left-(r.width-o.width)/2;case B.Start:case B.Fit:default:return o.left}case T.Left:return o.left-r.width-i;case T.Right:return o.left+o.width+i;case T.CenterHorizontal:default:return o.left-(r.width-o.width)/2}}function J(t){var e=t.left,n=t.windowWidth,r=t.contentWidth;return e>=0&&!(e+r>n)}function K(t){var e=t.top,n=t.windowHeight,r=t.contentHeight;return e>=0&&!(e+r>n)}var Q=(h(R={},T.Top,[T.Bottom]),h(R,T.Bottom,[T.Top]),h(R,T.Left,[T.Right]),h(R,T.Right,[T.Left]),h(R,T.CenterHorizontal,[T.Left,T.Right]),h(R,T.CenterVertical,[T.Top,T.Bottom]),R);var Z=(h(M={},B.Start,[B.End,B.Middle]),h(M,B.Middle,[B.End,B.Start]),h(M,B.End,[B.Start,B.Middle]),h(M,B.Fit,[B.Middle,B.Start,B.End]),M);function _(){var t=E(["\n display: none;\n "]);return _=function(){return t},t}function tt(){var t=E(["\n transform: translate3d(0, 0, 0) scale(1);\n opacity: 1;\n position: ",";\n pointer-events: initial;\n "]);return tt=function(){return t},t}function et(){var t=E(["\n transition: transform 150ms ease-in-out, opacity 150ms ease-in-out;\n position: absolute;\n opacity: 0;\n"]);return et=function(){return t},t}var nt=a(et()),rt={attributes:!0,characterData:!0,childList:!0,subtree:!0};function ot(i){var y=i.active,w=void 0!==y&&y,E=i.usePortal,b=void 0===E||E,j=i.spacing,O=void 0===j?10:j,S=i.align,C=void 0===S?T.Bottom:S,x=i.justify,D=void 0===x?B.Start:x,H=i.adjustOnMutation,V=void 0!==H&&H,R=i.children,M=i.className,W=i.portalClassName,N=i.refEl,A=v(i,["active","usePortal","spacing","align","justify","adjustOnMutation","children","className","portalClassName","refEl"]),I=P(e(null),2),k=I[0],U=I[1],X=P(e(null),2),Y=X[0],$=X[1],q=P(e(0),2),G=q[0],J=q[1],K=t.useRef(Y);K.current=Y;var Q=null;if(N&&N.current)Q=N.current;else if(k){var Z=k.parentNode;Z&&Z instanceof HTMLElement&&(Q=Z)}var et=u(),ot=V&&w,it=f(Q,rt,n(Date.now,[]),ot),ct=f(Y,rt,n(Date.now,[]),ot),at=d(z(Q)),lt=d(z(Y)),st=d(r((function(){return L(Q)}),[Q,et,it,w,C,D,G])),ut=d(r((function(){return L(Y)}),[Y,et,ct,w,C,D,G])),ft=p(D),dt=p(C),pt=ft!==D&&(D===B.Fit||ft===B.Fit)||dt!==C&&D===B.Fit;g((function(){pt&&J((function(t){return t+1}))}),[pt]);var gt=P(e(!1),2),ht=gt[0],mt=gt[1];if(g((function(){return mt(!0)}),[]),!ht)return null;var yt,wt=F({useRelativePositioning:!b,spacing:O,align:C,justify:D,referenceElViewportPos:at,referenceElDocumentPos:st,contentElViewportPos:lt,contentElDocumentPos:ut}),vt=wt.align,Et=wt.justify,Pt=wt.positionCSS,bt=a(tt(),b?"":"absolute"),jt=b?s:o,Ot=b?{className:W}:{};return yt=null==R?null:"function"==typeof R?R({align:vt,justify:Et,referenceElPos:st}):R,t.createElement(c,{nodeRef:K,in:w,timeout:{exit:150},mountOnEnter:!0,unmountOnExit:!0},(function(e){return t.createElement(t.Fragment,null,t.createElement("div",{ref:U,className:a(_())}),t.createElement(jt,Ot,t.createElement("div",m({},A,{className:l(nt,a(Pt),h({},bt,"entered"===e),M)}),t.createElement("div",{ref:$},yt))))}))}ot.displayName="Popover",ot.propTypes={children:i.oneOfType([i.node,i.func]),active:i.bool,className:i.string,align:i.oneOf(Object.values(T)),justify:i.oneOf(Object.values(B)),refEl:i.shape({current:"undefined"!=typeof window?i.instanceOf(Element):i.any}),usePortal:i.bool,portalClassName:i.string,spacing:i.number,adjustOnMutation:i.bool},ot.defaultProps={children:void 0,align:T.Bottom,justify:B.Start,active:!1,usePortal:!0,spacing:10,adjustOnMutation:!1};export default ot;export{T as Align,B as Justify};
import t,{useState as e,useMemo as n,Fragment as r}from"react";import o from"prop-types";import{Transition as i}from"react-transition-group";import{css as c,cx as a}from"@leafygreen-ui/emotion";import l from"@leafygreen-ui/portal";import{useViewportSize as s,useMutationObserver as u,useObjectDependency as f,usePrevious as d,useIsomorphicLayoutEffect as p}from"@leafygreen-ui/hooks";function g(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function h(){return(h=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function m(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function y(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?m(Object(n),!0).forEach((function(e){g(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):m(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function w(t,e){if(null==t)return{};var n,r,o=function(t,e){if(null==t)return{};var n,r,o={},i=Object.keys(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}function v(t,e){return e||(e=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}function E(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var c,a=t[Symbol.iterator]();!(r=(c=a.next()).done)&&(n.push(c.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==a.return||a.return()}finally{if(o)throw i}}return n}(t,e)||b(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function P(t){return function(t){if(Array.isArray(t))return j(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||b(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(t,e){if(t){if("string"==typeof t)return j(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?j(t,e):void 0}}function j(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var O,S,C,x,D,H,V,R,M={Top:"top",Bottom:"bottom",Left:"left",Right:"right",CenterVertical:"center-vertical",CenterHorizontal:"center-horizontal"},T={Start:"start",Middle:"middle",End:"end",Fit:"fit"};function B(t){var e=t.useRelativePositioning,n=t.spacing,r=t.align,o=t.justify,i=t.referenceElViewportPos,c=void 0===i?F:i,a=t.referenceElDocumentPos,l=void 0===a?F:a,s=t.contentElViewportPos,u=void 0===s?F:s,f=t.contentElDocumentPos,d=void 0===f?F:f,p=t.windowHeight,g=void 0===p?window.innerHeight:p,h=t.windowWidth,m=void 0===h?window.innerWidth:h,w={windowWidth:m,windowHeight:g,referenceElViewportPos:c,contentElViewportPos:u,spacing:n},v=function(t,e){var n=e.spacing,r=e.windowWidth,o=e.windowHeight,i=e.contentElViewportPos,c=e.referenceElViewportPos;return[t].concat(P(K[t])).find((function(t){return[M.Top,M.Bottom,M.CenterVertical].includes(t)?J({top:$({align:t,contentElPos:i,referenceElPos:c,spacing:n}),windowHeight:o,contentHeight:i.height}):!![M.Left,M.Right,M.CenterHorizontal].includes(t)&&G({left:q({align:t,contentElPos:i,referenceElPos:c,spacing:n}),windowWidth:r,contentWidth:i.width})}))||t}(r,w),E=function(t,e,n){var r,o,i=n.spacing,c=n.windowWidth,a=n.windowHeight,l=n.contentElViewportPos,s=n.referenceElViewportPos,u=[t].concat(P(Q[t]));switch(e){case M.Top:case M.Bottom:case M.CenterVertical:return null!==(r=u.find((function(t){return G({contentWidth:t===T.Fit?s.width:l.width,windowWidth:c,left:q({contentElPos:l,referenceElPos:s,spacing:i,align:e,justify:t})})})))&&void 0!==r?r:Q[t][0];case M.Left:case M.Right:case M.CenterHorizontal:return null!==(o=u.find((function(t){return J({contentHeight:t===T.Fit?s.height:l.height,windowHeight:a,top:$({contentElPos:l,referenceElPos:s,spacing:i,align:e,justify:t})})})))&&void 0!==o?o:Q[t][0]}}(o,v,w),b=function(t){var e,n,r=t.align,o=t.justify,i=A[r],c=null!==(e=i.x)&&void 0!==e?e:N[o],a=null!==(n=i.y)&&void 0!==n?n:z[o];return"".concat(c," ").concat(a)}({align:v,justify:E}),j=function(t,e){var n=.8;switch(t){case M.Top:return"translate3d(0, ".concat(e,"px, 0) scale(").concat(n,")");case M.Bottom:return"translate3d(0, -".concat(e,"px, 0) scale(").concat(n,")");case M.Left:return"translate3d(".concat(e,"px, 0, 0) scale(").concat(n,")");case M.Right:return"translate3d(-".concat(e,"px, 0, 0) scale(").concat(n,")");case M.CenterHorizontal:case M.CenterVertical:return"scale(".concat(n,")")}}(v,n);return e?{align:v,justify:E,positionCSS:y({},X({align:v,justify:E,referenceElDocumentPos:l,contentElDocumentPos:d,spacing:n}),{transformOrigin:b,transform:j})}:{align:v,justify:E,positionCSS:y({},Y({align:v,justify:E,referenceElDocumentPos:l,contentElDocumentPos:d,spacing:n,windowHeight:g,windowWidth:m}),{transformOrigin:b,transform:j})}}var F={top:0,bottom:0,left:0,right:0,height:0,width:0};function W(t){if(!t)return F;var e=t.getBoundingClientRect(),n=e.top,r=e.bottom,o=e.left,i=e.right,c=t.offsetHeight,a=t.offsetWidth,l=window,s=l.scrollX,u=l.scrollY;return{top:n+u,bottom:r+u,left:o+s,right:i+s,height:c,width:a}}function L(t){if(!t)return F;var e=t.getBoundingClientRect();return{top:e.top,bottom:e.bottom,left:e.left,right:e.right,height:t.offsetHeight,width:t.offsetWidth}}var z=(g(O={},T.Start,"top"),g(O,T.Middle,"center"),g(O,T.End,"bottom"),g(O,T.Fit,"center"),O),N=(g(S={},T.Start,"left"),g(S,T.Middle,"center"),g(S,T.End,"right"),g(S,T.Fit,"center"),S),A=(g(C={},M.Left,{x:"right"}),g(C,M.Right,{x:"left"}),g(C,M.Top,{y:"bottom"}),g(C,M.Bottom,{y:"top"}),g(C,M.CenterHorizontal,{x:"center"}),g(C,M.CenterVertical,{y:"center"}),C);var I=(g(x={},T.Start,{top:0}),g(x,T.End,{bottom:0}),g(x,T.Middle,(function(t){var e=t.contentElDocumentPos,n=t.referenceElDocumentPos;return{top:"".concat(n.height/2-e.height/2,"px")}})),g(x,T.Fit,{top:0,bottom:0}),x),k=(g(D={},T.Start,{left:0}),g(D,T.End,{right:0}),g(D,T.Middle,(function(t){var e=t.contentElDocumentPos,n=t.referenceElDocumentPos;return{left:"".concat(n.width/2-e.width/2,"px")}})),g(D,T.Fit,{left:0,right:0}),D),U=(g(H={},M.Top,{constant:function(t){var e=t.spacing;return{bottom:"calc(100% + ".concat(e,"px)")}},justifyPositions:k}),g(H,M.Bottom,{constant:function(t){var e=t.spacing;return{top:"calc(100% + ".concat(e,"px)")}},justifyPositions:k}),g(H,M.CenterVertical,{constant:function(t){var e=t.referenceElDocumentPos;return{top:"calc(".concat(e.height/2,"px - 50%)")}},justifyPositions:k}),g(H,M.Left,{constant:function(t){var e=t.spacing;return{right:"calc(100% + ".concat(e,"px)")}},justifyPositions:I}),g(H,M.Right,{constant:function(t){var e=t.spacing;return{left:"calc(100% + ".concat(e,"px)")}},justifyPositions:I}),g(H,M.CenterHorizontal,{constant:function(t){var e=t.referenceElDocumentPos;return{left:"calc(".concat(e.width/2,"px - 50%)")}},justifyPositions:I}),H);function X(t){var e,n=t.align,r=t.justify,o=t.referenceElDocumentPos,i=t.contentElDocumentPos,c=t.spacing,a=U[n],l=a.justifyPositions[r],s={contentElDocumentPos:i,referenceElDocumentPos:o,spacing:c};return y({},null===(e=a.constant)||void 0===e?void 0:e.call(a,s),{},"function"==typeof l?l(s):l)}function Y(t){var e=t.align,n=t.justify,r=t.referenceElDocumentPos,o=t.contentElDocumentPos,i=t.spacing,c=t.windowWidth,a=t.windowHeight,l="".concat(q({align:e,justify:n,referenceElPos:r,contentElPos:o,spacing:i}),"px"),s="".concat($({align:e,justify:n,referenceElPos:r,contentElPos:o,spacing:i}),"px");return n!==T.Fit?{left:l,top:s}:[M.Left,M.Right,M.CenterHorizontal].includes(e)?{left:l,top:s,bottom:"".concat(a-r.bottom,"px")}:{left:l,top:s,right:"".concat(c-r.right,"px")}}function $(t){var e=t.align,n=t.justify,r=t.contentElPos,o=t.referenceElPos,i=t.spacing;switch(e){case M.Left:case M.Right:case M.CenterHorizontal:switch(n){case T.Start:case T.Fit:return o.top;case T.End:return o.top+o.height-r.height;case T.Middle:default:return o.top-(r.height-o.height)/2}case M.CenterVertical:return o.top-(r.height-o.height)/2;case M.Top:return o.top-r.height-i;case M.Bottom:default:return o.top+o.height+i}}function q(t){var e=t.align,n=t.justify,r=t.contentElPos,o=t.referenceElPos,i=t.spacing;switch(e){case M.Top:case M.Bottom:case M.CenterVertical:switch(n){case T.End:return o.left+o.width-r.width;case T.Middle:return o.left-(r.width-o.width)/2;case T.Start:case T.Fit:default:return o.left}case M.Left:return o.left-r.width-i;case M.Right:return o.left+o.width+i;case M.CenterHorizontal:default:return o.left-(r.width-o.width)/2}}function G(t){var e=t.left,n=t.windowWidth,r=t.contentWidth;return e>=0&&!(e+r>n)}function J(t){var e=t.top,n=t.windowHeight,r=t.contentHeight;return e>=0&&!(e+r>n)}var K=(g(V={},M.Top,[M.Bottom]),g(V,M.Bottom,[M.Top]),g(V,M.Left,[M.Right]),g(V,M.Right,[M.Left]),g(V,M.CenterHorizontal,[M.Left,M.Right]),g(V,M.CenterVertical,[M.Top,M.Bottom]),V);var Q=(g(R={},T.Start,[T.End,T.Middle]),g(R,T.Middle,[T.End,T.Start]),g(R,T.End,[T.Start,T.Middle]),g(R,T.Fit,[T.Middle,T.Start,T.End]),R);function Z(){var t=v(["\n display: none;\n "]);return Z=function(){return t},t}function _(){var t=v(["\n opacity: 1;\n position: ",";\n pointer-events: initial;\n "]);return _=function(){return t},t}function tt(){var t=v(["\n position: absolute;\n transition: transform 150ms ease-in-out, opacity 150ms ease-in-out;\n transform: translate3d(0, 0, 0) scale(1);\n opacity: 0;\n"]);return tt=function(){return t},t}var et=c(tt()),nt={attributes:!0,characterData:!0,childList:!0,subtree:!0};function rt(o){var m=o.active,y=void 0!==m&&m,v=o.usePortal,P=void 0===v||v,b=o.spacing,j=void 0===b?10:b,O=o.align,S=void 0===O?M.Bottom:O,C=o.justify,x=void 0===C?T.Start:C,D=o.adjustOnMutation,H=void 0!==D&&D,V=o.children,R=o.className,F=o.portalClassName,z=o.refEl,N=w(o,["active","usePortal","spacing","align","justify","adjustOnMutation","children","className","portalClassName","refEl"]),A=E(e(null),2),I=A[0],k=A[1],U=E(e(null),2),X=U[0],Y=U[1],$=E(e(0),2),q=$[0],G=$[1],J=t.useRef(X);J.current=X;var K=null;if(z&&z.current)K=z.current;else if(I){var Q=I.parentNode;Q&&Q instanceof HTMLElement&&(K=Q)}var tt=s(),rt=H&&y,ot=u(K,nt,Date.now,rt),it=u(X,nt,Date.now,rt),ct=f(L(K)),at=f(L(X)),lt=f(n((function(){return W(K)}),[K,tt,ot,y,S,x,q])),st=f(n((function(){return W(X)}),[X,tt,it,y,S,x,q])),ut=d(x),ft=d(S),dt=ut!==x&&(x===T.Fit||ut===T.Fit)||ft!==S&&x===T.Fit;p((function(){dt&&G((function(t){return t+1}))}),[dt]);var pt=E(e(!1),2),gt=pt[0],ht=pt[1];if(p((function(){return ht(!0)}),[]),!gt)return null;var mt,yt=B({useRelativePositioning:!P,spacing:j,align:S,justify:x,referenceElViewportPos:ct,referenceElDocumentPos:lt,contentElViewportPos:at,contentElDocumentPos:st}),wt=yt.align,vt=yt.justify,Et=yt.positionCSS,Pt=Et.transform,bt=w(Et,["transform"]),jt=c(_(),P?"":"absolute"),Ot=P?l:r,St=P?{className:F}:{};return mt=null==V?null:"function"==typeof V?V({align:wt,justify:vt,referenceElPos:lt}):V,t.createElement(i,{nodeRef:J,in:y,timeout:150,mountOnEnter:!0,unmountOnExit:!0,appear:!0},(function(e){var n;return t.createElement(t.Fragment,null,t.createElement("div",{ref:k,className:c(Z())}),t.createElement(Ot,St,t.createElement("div",h({},N,{className:a(et,c(bt),(n={},g(n,c({transform:Pt}),"entering"===e||"exiting"===e),g(n,jt,"entered"===e),n),R)}),t.createElement("div",{ref:Y},mt))))}))}rt.displayName="Popover",rt.propTypes={children:o.oneOfType([o.node,o.func]),active:o.bool,className:o.string,align:o.oneOf(Object.values(M)),justify:o.oneOf(Object.values(T)),refEl:o.shape({current:"undefined"!=typeof window?o.instanceOf(Element):o.any}),usePortal:o.bool,portalClassName:o.string,spacing:o.number,adjustOnMutation:o.bool},rt.defaultProps={children:void 0,align:M.Bottom,justify:T.Start,active:!1,usePortal:!0,spacing:10,adjustOnMutation:!1};export default rt;export{M as Align,T as Justify};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types"),require("react-transition-group"),require("@leafygreen-ui/emotion"),require("@leafygreen-ui/portal"),require("@leafygreen-ui/hooks")):"function"==typeof define&&define.amd?define(["exports","react","prop-types","react-transition-group","@leafygreen-ui/emotion","@leafygreen-ui/portal","@leafygreen-ui/hooks"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@leafygreen-ui/popover"]={},t.React,t.PropTypes,t.reactTransitionGroup,t["@leafygreen-ui/emotion"],t["@leafygreen-ui/portal"],t["@leafygreen-ui/hooks"])}(this,(function(t,e,n,r,o,i,a){"use strict";function c(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var u=c(e),l=c(n),s=c(i);function f(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function d(){return(d=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function p(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function g(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?p(Object(n),!0).forEach((function(e){f(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):p(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function h(t,e){if(null==t)return{};var n,r,o=function(t,e){if(null==t)return{};var n,r,o={},i=Object.keys(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}function y(t,e){return e||(e=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}function m(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(r=(a=c.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==c.return||c.return()}finally{if(o)throw i}}return n}(t,e)||w(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(t){return function(t){if(Array.isArray(t))return b(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||w(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(t,e){if(t){if("string"==typeof t)return b(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?b(t,e):void 0}}function b(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var P,E,j,O,S,D,C,x,H={Top:"top",Bottom:"bottom",Left:"left",Right:"right",CenterVertical:"center-vertical",CenterHorizontal:"center-horizontal"},M={Start:"start",Middle:"middle",End:"end",Fit:"fit"};function T(t){var e=t.useRelativePositioning,n=t.spacing,r=t.align,o=t.justify,i=t.referenceElViewportPos,a=void 0===i?V:i,c=t.referenceElDocumentPos,u=void 0===c?V:c,l=t.contentElViewportPos,s=void 0===l?V:l,f=t.contentElDocumentPos,d=void 0===f?V:f,p=t.windowHeight,h=void 0===p?window.innerHeight:p,y=t.windowWidth,m=void 0===y?window.innerWidth:y,w={windowWidth:m,windowHeight:h,referenceElViewportPos:a,contentElViewportPos:s,spacing:n},b=function(t,e){var n=e.spacing,r=e.windowWidth,o=e.windowHeight,i=e.contentElViewportPos,a=e.referenceElViewportPos;return[t].concat(v(U[t])).find((function(t){return[H.Top,H.Bottom,H.CenterVertical].includes(t)?J({top:q({align:t,contentElPos:i,referenceElPos:a,spacing:n}),windowHeight:o,contentHeight:i.height}):!![H.Left,H.Right,H.CenterHorizontal].includes(t)&&G({left:_({align:t,contentElPos:i,referenceElPos:a,spacing:n}),windowWidth:r,contentWidth:i.width})}))||t}(r,w),P=function(t,e,n){var r,o,i=n.spacing,a=n.windowWidth,c=n.windowHeight,u=n.contentElViewportPos,l=n.referenceElViewportPos,s=[t].concat(v(X[t]));switch(e){case H.Top:case H.Bottom:case H.CenterVertical:return null!==(r=s.find((function(t){return G({contentWidth:t===M.Fit?l.width:u.width,windowWidth:a,left:_({contentElPos:u,referenceElPos:l,spacing:i,align:e,justify:t})})})))&&void 0!==r?r:X[t][0];case H.Left:case H.Right:case H.CenterHorizontal:return null!==(o=s.find((function(t){return J({contentHeight:t===M.Fit?l.height:u.height,windowHeight:c,top:q({contentElPos:u,referenceElPos:l,spacing:i,align:e,justify:t})})})))&&void 0!==o?o:X[t][0]}}(o,b,w),E=function(t){var e,n,r=t.align,o=t.justify,i=W[r],a=null!==(e=i.x)&&void 0!==e?e:B[o],c=null!==(n=i.y)&&void 0!==n?n:L[o];return"".concat(a," ").concat(c)}({align:b,justify:P}),j=function(t,e){var n=.8;switch(t){case H.Top:return"translate3d(0, ".concat(e,"px, 0) scale(").concat(n,")");case H.Bottom:return"translate3d(0, -".concat(e,"px, 0) scale(").concat(n,")");case H.Left:return"translate3d(".concat(e,"px, 0, 0) scale(").concat(n,")");case H.Right:return"translate3d(-".concat(e,"px, 0, 0) scale(").concat(n,")");case H.CenterHorizontal:case H.CenterVertical:return"scale(".concat(n,")")}}(b,n);return e?{align:b,justify:P,positionCSS:g({},I({align:b,justify:P,referenceElDocumentPos:u,contentElDocumentPos:d,spacing:n}),{transformOrigin:E,transform:j})}:{align:b,justify:P,positionCSS:g({},k({align:b,justify:P,referenceElDocumentPos:u,contentElDocumentPos:d,spacing:n,windowHeight:h,windowWidth:m}),{transformOrigin:E,transform:j})}}var V={top:0,bottom:0,left:0,right:0,height:0,width:0};function R(t){if(!t)return V;var e=t.getBoundingClientRect(),n=e.top,r=e.bottom,o=e.left,i=e.right,a=t.offsetHeight,c=t.offsetWidth,u=window,l=u.scrollX,s=u.scrollY;return{top:n+s,bottom:r+s,left:o+l,right:i+l,height:a,width:c}}function F(t){if(!t)return V;var e=t.getBoundingClientRect();return{top:e.top,bottom:e.bottom,left:e.left,right:e.right,height:t.offsetHeight,width:t.offsetWidth}}var L=(f(P={},M.Start,"top"),f(P,M.Middle,"center"),f(P,M.End,"bottom"),f(P,M.Fit,"center"),P),B=(f(E={},M.Start,"left"),f(E,M.Middle,"center"),f(E,M.End,"right"),f(E,M.Fit,"center"),E),W=(f(j={},H.Left,{x:"right"}),f(j,H.Right,{x:"left"}),f(j,H.Top,{y:"bottom"}),f(j,H.Bottom,{y:"top"}),f(j,H.CenterHorizontal,{x:"center"}),f(j,H.CenterVertical,{y:"center"}),j);var z=(f(O={},M.Start,{top:0}),f(O,M.End,{bottom:0}),f(O,M.Middle,(function(t){var e=t.contentElDocumentPos,n=t.referenceElDocumentPos;return{top:"".concat(n.height/2-e.height/2,"px")}})),f(O,M.Fit,{top:0,bottom:0}),O),N=(f(S={},M.Start,{left:0}),f(S,M.End,{right:0}),f(S,M.Middle,(function(t){var e=t.contentElDocumentPos,n=t.referenceElDocumentPos;return{left:"".concat(n.width/2-e.width/2,"px")}})),f(S,M.Fit,{left:0,right:0}),S),A=(f(D={},H.Top,{constant:function(t){var e=t.spacing;return{bottom:"calc(100% + ".concat(e,"px)")}},justifyPositions:N}),f(D,H.Bottom,{constant:function(t){var e=t.spacing;return{top:"calc(100% + ".concat(e,"px)")}},justifyPositions:N}),f(D,H.CenterVertical,{constant:function(t){var e=t.referenceElDocumentPos;return{top:"calc(".concat(e.height/2,"px - 50%)")}},justifyPositions:N}),f(D,H.Left,{constant:function(t){var e=t.spacing;return{right:"calc(100% + ".concat(e,"px)")}},justifyPositions:z}),f(D,H.Right,{constant:function(t){var e=t.spacing;return{left:"calc(100% + ".concat(e,"px)")}},justifyPositions:z}),f(D,H.CenterHorizontal,{constant:function(t){var e=t.referenceElDocumentPos;return{left:"calc(".concat(e.width/2,"px - 50%)")}},justifyPositions:z}),D);function I(t){var e,n=t.align,r=t.justify,o=t.referenceElDocumentPos,i=t.contentElDocumentPos,a=t.spacing,c=A[n],u=c.justifyPositions[r],l={contentElDocumentPos:i,referenceElDocumentPos:o,spacing:a};return g({},null===(e=c.constant)||void 0===e?void 0:e.call(c,l),{},"function"==typeof u?u(l):u)}function k(t){var e=t.align,n=t.justify,r=t.referenceElDocumentPos,o=t.contentElDocumentPos,i=t.spacing,a=t.windowWidth,c=t.windowHeight,u="".concat(_({align:e,justify:n,referenceElPos:r,contentElPos:o,spacing:i}),"px"),l="".concat(q({align:e,justify:n,referenceElPos:r,contentElPos:o,spacing:i}),"px");return n!==M.Fit?{left:u,top:l}:[H.Left,H.Right,H.CenterHorizontal].includes(e)?{left:u,top:l,bottom:"".concat(c-r.bottom,"px")}:{left:u,top:l,right:"".concat(a-r.right,"px")}}function q(t){var e=t.align,n=t.justify,r=t.contentElPos,o=t.referenceElPos,i=t.spacing;switch(e){case H.Left:case H.Right:case H.CenterHorizontal:switch(n){case M.Start:case M.Fit:return o.top;case M.End:return o.top+o.height-r.height;case M.Middle:default:return o.top-(r.height-o.height)/2}case H.CenterVertical:return o.top-(r.height-o.height)/2;case H.Top:return o.top-r.height-i;case H.Bottom:default:return o.top+o.height+i}}function _(t){var e=t.align,n=t.justify,r=t.contentElPos,o=t.referenceElPos,i=t.spacing;switch(e){case H.Top:case H.Bottom:case H.CenterVertical:switch(n){case M.End:return o.left+o.width-r.width;case M.Middle:return o.left-(r.width-o.width)/2;case M.Start:case M.Fit:default:return o.left}case H.Left:return o.left-r.width-i;case H.Right:return o.left+o.width+i;case H.CenterHorizontal:default:return o.left-(r.width-o.width)/2}}function G(t){var e=t.left,n=t.windowWidth,r=t.contentWidth;return e>=0&&!(e+r>n)}function J(t){var e=t.top,n=t.windowHeight,r=t.contentHeight;return e>=0&&!(e+r>n)}var U=(f(C={},H.Top,[H.Bottom]),f(C,H.Bottom,[H.Top]),f(C,H.Left,[H.Right]),f(C,H.Right,[H.Left]),f(C,H.CenterHorizontal,[H.Left,H.Right]),f(C,H.CenterVertical,[H.Top,H.Bottom]),C);var X=(f(x={},M.Start,[M.End,M.Middle]),f(x,M.Middle,[M.End,M.Start]),f(x,M.End,[M.Start,M.Middle]),f(x,M.Fit,[M.Middle,M.Start,M.End]),x);function Y(){var t=y(["\n display: none;\n "]);return Y=function(){return t},t}function $(){var t=y(["\n transform: translate3d(0, 0, 0) scale(1);\n opacity: 1;\n position: ",";\n pointer-events: initial;\n "]);return $=function(){return t},t}function K(){var t=y(["\n transition: transform 150ms ease-in-out, opacity 150ms ease-in-out;\n position: absolute;\n opacity: 0;\n"]);return K=function(){return t},t}var Q=o.css(K()),Z={attributes:!0,characterData:!0,childList:!0,subtree:!0};function tt(t){var n=t.active,i=void 0!==n&&n,c=t.usePortal,l=void 0===c||c,p=t.spacing,g=void 0===p?10:p,y=t.align,v=void 0===y?H.Bottom:y,w=t.justify,b=void 0===w?M.Start:w,P=t.adjustOnMutation,E=void 0!==P&&P,j=t.children,O=t.className,S=t.portalClassName,D=t.refEl,C=h(t,["active","usePortal","spacing","align","justify","adjustOnMutation","children","className","portalClassName","refEl"]),x=m(e.useState(null),2),V=x[0],L=x[1],B=m(e.useState(null),2),W=B[0],z=B[1],N=m(e.useState(0),2),A=N[0],I=N[1],k=u.default.useRef(W);k.current=W;var q=null;if(D&&D.current)q=D.current;else if(V){var _=V.parentNode;_&&_ instanceof HTMLElement&&(q=_)}var G=a.useViewportSize(),J=E&&i,U=a.useMutationObserver(q,Z,e.useCallback(Date.now,[]),J),X=a.useMutationObserver(W,Z,e.useCallback(Date.now,[]),J),K=a.useObjectDependency(F(q)),tt=a.useObjectDependency(F(W)),et=a.useObjectDependency(e.useMemo((function(){return R(q)}),[q,G,U,i,v,b,A])),nt=a.useObjectDependency(e.useMemo((function(){return R(W)}),[W,G,X,i,v,b,A])),rt=a.usePrevious(b),ot=a.usePrevious(v),it=rt!==b&&(b===M.Fit||rt===M.Fit)||ot!==v&&b===M.Fit;a.useIsomorphicLayoutEffect((function(){it&&I((function(t){return t+1}))}),[it]);var at=m(e.useState(!1),2),ct=at[0],ut=at[1];if(a.useIsomorphicLayoutEffect((function(){return ut(!0)}),[]),!ct)return null;var lt,st=T({useRelativePositioning:!l,spacing:g,align:v,justify:b,referenceElViewportPos:K,referenceElDocumentPos:et,contentElViewportPos:tt,contentElDocumentPos:nt}),ft=st.align,dt=st.justify,pt=st.positionCSS,gt=o.css($(),l?"":"absolute"),ht=l?s.default:e.Fragment,yt=l?{className:S}:{};return lt=null==j?null:"function"==typeof j?j({align:ft,justify:dt,referenceElPos:et}):j,u.default.createElement(r.Transition,{nodeRef:k,in:i,timeout:{exit:150},mountOnEnter:!0,unmountOnExit:!0},(function(t){return u.default.createElement(u.default.Fragment,null,u.default.createElement("div",{ref:L,className:o.css(Y())}),u.default.createElement(ht,yt,u.default.createElement("div",d({},C,{className:o.cx(Q,o.css(pt),f({},gt,"entered"===t),O)}),u.default.createElement("div",{ref:z},lt))))}))}tt.displayName="Popover",tt.propTypes={children:l.default.oneOfType([l.default.node,l.default.func]),active:l.default.bool,className:l.default.string,align:l.default.oneOf(Object.values(H)),justify:l.default.oneOf(Object.values(M)),refEl:l.default.shape({current:"undefined"!=typeof window?l.default.instanceOf(Element):l.default.any}),usePortal:l.default.bool,portalClassName:l.default.string,spacing:l.default.number,adjustOnMutation:l.default.bool},tt.defaultProps={children:void 0,align:H.Bottom,justify:M.Start,active:!1,usePortal:!0,spacing:10,adjustOnMutation:!1},t.Align=H,t.Justify=M,t.default=tt,Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types"),require("react-transition-group"),require("@leafygreen-ui/emotion"),require("@leafygreen-ui/portal"),require("@leafygreen-ui/hooks")):"function"==typeof define&&define.amd?define(["exports","react","prop-types","react-transition-group","@leafygreen-ui/emotion","@leafygreen-ui/portal","@leafygreen-ui/hooks"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@leafygreen-ui/popover"]={},t.React,t.PropTypes,t.reactTransitionGroup,t["@leafygreen-ui/emotion"],t["@leafygreen-ui/portal"],t["@leafygreen-ui/hooks"])}(this,(function(t,e,n,r,o,i,a){"use strict";function c(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var u=c(e),s=c(n),l=c(i);function f(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function d(){return(d=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function p(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function g(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?p(Object(n),!0).forEach((function(e){f(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):p(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function h(t,e){if(null==t)return{};var n,r,o=function(t,e){if(null==t)return{};var n,r,o={},i=Object.keys(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(r=0;r<i.length;r++)n=i[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}function y(t,e){return e||(e=t.slice(0)),Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(e)}}))}function m(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var a,c=t[Symbol.iterator]();!(r=(a=c.next()).done)&&(n.push(a.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==c.return||c.return()}finally{if(o)throw i}}return n}(t,e)||w(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(t){return function(t){if(Array.isArray(t))return b(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||w(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function w(t,e){if(t){if("string"==typeof t)return b(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?b(t,e):void 0}}function b(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var P,E,j,O,S,D,x,C,H={Top:"top",Bottom:"bottom",Left:"left",Right:"right",CenterVertical:"center-vertical",CenterHorizontal:"center-horizontal"},M={Start:"start",Middle:"middle",End:"end",Fit:"fit"};function T(t){var e=t.useRelativePositioning,n=t.spacing,r=t.align,o=t.justify,i=t.referenceElViewportPos,a=void 0===i?V:i,c=t.referenceElDocumentPos,u=void 0===c?V:c,s=t.contentElViewportPos,l=void 0===s?V:s,f=t.contentElDocumentPos,d=void 0===f?V:f,p=t.windowHeight,h=void 0===p?window.innerHeight:p,y=t.windowWidth,m=void 0===y?window.innerWidth:y,w={windowWidth:m,windowHeight:h,referenceElViewportPos:a,contentElViewportPos:l,spacing:n},b=function(t,e){var n=e.spacing,r=e.windowWidth,o=e.windowHeight,i=e.contentElViewportPos,a=e.referenceElViewportPos;return[t].concat(v(U[t])).find((function(t){return[H.Top,H.Bottom,H.CenterVertical].includes(t)?J({top:k({align:t,contentElPos:i,referenceElPos:a,spacing:n}),windowHeight:o,contentHeight:i.height}):!![H.Left,H.Right,H.CenterHorizontal].includes(t)&&G({left:_({align:t,contentElPos:i,referenceElPos:a,spacing:n}),windowWidth:r,contentWidth:i.width})}))||t}(r,w),P=function(t,e,n){var r,o,i=n.spacing,a=n.windowWidth,c=n.windowHeight,u=n.contentElViewportPos,s=n.referenceElViewportPos,l=[t].concat(v(X[t]));switch(e){case H.Top:case H.Bottom:case H.CenterVertical:return null!==(r=l.find((function(t){return G({contentWidth:t===M.Fit?s.width:u.width,windowWidth:a,left:_({contentElPos:u,referenceElPos:s,spacing:i,align:e,justify:t})})})))&&void 0!==r?r:X[t][0];case H.Left:case H.Right:case H.CenterHorizontal:return null!==(o=l.find((function(t){return J({contentHeight:t===M.Fit?s.height:u.height,windowHeight:c,top:k({contentElPos:u,referenceElPos:s,spacing:i,align:e,justify:t})})})))&&void 0!==o?o:X[t][0]}}(o,b,w),E=function(t){var e,n,r=t.align,o=t.justify,i=W[r],a=null!==(e=i.x)&&void 0!==e?e:B[o],c=null!==(n=i.y)&&void 0!==n?n:L[o];return"".concat(a," ").concat(c)}({align:b,justify:P}),j=function(t,e){var n=.8;switch(t){case H.Top:return"translate3d(0, ".concat(e,"px, 0) scale(").concat(n,")");case H.Bottom:return"translate3d(0, -".concat(e,"px, 0) scale(").concat(n,")");case H.Left:return"translate3d(".concat(e,"px, 0, 0) scale(").concat(n,")");case H.Right:return"translate3d(-".concat(e,"px, 0, 0) scale(").concat(n,")");case H.CenterHorizontal:case H.CenterVertical:return"scale(".concat(n,")")}}(b,n);return e?{align:b,justify:P,positionCSS:g({},I({align:b,justify:P,referenceElDocumentPos:u,contentElDocumentPos:d,spacing:n}),{transformOrigin:E,transform:j})}:{align:b,justify:P,positionCSS:g({},q({align:b,justify:P,referenceElDocumentPos:u,contentElDocumentPos:d,spacing:n,windowHeight:h,windowWidth:m}),{transformOrigin:E,transform:j})}}var V={top:0,bottom:0,left:0,right:0,height:0,width:0};function R(t){if(!t)return V;var e=t.getBoundingClientRect(),n=e.top,r=e.bottom,o=e.left,i=e.right,a=t.offsetHeight,c=t.offsetWidth,u=window,s=u.scrollX,l=u.scrollY;return{top:n+l,bottom:r+l,left:o+s,right:i+s,height:a,width:c}}function F(t){if(!t)return V;var e=t.getBoundingClientRect();return{top:e.top,bottom:e.bottom,left:e.left,right:e.right,height:t.offsetHeight,width:t.offsetWidth}}var L=(f(P={},M.Start,"top"),f(P,M.Middle,"center"),f(P,M.End,"bottom"),f(P,M.Fit,"center"),P),B=(f(E={},M.Start,"left"),f(E,M.Middle,"center"),f(E,M.End,"right"),f(E,M.Fit,"center"),E),W=(f(j={},H.Left,{x:"right"}),f(j,H.Right,{x:"left"}),f(j,H.Top,{y:"bottom"}),f(j,H.Bottom,{y:"top"}),f(j,H.CenterHorizontal,{x:"center"}),f(j,H.CenterVertical,{y:"center"}),j);var z=(f(O={},M.Start,{top:0}),f(O,M.End,{bottom:0}),f(O,M.Middle,(function(t){var e=t.contentElDocumentPos,n=t.referenceElDocumentPos;return{top:"".concat(n.height/2-e.height/2,"px")}})),f(O,M.Fit,{top:0,bottom:0}),O),N=(f(S={},M.Start,{left:0}),f(S,M.End,{right:0}),f(S,M.Middle,(function(t){var e=t.contentElDocumentPos,n=t.referenceElDocumentPos;return{left:"".concat(n.width/2-e.width/2,"px")}})),f(S,M.Fit,{left:0,right:0}),S),A=(f(D={},H.Top,{constant:function(t){var e=t.spacing;return{bottom:"calc(100% + ".concat(e,"px)")}},justifyPositions:N}),f(D,H.Bottom,{constant:function(t){var e=t.spacing;return{top:"calc(100% + ".concat(e,"px)")}},justifyPositions:N}),f(D,H.CenterVertical,{constant:function(t){var e=t.referenceElDocumentPos;return{top:"calc(".concat(e.height/2,"px - 50%)")}},justifyPositions:N}),f(D,H.Left,{constant:function(t){var e=t.spacing;return{right:"calc(100% + ".concat(e,"px)")}},justifyPositions:z}),f(D,H.Right,{constant:function(t){var e=t.spacing;return{left:"calc(100% + ".concat(e,"px)")}},justifyPositions:z}),f(D,H.CenterHorizontal,{constant:function(t){var e=t.referenceElDocumentPos;return{left:"calc(".concat(e.width/2,"px - 50%)")}},justifyPositions:z}),D);function I(t){var e,n=t.align,r=t.justify,o=t.referenceElDocumentPos,i=t.contentElDocumentPos,a=t.spacing,c=A[n],u=c.justifyPositions[r],s={contentElDocumentPos:i,referenceElDocumentPos:o,spacing:a};return g({},null===(e=c.constant)||void 0===e?void 0:e.call(c,s),{},"function"==typeof u?u(s):u)}function q(t){var e=t.align,n=t.justify,r=t.referenceElDocumentPos,o=t.contentElDocumentPos,i=t.spacing,a=t.windowWidth,c=t.windowHeight,u="".concat(_({align:e,justify:n,referenceElPos:r,contentElPos:o,spacing:i}),"px"),s="".concat(k({align:e,justify:n,referenceElPos:r,contentElPos:o,spacing:i}),"px");return n!==M.Fit?{left:u,top:s}:[H.Left,H.Right,H.CenterHorizontal].includes(e)?{left:u,top:s,bottom:"".concat(c-r.bottom,"px")}:{left:u,top:s,right:"".concat(a-r.right,"px")}}function k(t){var e=t.align,n=t.justify,r=t.contentElPos,o=t.referenceElPos,i=t.spacing;switch(e){case H.Left:case H.Right:case H.CenterHorizontal:switch(n){case M.Start:case M.Fit:return o.top;case M.End:return o.top+o.height-r.height;case M.Middle:default:return o.top-(r.height-o.height)/2}case H.CenterVertical:return o.top-(r.height-o.height)/2;case H.Top:return o.top-r.height-i;case H.Bottom:default:return o.top+o.height+i}}function _(t){var e=t.align,n=t.justify,r=t.contentElPos,o=t.referenceElPos,i=t.spacing;switch(e){case H.Top:case H.Bottom:case H.CenterVertical:switch(n){case M.End:return o.left+o.width-r.width;case M.Middle:return o.left-(r.width-o.width)/2;case M.Start:case M.Fit:default:return o.left}case H.Left:return o.left-r.width-i;case H.Right:return o.left+o.width+i;case H.CenterHorizontal:default:return o.left-(r.width-o.width)/2}}function G(t){var e=t.left,n=t.windowWidth,r=t.contentWidth;return e>=0&&!(e+r>n)}function J(t){var e=t.top,n=t.windowHeight,r=t.contentHeight;return e>=0&&!(e+r>n)}var U=(f(x={},H.Top,[H.Bottom]),f(x,H.Bottom,[H.Top]),f(x,H.Left,[H.Right]),f(x,H.Right,[H.Left]),f(x,H.CenterHorizontal,[H.Left,H.Right]),f(x,H.CenterVertical,[H.Top,H.Bottom]),x);var X=(f(C={},M.Start,[M.End,M.Middle]),f(C,M.Middle,[M.End,M.Start]),f(C,M.End,[M.Start,M.Middle]),f(C,M.Fit,[M.Middle,M.Start,M.End]),C);function Y(){var t=y(["\n display: none;\n "]);return Y=function(){return t},t}function $(){var t=y(["\n opacity: 1;\n position: ",";\n pointer-events: initial;\n "]);return $=function(){return t},t}function K(){var t=y(["\n position: absolute;\n transition: transform 150ms ease-in-out, opacity 150ms ease-in-out;\n transform: translate3d(0, 0, 0) scale(1);\n opacity: 0;\n"]);return K=function(){return t},t}var Q=o.css(K()),Z={attributes:!0,characterData:!0,childList:!0,subtree:!0};function tt(t){var n=t.active,i=void 0!==n&&n,c=t.usePortal,s=void 0===c||c,p=t.spacing,g=void 0===p?10:p,y=t.align,v=void 0===y?H.Bottom:y,w=t.justify,b=void 0===w?M.Start:w,P=t.adjustOnMutation,E=void 0!==P&&P,j=t.children,O=t.className,S=t.portalClassName,D=t.refEl,x=h(t,["active","usePortal","spacing","align","justify","adjustOnMutation","children","className","portalClassName","refEl"]),C=m(e.useState(null),2),V=C[0],L=C[1],B=m(e.useState(null),2),W=B[0],z=B[1],N=m(e.useState(0),2),A=N[0],I=N[1],q=u.default.useRef(W);q.current=W;var k=null;if(D&&D.current)k=D.current;else if(V){var _=V.parentNode;_&&_ instanceof HTMLElement&&(k=_)}var G=a.useViewportSize(),J=E&&i,U=a.useMutationObserver(k,Z,Date.now,J),X=a.useMutationObserver(W,Z,Date.now,J),K=a.useObjectDependency(F(k)),tt=a.useObjectDependency(F(W)),et=a.useObjectDependency(e.useMemo((function(){return R(k)}),[k,G,U,i,v,b,A])),nt=a.useObjectDependency(e.useMemo((function(){return R(W)}),[W,G,X,i,v,b,A])),rt=a.usePrevious(b),ot=a.usePrevious(v),it=rt!==b&&(b===M.Fit||rt===M.Fit)||ot!==v&&b===M.Fit;a.useIsomorphicLayoutEffect((function(){it&&I((function(t){return t+1}))}),[it]);var at=m(e.useState(!1),2),ct=at[0],ut=at[1];if(a.useIsomorphicLayoutEffect((function(){return ut(!0)}),[]),!ct)return null;var st,lt=T({useRelativePositioning:!s,spacing:g,align:v,justify:b,referenceElViewportPos:K,referenceElDocumentPos:et,contentElViewportPos:tt,contentElDocumentPos:nt}),ft=lt.align,dt=lt.justify,pt=lt.positionCSS,gt=pt.transform,ht=h(pt,["transform"]),yt=o.css($(),s?"":"absolute"),mt=s?l.default:e.Fragment,vt=s?{className:S}:{};return st=null==j?null:"function"==typeof j?j({align:ft,justify:dt,referenceElPos:et}):j,u.default.createElement(r.Transition,{nodeRef:q,in:i,timeout:150,mountOnEnter:!0,unmountOnExit:!0,appear:!0},(function(t){var e;return u.default.createElement(u.default.Fragment,null,u.default.createElement("div",{ref:L,className:o.css(Y())}),u.default.createElement(mt,vt,u.default.createElement("div",d({},x,{className:o.cx(Q,o.css(ht),(e={},f(e,o.css({transform:gt}),"entering"===t||"exiting"===t),f(e,yt,"entered"===t),e),O)}),u.default.createElement("div",{ref:z},st))))}))}tt.displayName="Popover",tt.propTypes={children:s.default.oneOfType([s.default.node,s.default.func]),active:s.default.bool,className:s.default.string,align:s.default.oneOf(Object.values(H)),justify:s.default.oneOf(Object.values(M)),refEl:s.default.shape({current:"undefined"!=typeof window?s.default.instanceOf(Element):s.default.any}),usePortal:s.default.bool,portalClassName:s.default.string,spacing:s.default.number,adjustOnMutation:s.default.bool},tt.defaultProps={children:void 0,align:H.Bottom,justify:M.Start,active:!1,usePortal:!0,spacing:10,adjustOnMutation:!1},t.Align=H,t.Justify=M,t.default=tt,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=index.js.map
{
"name": "@leafygreen-ui/popover",
"version": "7.1.0",
"version": "7.1.1",
"description": "LeafyGreen UI Kit Popover",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

@@ -73,3 +73,3 @@ # Popover

| `onClick` | `function` | Function that will be called when popover content is clicked. | |
| ... | | Any other properties will be spread on the popover-content container | |
| ... | native attributes of Portal or Fragment | Any other properties will be spread on the popover-content container | |

@@ -76,0 +76,0 @@ ## Advanced Use Case

@@ -363,5 +363,7 @@ import { Align, Justify, ElementPosition } from './types';

if (
([Align.Left, Align.Right, Align.CenterHorizontal] as Array<
Align
>).includes(align)
([
Align.Left,
Align.Right,
Align.CenterHorizontal,
] as Array<Align>).includes(align)
) {

@@ -541,5 +543,7 @@ return {

if (
([Align.Top, Align.Bottom, Align.CenterVertical] as Array<
Align
>).includes(fallback)
([
Align.Top,
Align.Bottom,
Align.CenterVertical,
] as Array<Align>).includes(fallback)
) {

@@ -561,5 +565,7 @@ const top = calcTop({

if (
([Align.Left, Align.Right, Align.CenterHorizontal] as Array<
Align
>).includes(fallback)
([
Align.Left,
Align.Right,
Align.CenterHorizontal,
] as Array<Align>).includes(fallback)
) {

@@ -566,0 +572,0 @@ const left = calcLeft({

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc