UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

81 lines (80 loc) 3.1 kB
"use strict"; "use client"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _withComponentMarkers = _interopRequireDefault(require("../../shared/helpers/withComponentMarkers.js")); var _react = _interopRequireWildcard(require("react")); var _clsx = _interopRequireDefault(require("clsx")); var _useHeightAnimation = require("./useHeightAnimation.js"); var _Space = _interopRequireDefault(require("../space/Space.js")); var _jsxRuntime = require("react/jsx-runtime"); 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 _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function HeightAnimation({ open = true, animate = true, keepInDOM = false, showOverflow = false, element, duration, delay, className, ref, children, compensateForGap, onInit = null, onOpen = null, onAnimationStart = null, onAnimationEnd = null, ...rest }) { const elementRef = (0, _react.useRef)(undefined); const targetRef = ref || 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 (0, _jsxRuntime.jsx)(_Space.default, { ref: targetRef, element: element || 'div', className: (0, _clsx.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, children: compensateForGap ? (0, _jsxRuntime.jsx)("div", { className: "compensateForGap", children: children }) : children }); } (0, _withComponentMarkers.default)(HeightAnimation, { _supportsSpacingProps: 'children' }); var _default = exports.default = HeightAnimation; //# sourceMappingURL=HeightAnimation.js.map