UNPKG

@momentum-ui/react-collaboration

Version:

Cisco Momentum UI Framework for React Collaboration Applications

85 lines 3.63 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; import React, { useMemo } from 'react'; import Tippy from '@tippyjs/react'; /** * The LazyTippy component is used to "lazify" the Popover. * By default the `tippy.js` library mounts the content of the Popover in the DOM (hidden through styling), before it is shown * (which means that it could, if its used a lot, polute the DOM tree). Therefore the Popover has to be * lazified so that it will only be mounted to the DOM, whenever it is triggered to do so. */ export var LazyTippy = React.forwardRef(function (_a, ref) { var setInstance = _a.setInstance, continuePropagationOnTrigger = _a.continuePropagationOnTrigger, props = __rest(_a, ["setInstance", "continuePropagationOnTrigger"]); var _b = React.useState(false), mounted = _b[0], setMounted = _b[1]; var stopPropagationPlugin = { fn: function () { return ({ onTrigger: function (instance, event) { if (!continuePropagationOnTrigger) { event.stopPropagation(); } }, }); }, }; var lazyPlugin = { fn: function () { return ({ onMount: function () { return setMounted(true); }, onHidden: function () { return setMounted(false); }, }); }, }; var instancePlugin = useMemo(function () { return ({ fn: function (instance) { return ({ onCreate: function () { return setInstance === null || setInstance === void 0 ? void 0 : setInstance(instance); }, onDestroy: function () { return setInstance === null || setInstance === void 0 ? void 0 : setInstance(undefined); }, }); }, }); }, []); var computedProps = __assign({}, props); computedProps.plugins = __spreadArray([ instancePlugin, lazyPlugin, stopPropagationPlugin ], (props.plugins || []), true); if (props.render) { computedProps.render = function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return (mounted ? props.render.apply(props, args) : ''); }; } else { computedProps.content = mounted ? props.content : ''; } return React.createElement(Tippy, __assign({ ref: ref }, computedProps)); }); LazyTippy.displayName = 'LazyTippy'; //# sourceMappingURL=LazyTippy.js.map