@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.
50 lines (44 loc) • 1.78 kB
JavaScript
import * as React from "react";
import styled from "styled-components";
import defaultTheme from "../defaultTheme";
import { Provider as SectionProvider } from "./AccordionContext";
import getSpacingToken from "../common/getSpacingToken";
export var StyledAccordion = styled.div.withConfig({
displayName: "Accordion__StyledAccordion",
componentId: "sc-1b26k48-0"
})(["width:100%;box-sizing:border-box;position:relative;font-family:", ";margin-bottom:", ";"], function (_ref) {
var theme = _ref.theme;
return theme.orbit.fontFamily;
}, getSpacingToken); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledAccordion.defaultProps = {
theme: defaultTheme
};
var Accordion = function Accordion(_ref2) {
var children = _ref2.children,
dataTest = _ref2.dataTest,
spaceAfter = _ref2.spaceAfter,
expandedSection = _ref2.expandedSection,
loading = _ref2.loading,
onExpand = _ref2.onExpand;
return /*#__PURE__*/React.createElement(StyledAccordion, {
spaceAfter: spaceAfter,
"data-test": dataTest
}, children ? React.Children.map(children, function (item) {
if (!item) return null;
var id = item.props.id; // Determine if section is expanded
var isExpanded = expandedSection === id; // Callback with section id
// onExpand is not required prop to have easier loading use case
var handleExpand = function handleExpand() {
return onExpand && onExpand(id);
};
return /*#__PURE__*/React.createElement(SectionProvider, {
value: {
expanded: isExpanded,
onExpand: handleExpand,
loading: loading
}
}, item);
}) : null);
};
export default Accordion;
export { default as AccordionSection } from "./AccordionSection";