Skip to content

Commit 33c1bfa

Browse files
committed
feat: introduce custom timeline ends
1 parent 4310e66 commit 33c1bfa

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/components/Timeline.css

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,25 @@
2323
display: flex;
2424
}
2525

26-
.timeline__line {
26+
.timeline-line {
2727
background-color: var(--line-color);
2828
min-width: var(--line-width);
29+
position: relative;
30+
}
31+
32+
.timeline-line__end {
33+
position: absolute;
34+
left: 50%;
35+
}
36+
37+
.timeline-line__end--opening {
38+
transform: translate(-50%, -100%);
39+
top: 0;
40+
}
41+
42+
.timeline-line__end--closing {
43+
transform: translate(-50%, 100%);
44+
bottom: 0;
2945
}
3046

3147
.timeline__items-container {

src/components/Timeline.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Key, ReactElement, useEffect, useRef } from 'react';
33
import { TimelineItem, TimelineItemRefs, TimelineItemsProps } from './TimelineItem';
44
import { Positioning } from '../models/positioning';
55
import { convertToCssVariable, StyleConfig } from '../models/style';
6+
import { isElement } from '../helper/element';
67

78
export type TimelineProps = {
89
items: TimelineItemsProps;
@@ -11,6 +12,7 @@ export type TimelineProps = {
1112
formatDate?: (date: Date) => string;
1213
customMarker?: ReactElement;
1314
customPointer?: ReactElement;
15+
customTimelineEnds?: ReactElement | { opening?: ReactElement; closing?: ReactElement };
1416
styleConfig?: StyleConfig;
1517
className?: string;
1618
};
@@ -21,7 +23,7 @@ export const defaultTimelineConfig: Partial<TimelineProps> = {
2123
};
2224

2325
export function Timeline(props: TimelineProps) {
24-
const { items, positioning, minMarkerGap, className, customMarker, customPointer, styleConfig, formatDate } = {
26+
const { items, positioning, minMarkerGap, className, customMarker, customPointer, customTimelineEnds, styleConfig, formatDate } = {
2527
...defaultTimelineConfig,
2628
...props,
2729
};
@@ -121,7 +123,14 @@ export function Timeline(props: TimelineProps) {
121123
))}
122124
</div>
123125

124-
<div className="timeline__line" />
126+
<div className="timeline-line">
127+
<div className="timeline-line__end timeline-line__end--opening">
128+
{isElement(customTimelineEnds) ? customTimelineEnds : customTimelineEnds?.opening}
129+
</div>
130+
<div className="timeline-line__end timeline-line__end--closing">
131+
{isElement(customTimelineEnds) ? customTimelineEnds : customTimelineEnds?.closing}
132+
</div>
133+
</div>
125134

126135
<div ref={rightContainer} className="timeline__items-container timeline__items-container--right" />
127136
</div>

src/helper/element.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { ReactElement, isValidElement } from 'react';
2+
3+
export const isElement = (element: any): element is ReactElement => isValidElement(element);

0 commit comments

Comments
 (0)