@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.
48 lines (44 loc) • 1.61 kB
JavaScript
import * as React from "react";
import styled from "styled-components";
import Stack from "../Stack";
import useMediaQuery from "../hooks/useMediaQuery";
import { TimelineStatusProvider, TimelineStepContext } from "./TimelineContext";
import getSpacingToken from "../common/getSpacingToken";
import themeDefault from "../defaultTheme";
const WrapperStyled = styled.div.withConfig({
displayName: "Timeline__WrapperStyled",
componentId: "sc-1ogyzsj-0"
})(["position:relative;overflow:hidden;margin-bottom:", ";"], getSpacingToken); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
WrapperStyled.defaultProps = {
theme: themeDefault
};
const Timeline = ({
children,
spaceAfter,
dataTest
}) => {
const childrenArr = React.Children.toArray(children);
const {
isDesktop
} = useMediaQuery();
return childrenArr && childrenArr.length > 0 ? /*#__PURE__*/React.createElement(WrapperStyled, {
spaceAfter: spaceAfter,
"data-test": dataTest
}, /*#__PURE__*/React.createElement(Stack, {
flex: true,
shrink: true,
direction: isDesktop ? "row" : "column"
}, /*#__PURE__*/React.createElement(TimelineStatusProvider, null, React.Children.map(childrenArr, (child, i) => {
if ( /*#__PURE__*/React.isValidElement(child)) {
return /*#__PURE__*/React.createElement(TimelineStepContext.Provider, {
value: {
index: i,
last: i + 1 === childrenArr.length
}
}, child);
}
return null;
})))) : null;
};
export default Timeline;
export { default as TimelineStep } from "./TimelineStep";