Skip to content

Commit f969c0d

Browse files
authored
Merge pull request #104 from openscript-ch/100-positioning-not-calculated-correctly
fix: consider gaps for positioning
2 parents c5c299c + 380bd57 commit f969c0d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/components/Timeline.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
.timeline__items-container {
3232
display: flex;
3333
flex-direction: column;
34-
gap: var(--gap);
3534
flex: 1;
3635
}
3736

@@ -51,6 +50,10 @@
5150
gap: var(--card-offset);
5251
}
5352

53+
.timeline-item:not(:last-child) {
54+
margin-bottom: var(--gap);
55+
}
56+
5457
.timeline__items-container--left .timeline-item {
5558
flex-direction: row-reverse;
5659
}

src/components/Timeline.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,16 @@ export function Timeline(props: TimelineProps) {
5757
let leftHeight = leftContainer.current.offsetTop;
5858
let rightHeight = rightContainer.current.offsetTop;
5959

60-
const defaultMarkerOffset = elements[0].marker?.offsetTop ?? 0;
60+
const [firstElement] = elements;
61+
62+
const defaultMarkerOffset = firstElement.marker?.offsetTop ?? 0;
6163
let nextMarkerOffset = defaultMarkerOffset;
6264

65+
if (!firstElement.item) return;
66+
67+
const { marginBottom } = getComputedStyle(firstElement.item);
68+
const gapHeight = parseFloat(marginBottom);
69+
6370
elements.forEach((refs) => {
6471
const { item, pointer, marker } = refs;
6572
if (!item || !pointer || !marker) return;
@@ -74,10 +81,10 @@ export function Timeline(props: TimelineProps) {
7481
// defines whether an item should be appended on the left or right side of the timeline
7582
if ((positioning !== 'right' && leftHeight > rightHeight) || positioning === 'left') {
7683
rightContainer.current?.appendChild(item);
77-
rightHeight += item.offsetHeight;
84+
rightHeight += item.offsetHeight + gapHeight;
7885
} else {
7986
leftContainer.current?.appendChild(item);
80-
leftHeight += item.offsetHeight;
87+
leftHeight += item.offsetHeight + gapHeight;
8188
}
8289
});
8390
}

0 commit comments

Comments
 (0)