@@ -2,9 +2,11 @@ import './Timeline.css';
2
2
import { Key , useEffect , useRef } from 'react' ;
3
3
import { PropsWithKey , TimelineItem , TimelineItemProps } from './TimelineItem' ;
4
4
import { OffsetConfig , resolveOffsets } from '../models/offset' ;
5
+ import { Positioning } from '../models/positioning' ;
5
6
6
7
export type TimelineProps = {
7
8
items : PropsWithKey < TimelineItemProps > [ ] ;
9
+ positioning : Positioning ;
8
10
gap ?: number ;
9
11
offset ?: OffsetConfig ;
10
12
minMarkerGap ?: number ;
@@ -14,14 +16,15 @@ export type TimelineProps = {
14
16
} ;
15
17
16
18
const defaultTimelineConfig : Partial < TimelineProps > = {
19
+ positioning : 'alternating' ,
17
20
gap : 50 ,
18
21
offset : 50 ,
19
22
minMarkerGap : 50 ,
20
23
dateFormat : 'P' ,
21
24
} ;
22
25
23
26
export 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 } ;
25
28
26
29
const timelineRef = useRef < HTMLDivElement > ( null ) ;
27
30
const itemsRef = useRef < Map < Key , HTMLElement > > ( ) ;
@@ -54,7 +57,7 @@ export function Timeline(props: TimelineProps) {
54
57
elements . forEach ( ( item ) => {
55
58
const element = item ;
56
59
57
- if ( leftHeight > rightHeight ) {
60
+ if ( ( positioning !== 'right' && leftHeight > rightHeight ) || positioning === 'left' ) {
58
61
leftHeight += getMinMarkerGapCompensation ( leftHeight , rightHeight ) ;
59
62
60
63
element . style . top = `${ rightHeight } px` ;
@@ -84,7 +87,7 @@ export function Timeline(props: TimelineProps) {
84
87
useEffect ( positionTimelineItems , [ itemsRef ] ) ;
85
88
86
89
return (
87
- < div className = { [ 'timeline' , className ] . join ( ' ' ) } ref = { timelineRef } >
90
+ < div className = { [ 'timeline' , `timeline-- ${ positioning } ` , className ] . join ( ' ' ) } ref = { timelineRef } >
88
91
< div className = "timeline__line" />
89
92
{ items . map ( ( item ) => (
90
93
< TimelineItem
0 commit comments