@@ -2,9 +2,11 @@ import './Timeline.css';
22import { Key , useEffect , useRef } from 'react' ;
33import { PropsWithKey , TimelineItem , TimelineItemProps } from './TimelineItem' ;
44import { OffsetConfig , resolveOffsets } from '../models/offset' ;
5+ import { Positioning } from '../models/positioning' ;
56
67export type TimelineProps = {
78 items : PropsWithKey < TimelineItemProps > [ ] ;
9+ positioning : Positioning ;
810 gap ?: number ;
911 offset ?: OffsetConfig ;
1012 minMarkerGap ?: number ;
@@ -14,14 +16,15 @@ export type TimelineProps = {
1416} ;
1517
1618const defaultTimelineConfig : Partial < TimelineProps > = {
19+ positioning : 'alternating' ,
1720 gap : 50 ,
1821 offset : 50 ,
1922 minMarkerGap : 50 ,
2023 dateFormat : 'P' ,
2124} ;
2225
2326export function Timeline ( props : TimelineProps ) {
24- const { items, gap, offset, minMarkerGap, className, dateFormat, dateLocale } = { ...defaultTimelineConfig , ...props } ;
27+ const { items, positioning , gap, offset, minMarkerGap, className, dateFormat, dateLocale } = { ...defaultTimelineConfig , ...props } ;
2528
2629 const timelineRef = useRef < HTMLDivElement > ( null ) ;
2730 const itemsRef = useRef < Map < Key , HTMLElement > > ( ) ;
@@ -54,7 +57,7 @@ export function Timeline(props: TimelineProps) {
5457 elements . forEach ( ( item ) => {
5558 const element = item ;
5659
57- if ( leftHeight > rightHeight ) {
60+ if ( ( positioning !== 'right' && leftHeight > rightHeight ) || positioning === 'left' ) {
5861 leftHeight += getMinMarkerGapCompensation ( leftHeight , rightHeight ) ;
5962
6063 element . style . top = `${ rightHeight } px` ;
@@ -84,7 +87,7 @@ export function Timeline(props: TimelineProps) {
8487 useEffect ( positionTimelineItems , [ itemsRef ] ) ;
8588
8689 return (
87- < div className = { [ 'timeline' , className ] . join ( ' ' ) } ref = { timelineRef } >
90+ < div className = { [ 'timeline' , `timeline-- ${ positioning } ` , className ] . join ( ' ' ) } ref = { timelineRef } >
8891 < div className = "timeline__line" />
8992 { items . map ( ( item ) => (
9093 < TimelineItem
0 commit comments