UNPKG

@zag-js/popper

Version:

Dynamic positioning logic for ui machines

49 lines (48 loc) 1.59 kB
// src/get-styles.ts import { cssVars } from "./middleware.mjs"; var ARROW_FLOATING_STYLE = { bottom: "rotate(45deg)", left: "rotate(135deg)", top: "rotate(225deg)", right: "rotate(315deg)" }; function getPlacementStyles(options = {}) { const { placement, sameWidth, fitViewport, strategy = "absolute" } = options; return { arrow: { position: "absolute", width: cssVars.arrowSize.reference, height: cssVars.arrowSize.reference, [cssVars.arrowSizeHalf.variable]: `calc(${cssVars.arrowSize.reference} / 2)`, [cssVars.arrowOffset.variable]: `calc(${cssVars.arrowSizeHalf.reference} * -1)` }, arrowTip: { // @ts-expect-error - Fix this transform: placement ? ARROW_FLOATING_STYLE[placement.split("-")[0]] : void 0, background: cssVars.arrowBg.reference, top: "0", left: "0", width: "100%", height: "100%", position: "absolute", zIndex: "inherit" }, floating: { position: strategy, isolation: "isolate", minWidth: sameWidth ? void 0 : "max-content", width: sameWidth ? "var(--reference-width)" : void 0, maxWidth: fitViewport ? "var(--available-width)" : void 0, maxHeight: fitViewport ? "var(--available-height)" : void 0, pointerEvents: !placement ? "none" : void 0, top: "0px", left: "0px", // move off-screen if placement is not defined transform: placement ? "translate3d(var(--x), var(--y), 0)" : "translate3d(0, -100vh, 0)", zIndex: "var(--z-index)" } }; } export { getPlacementStyles };