UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

75 lines (74 loc) 3.19 kB
"use strict"; "use client"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _classnames = _interopRequireDefault(require("classnames")); var _useHeightAnimation = require("./useHeightAnimation.js"); var _Space = _interopRequireDefault(require("../space/Space.js")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function HeightAnimation({ open = true, animate = true, keepInDOM = false, showOverflow = false, element, duration, delay, className, innerRef, children, compensateForGap, onInit = null, onOpen = null, onAnimationStart = null, onAnimationEnd = null, ...rest }) { const elementRef = (0, _react.useRef)(); const targetRef = innerRef || elementRef; const { isInDOM, isVisible, isVisibleParallax, isAnimating, firstPaintStyle } = (0, _useHeightAnimation.useHeightAnimation)(targetRef, { open, animate, children, compensateForGap, onInit, onOpen, onAnimationStart, onAnimationEnd }); if (!keepInDOM && !isInDOM && !isAnimating) { return null; } if (duration) { firstPaintStyle['--duration'] = `${duration}ms`; } if (delay) { firstPaintStyle['--delay'] = `${delay}ms`; } return _react.default.createElement(_Space.default, _extends({ innerRef: targetRef, element: element || 'div', className: (0, _classnames.default)('dnb-height-animation', className, isVisible ? 'dnb-height-animation--is-visible' : !isAnimating && !open && 'dnb-height-animation--hidden', isInDOM && 'dnb-height-animation--is-in-dom', animate && isVisibleParallax && 'dnb-height-animation--parallax', isAnimating && 'dnb-height-animation--animating', showOverflow && 'dnb-height-animation--show-overflow'), style: { ...firstPaintStyle, ...(rest === null || rest === void 0 ? void 0 : rest.style) }, "aria-hidden": keepInDOM ? !open : undefined }, rest), compensateForGap ? _react.default.createElement("div", { className: "compensateForGap" }, children) : children); } HeightAnimation._supportsSpacingProps = 'children'; var _default = exports.default = HeightAnimation; //# sourceMappingURL=HeightAnimation.js.map