Skip to content

Commit 5945fd8

Browse files
committed
feat: implement calculating height of timeline
1 parent 4b53834 commit 5945fd8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/components/Timeline.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
div.timeline__line {
66
background-color: black;
77
width: 0.5rem;
8-
height: 20rem;
8+
height: 100%;
99
margin-inline: auto;
1010
}
1111

src/components/Timeline.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const defaultTimelineConfig: Partial<TimelineProps> = {
2121
export function Timeline(props: TimelineProps) {
2222
const { items, gap, offset } = { ...defaultTimelineConfig, ...props };
2323

24+
const timelineRef = useRef<HTMLDivElement>(null);
2425
const itemsRef = useRef<Map<Date, HTMLElement>>();
2526

2627
function getRefMap() {
@@ -50,10 +51,15 @@ export function Timeline(props: TimelineProps) {
5051
element.classList.add('timeline-item--left');
5152
}
5253
});
54+
55+
const timelineElement = timelineRef.current;
56+
if (timelineElement) {
57+
timelineElement.style.height = `${Math.max(leftHeight, rightHeight)}px`;
58+
}
5359
}, [itemsRef]);
5460

5561
return (
56-
<div className="timeline">
62+
<div className="timeline" ref={timelineRef}>
5763
<div className="timeline__line" />
5864
{items.map((item) => (
5965
<TimelineItem

0 commit comments

Comments
 (0)