@kiwicom/orbit-components
Version:
Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.
58 lines (56 loc) • 1.73 kB
JavaScript
import * as React from "react";
import { useAccordion } from "../AccordionContext";
import useRandomId from "../../hooks/useRandomId";
import useBoundingRect from "../../hooks/useBoundingRect";
import Slide from "../../utils/Slide";
import Loading from "../../Loading";
import AccordionWrapper from "../components/AccordionWrapper";
import SectionHeader from "./components/SectionHeader";
import SectionFooter from "./components/SectionFooter";
import SectionContent from "./components/SectionContent";
const AccordionSection = ({
children,
header,
footer,
actions,
dataTest,
expandable = true
}) => {
const {
expanded,
onExpand,
loading
} = useAccordion();
const slideId = useRandomId();
const isExpanded = expandable && expanded;
const [{
height
}, ref] = useBoundingRect({
height: isExpanded ? null : 0
});
return /*#__PURE__*/React.createElement(AccordionWrapper, {
dataTest: dataTest
}, /*#__PURE__*/React.createElement(Loading, {
loading: loading,
type: "boxLoader",
dataTest: dataTest && `${dataTest}Loading`
}, header && /*#__PURE__*/React.createElement(SectionHeader, {
actions: actions,
expanded: Boolean(isExpanded),
onExpand: onExpand,
expandable: expandable,
dataTest: dataTest
}, header), /*#__PURE__*/React.createElement(Slide, {
maxHeight: height,
expanded: isExpanded,
id: slideId,
ariaLabelledBy: slideId
}, /*#__PURE__*/React.createElement("div", {
ref: ref
}, children && /*#__PURE__*/React.createElement(SectionContent, {
dataTest: dataTest
}, children), footer && /*#__PURE__*/React.createElement(SectionFooter, {
dataTest: dataTest
}, footer)))));
};
export default AccordionSection;