UNPKG

@styleless-ui/react

Version:

Completely unstyled, headless and accessible React UI components.

1 lines 3.32 kB
var e=this&&this.__assign||function(){return e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},e.apply(this,arguments)},t=this&&this.__rest||function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n};import{jsx as n}from"react/jsx-runtime";import*as r from"react";import o from"../Portal";import{componentWithForwardedRef as i,useDeterministicId as a,useDirection as l,useForkedRefs as c,useIsomorphicLayoutEffect as s,useRegisterNodeRef as u}from"../utils";import{computePosition as d}from"./helpers";import*as p from"./slots";var f=function(e){var t=e.x,n=e.y,r="undefined"!=typeof window?window.devicePixelRatio:1,o={x:Math.round(Math.round(t*r)/r),y:Math.round(Math.round(n*r)/r)},i=o.y,a="translate(".concat(o.x,"px, ").concat(i,"px)");return{transform:a,WebkitTransform:a,MozTransform:a,msTransform:a}},m=function(e){return"string"==typeof e?"undefined"!=typeof document?document.querySelector(e):null:"current"in e?e.current:e},y=i((function(i,y){var h=i.open,v=i.actions,b=i.style,g=i.id,w=i.className,x=i.children,M=i.computationMiddleware,O=i.anchorElement,P=i.offset,j=void 0===P?8:P,E=i.side,R=void 0===E?"top":E,S=i.keepMounted,T=void 0!==S&&S,I=i.autoPlacement,_=void 0!==I&&I,H=i.alignment,k=void 0===H?"middle":H,L=i.positioningStrategy,N=void 0===L?"absolute":L,q=i.computationMiddlewareOrder,A=void 0===q?"afterAutoPlacement":q,C=t(i,["open","actions","style","id","className","children","computationMiddleware","anchorElement","offset","side","keepMounted","autoPlacement","alignment","positioningStrategy","computationMiddlewareOrder"]);if(!O)throw new Error(["[StylelessUI][Popper]: Invalid `anchorElement` property.","The `anchorElement` property must be either a `query selector (string)`, `HTMLElement`, `RefObject<HTMLElement>`, or in shape of `{ getBoundingClientRect(): ClientRect }`"].join("\n"));var z="rtl"===l(),B=a(g,"styleless-ui__popper"),U=r.useRef(null),W=c(y,U),D=r.useState({x:0,y:0}),F=D[0],G=D[1],J=r.useRef("middle"===k?R:"".concat(R,"-").concat(k)).current,K=r.useState(J),Q=K[0],V=K[1],X={computationMiddleware:M,computationMiddlewareOrder:A,placement:J,autoPlacement:_,offset:j,strategy:N,isRtl:z},Y=function(){var e=m(O);if(e&&U.current){var t=d(e,U.current,X);return V(t.placement),G({x:t.x,y:t.y}),!0}return!1};r.useImperativeHandle(v,(function(){return{recompute:function(){Y()}}})),s((function(){var e=m(O);e&&B&&e instanceof HTMLElement&&e.setAttribute("aria-describedby",B)}));var Z={placement:Q,openState:h},$="function"==typeof x?x(Z):x,ee="function"==typeof w?w(Z):w,te=u((function(e){W(e),Y()}),[]);return T||!T&&h?n(o,{children:n("div",e({"data-slot":"Portal:Root",role:"presentation",tabIndex:-1,"aria-hidden":!h,style:{position:"absolute",top:0,left:0,right:0}},{children:n("div",e({},C,{tabIndex:-1,"data-slot":p.Root,id:B,className:ee,ref:te,style:e(e(e({},null!=b?b:{}),f(F)),{position:N,left:0,top:0}),"data-open":h?"":void 0},{children:$}))}))}):null}));export default y;