UNPKG

@littlespoon/accordion

Version:
51 lines 2.48 kB
"use strict"; 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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AccordionDetails = void 0; var jsx_runtime_1 = require("react/jsx-runtime"); var react_1 = require("react"); var styled_1 = require("./styled"); function AccordionDetails(_a) { var children = _a.children, _b = _a.isExpanded, isExpanded = _b === void 0 ? false : _b, className = _a.className; var resizeObserver = (0, react_1.useRef)(); var _c = (0, react_1.useState)(0), innerContentHeight = _c[0], setInnerContentHeight = _c[1]; var contentRef = (0, react_1.useRef)(null); /* istanbul ignore next */ (0, react_1.useEffect)(function () { var _a, _b; // for OS that lack ResizeObserver support use fallback when undefined if ('ResizeObserver' in window) { // create the observer only once resizeObserver.current = new ResizeObserver(function () { if (contentRef.current) { setInnerContentHeight(contentRef.current.scrollHeight); } }); if (contentRef.current) { resizeObserver.current.observe(contentRef.current); } return function () { var _a; (_a = resizeObserver.current) === null || _a === void 0 ? void 0 : _a.disconnect(); }; } else { if ((_a = contentRef === null || contentRef === void 0 ? void 0 : contentRef.current) === null || _a === void 0 ? void 0 : _a.scrollHeight) { setInnerContentHeight((_b = contentRef === null || contentRef === void 0 ? void 0 : contentRef.current) === null || _b === void 0 ? void 0 : _b.scrollHeight); } } }, []); return ((0, jsx_runtime_1.jsx)(styled_1.ContentWrapper, __assign({ isExpanded: isExpanded, className: className, expandedHeight: innerContentHeight }, { children: (0, jsx_runtime_1.jsx)(styled_1.Content, __assign({ ref: contentRef }, { children: children })) }))); } exports.AccordionDetails = AccordionDetails; //# sourceMappingURL=AccordionDetails.js.map