Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@filerobot/common / lib / Transitions / TransitionWrapper.js
Size: Mime:
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { useEffect, useRef, useState } from 'react';
import { BackdropOverlay } from '..';

// transitionClass = the class name that has the animation
// it must have -enter, -enter-active, -leave, -leave-active sub classes
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var TransitionWrapper = function TransitionWrapper(_ref) {
  var children = _ref.children,
    transitionClass = _ref.transitionClass,
    transitionTimeoutInMS = _ref.transitionTimeoutInMS,
    zIndex = _ref.zIndex,
    handleClose = _ref.handleClose,
    viewReset = _ref.viewReset,
    transitionStyle = _ref.transitionStyle;
  var _useState = useState(children || null),
    _useState2 = _slicedToArray(_useState, 2),
    oldChildren = _useState2[0],
    setOldChildren = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    isApplied = _useState4[0],
    setIsApplied = _useState4[1];
  var wrapperRef = useRef(null);
  useEffect(function () {
    if (wrapperRef && wrapperRef !== null && wrapperRef !== void 0 && wrapperRef.current) {
      var isChildrenArray = Array.isArray(children);
      var hasChildren = children && (isChildrenArray && children.filter(function (child) {
        return child;
      }).length > 0 || !isChildrenArray);
      if (hasChildren) {
        setTimeout(function () {
          if (typeof viewReset === 'function' && !isApplied) {
            viewReset(true);
          }
          if (wrapperRef.current) {
            wrapperRef.current.classList.add("".concat(transitionClass, "-enter-active"));
          }
        }, 0);
        setIsApplied(true);
        setOldChildren(children);
      } else if (isApplied) {
        setTimeout(function () {
          if (wrapperRef.current) {
            wrapperRef.current.classList.add("".concat(transitionClass, "-leave-active"));
          }
          setTimeout(function () {
            if (wrapperRef.current) {
              wrapperRef.current.classList.remove('--applied');
            }
            setOldChildren(null);
          }, transitionTimeoutInMS + 1);
        }, 0);
        setIsApplied(true);
      }
    }
  }, [children]);
  var transitionClasses = children ? " --applied ".concat(transitionClass, "-enter") : isApplied ? " --applied ".concat(transitionClass, "-leave") : '';
  var renderedChildren = oldChildren || children;
  return /*#__PURE__*/_jsxs("div", {
    style: {
      zIndex: zIndex
    },
    children: [isApplied && renderedChildren && /*#__PURE__*/_jsx(BackdropOverlay, {
      onClick: handleClose,
      zIndex: -1,
      acceptScroll: true,
      floatyColored: true
    }), /*#__PURE__*/_jsx("div", {
      className: "filerobot-TransitionWrapper".concat(transitionClasses),
      ref: wrapperRef,
      style: transitionStyle,
      children: renderedChildren
    })]
  });
};
export default TransitionWrapper;