UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

73 lines (72 loc) 3.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; exports.useTableAnimationHandler = useTableAnimationHandler; require("core-js/modules/web.dom-collections.iterator.js"); var _react = _interopRequireWildcard(require("react")); var _componentHelper = require("../../../shared/component-helper"); var _useHeightAnimation = require("../../height-animation/useHeightAnimation"); var _TableAccordionContext = require("./TableAccordionContext"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function useTableAnimationHandler(_ref) { let { innerRef, trRef, expanded, noAnimation } = _ref; const tableAccordionContext = _react.default.useContext(_TableAccordionContext.TableAccordionContext); const [ariaLive, setAriaLive] = _react.default.useState(null); const open = Boolean(expanded || (tableAccordionContext === null || tableAccordionContext === void 0 ? void 0 : tableAccordionContext.trIsOpen)); const scrollViewHandler = (0, _react.useCallback)(clip => { const scrollView = (0, _componentHelper.getClosestScrollViewElement)(trRef.current); if (scrollView instanceof HTMLElement) { scrollView.style.overflowY = clip ? 'clip' : ''; } }, [trRef]); const onOpen = (0, _react.useCallback)(state => { setAriaLive(state ? true : null); }, []); const onAnimationStart = (0, _react.useCallback)(() => { scrollViewHandler(true); }, [scrollViewHandler]); const onAnimationEnd = (0, _react.useCallback)(state => { var _tableAccordionContex, _tableAccordionContex2; const event = { target: trRef.current }; switch (state) { case 'opened': (_tableAccordionContex = tableAccordionContext.onOpened) === null || _tableAccordionContex === void 0 ? void 0 : _tableAccordionContex.call(tableAccordionContext, event); break; case 'closed': (_tableAccordionContex2 = tableAccordionContext.onClosed) === null || _tableAccordionContex2 === void 0 ? void 0 : _tableAccordionContex2.call(tableAccordionContext, event); break; } scrollViewHandler(false); }, [scrollViewHandler, tableAccordionContext, trRef]); const { isInDOM, isAnimating, isVisibleParallax, firstPaintStyle } = (0, _useHeightAnimation.useHeightAnimation)(innerRef, { open, animate: Boolean(!noAnimation && !(tableAccordionContext !== null && tableAccordionContext !== void 0 && tableAccordionContext.noAnimation)), onOpen, onAnimationStart, onAnimationEnd }); return { ariaLive, isInDOM, isAnimating, isVisibleParallax, firstPaintStyle }; } var _default = exports.default = useTableAnimationHandler; //# sourceMappingURL=useTableAnimationHandler.js.map