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.

48 lines (47 loc) 1.62 kB
"use client"; import * as React from "react"; import cx from "clsx"; import Stack from "../Stack"; import useMediaQuery from "../hooks/useMediaQuery"; import { TimelineStatusProvider, TimelineStepProvider } from "./TimelineContext"; import { spaceAfterClasses } from "../common/tailwind"; const Timeline = ({ children, spaceAfter, direction, dataTest, id }) => { const childrenArr = React.Children.toArray(children); const { isDesktop } = useMediaQuery(); const getDirection = () => { if (direction) return direction; return isDesktop ? "row" : "column"; }; const hasSubLabelMargin = React.useMemo(() => childrenArr.some(child => /*#__PURE__*/React.isValidElement(child) && child.props.subLabel), [childrenArr]); return childrenArr && childrenArr.length > 0 ? /*#__PURE__*/React.createElement("div", { className: cx("orbit-timeline relative overflow-hidden", spaceAfter && spaceAfterClasses[spaceAfter]), "data-test": dataTest, id: id }, /*#__PURE__*/React.createElement(Stack, { flex: true, shrink: true, direction: getDirection(), as: "ol" }, /*#__PURE__*/React.createElement(TimelineStatusProvider, { direction: direction }, React.Children.map(childrenArr, (child, i) => { if ( /*#__PURE__*/React.isValidElement(child)) { return /*#__PURE__*/React.createElement(TimelineStepProvider, { index: i, last: i + 1 === childrenArr.length, hasSubLabelMargin: hasSubLabelMargin }, child); } return null; })))) : null; }; export default Timeline; export { default as TimelineStep } from "./TimelineStep";