UNPKG

@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.53 kB
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 const StyledAccordion = styled.div.withConfig({ displayName: "Accordion__StyledAccordion", componentId: "sc-1m21o0-0" })(["width:100%;box-sizing:border-box;position:relative;font-family:", ";margin-bottom:", ";"], ({ theme }) => theme.orbit.fontFamily, getSpacingToken); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198 StyledAccordion.defaultProps = { theme: defaultTheme }; const Accordion = ({ children, dataTest, id, spaceAfter, expandedSection, loading, onExpand }) => /*#__PURE__*/React.createElement(StyledAccordion, { spaceAfter: spaceAfter, id: id, "data-test": dataTest }, children ? React.Children.map(children, item => { if (!item) return null; const { id: innerId } = item.props; // Determine if section is expanded const isExpanded = expandedSection === id; // 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 } }, item); }) : null); export default Accordion; export { default as AccordionSection } from "./AccordionSection";