UNPKG

@dialpad/dialtone

Version:

Dialpad's Dialtone design system monorepo

95 lines (94 loc) 2.51 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const tippy = require("tippy.js"); const BASE_TIPPY_DIRECTIONS = [ "bottom", "bottom-start", "bottom-end", "right", "right-start", "right-end", "left", "left-start", "left-end", "top", "top-start", "top-end" ]; const TIPPY_STICKY_VALUES = [true, false, "reference", "popper"]; const createTippyPopover = (anchorElement, options) => { const { contentElement } = { ...options }; delete options.contentElement; return tippy(anchorElement, { ...options, plugins: [tippy.sticky], render: () => getContentWrapper(contentElement) }); }; const createTippy = (anchorElement, options) => { return tippy(anchorElement, { ...options, plugins: [tippy.sticky] }); }; const getPopperOptions = ({ boundary = "clippingParents", fallbackPlacements = [], onChangePlacement = () => { }, hasHideModifierEnabled = false, // If set to false the dialog will display over top of the anchor when there is insufficient space. // if set to true it will never move from its position relative to the anchor and will clip instead. tether = true } = {}) => { return { modifiers: [ { name: "flip", options: { fallbackPlacements, boundary } }, { name: "hide", enabled: hasHideModifierEnabled }, { name: "preventOverflow", options: { altAxis: !tether, tether } } ] }; }; const createAnchor = (anchorWrapper) => { const span = document.createElement("span"); span.innerText = anchorWrapper.innerText || ""; anchorWrapper.innerText = ""; anchorWrapper.appendChild(span); return span; }; const getAnchor = (anchorWrapper) => { const anchor = anchorWrapper == null ? void 0 : anchorWrapper.children[0]; if (!anchor) return createAnchor(anchorWrapper); return anchor; }; const getContentWrapper = (content) => { const popper = document.createElement("div"); popper.className = "tippy-box d-ps-absolute"; popper.appendChild(content); return { popper }; }; exports.BASE_TIPPY_DIRECTIONS = BASE_TIPPY_DIRECTIONS; exports.TIPPY_STICKY_VALUES = TIPPY_STICKY_VALUES; exports.createTippy = createTippy; exports.createTippyPopover = createTippyPopover; exports.getAnchor = getAnchor; exports.getContentWrapper = getContentWrapper; exports.getPopperOptions = getPopperOptions; //# sourceMappingURL=tippy_utils.cjs.map