UNPKG

@ebay/ui-core-react

Version:

Skin components build off React

2 lines (1 loc) 1.74 kB
"use strict";const w=require("react"),l=require("@floating-ui/react");function F({open:i,options:e}){var t;const{floatingStyles:a,refs:r}=l.useFloating({placement:e?.reverse?"bottom-end":"bottom-start",strategy:e?.strategy,open:i,middleware:[l.offset((t=e?.offset)!==null&&t!==void 0?t:4),l.flip(),l.shift()],whileElementsMounted:l.autoUpdate});return{overlayStyles:i?a:void 0,refs:{host:r.reference,overlay:r.floating,setHost:r.setReference,setOverlay:r.setFloating}}}const S={left:"right","left-top":"right-start","left-bottom":"right-end",right:"left","right-top":"left-start","right-bottom":"left-end",top:"bottom","top-left":"bottom-start","top-right":"bottom-end",bottom:"top","bottom-left":"top-start","bottom-right":"top-end"};function _({open:i,hostRef:e,options:t}){var a,r,d,f;const u=w.useRef(null),g=(a=t?.placement)!==null&&a!==void 0?a:S[(r=t?.pointer)!==null&&r!==void 0?r:"bottom"],m=[l.offset((d=t?.offset)!==null&&d!==void 0?d:6),!t?.notInline&&l.inline(),!t?.noFlip&&l.flip({fallbackAxisSideDirection:"end",flipAlignment:!1}),!t?.noShift&&l.shift(),l.arrow({element:u,padding:20})].filter(Boolean),{floatingStyles:b,refs:n,middlewareData:v,placement:h}=l.useFloating({placement:g,strategy:(f=t?.strategy)!==null&&f!==void 0?f:"absolute",open:i,middleware:m,whileElementsMounted:l.autoUpdate,elements:{reference:e?.current}}),o={};if(v.arrow){const{x:s,y:c}=v.arrow,y={top:"bottom",right:"left",bottom:"top",left:"right"}[h.split("-")[0]];o.left=s!=null?`${s}px`:"",o.top=c!=null?`${c}px`:"",o.right="",o.bottom="",o[y]="-4px"}return{overlayStyles:b,arrowStyles:o,refs:{host:n.reference,overlay:n.floating,arrow:u,setHost:n.setReference,setOverlay:n.setFloating}}}exports.useFloatingDropdown=F;exports.useFloatingTooltip=_;