import React from 'react' import classnames from 'classnames' import { buildCss, buildHtmlProps } from '../utilities/props' import { globalProps, GlobalProps } from "../utilities/globalProps" import DateStacked from '../pb_date_stacked/_date_stacked' import IconCircle from '../pb_icon_circle/_icon_circle' import TimelineLabel from './subcomponents/Label' import TimelineStep from './subcomponents/Step' import TimelineDetail from './subcomponents/Detail' type ItemProps = { className?: string, children?: React.ReactNode[] | React.ReactNode, date?: Date, htmlOptions?: {[key: string]: string | number | boolean | (() => void)}, icon?: string, iconColor?: 'default' | 'royal' | 'blue' | 'purple' | 'teal' | 'red' | 'yellow' | 'green', lineStyle?: 'solid' | 'dotted', } & GlobalProps function isElementOfType
( element: React.ReactNode, component: React.ComponentType
): element is React.ReactElement
{ return React.isValidElement
(element) && element.type === component } const TimelineItem = ({ className, children, date, htmlOptions = {}, icon = 'user', iconColor = 'default', lineStyle = 'solid', ...props }: ItemProps): React.ReactElement => { const timelineItemCss = buildCss('pb_timeline_item_kit', lineStyle) const htmlProps = buildHtmlProps(htmlOptions) const childrenArray = React.Children.toArray(children) const labelChild = childrenArray.find( (child): child is React.ReactElement => isElementOfType(child, TimelineLabel) ) const stepChild = childrenArray.find( (child): child is React.ReactElement => isElementOfType(child, TimelineStep) ) const detailChild = childrenArray.find( (child): child is React.ReactElement => isElementOfType(child, TimelineDetail) ) const otherChildren = childrenArray.filter( (child) => !isElementOfType(child, TimelineLabel) && !isElementOfType(child, TimelineStep) && !isElementOfType(child, TimelineDetail) ) return (