@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.
44 lines (42 loc) • 1.22 kB
JavaScript
"use client";
import React from "react";
import cx from "clsx";
import { Provider as SectionProvider } from "./AccordionContext";
import { spaceAfterClasses } from "../common/tailwind";
const Accordion = ({
children,
dataTest,
id,
spaceAfter,
expandedSection,
loading,
loadingTitle,
loadingHidden,
onExpand
}) => /*#__PURE__*/React.createElement("div", {
className: cx("orbit-accordion font-base relative w-full", spaceAfter && spaceAfterClasses[spaceAfter]),
id: id,
"data-test": dataTest
}, children ? React.Children.map(children, item => {
if (!item) return null;
// @ts-expect-error TODO
const {
id: innerId
} = item.props;
// Determine if section is expanded
const isExpanded = expandedSection === innerId;
// Callback with section id
// onExpand is not required prop to have easier loading use case
const handleExpand = () => onExpand && onExpand(innerId);
return /*#__PURE__*/React.createElement(SectionProvider, {
value: {
expanded: isExpanded,
onExpand: handleExpand,
loading,
loadingTitle,
loadingHidden
}
}, item);
}) : null);
export default Accordion;
export { default as AccordionSection } from "./AccordionSection";