Skip to content

Commit 7e4ddfc

Browse files
committed
feat: introduce timeline markers
1 parent 5945fd8 commit 7e4ddfc

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

src/components/Timeline.css

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
.timeline {
2+
--timeline-line-width: 0.2rem;
3+
--marker-line-width: var(--timeline-line-width);
4+
--marker-size: 1.5rem;
5+
26
position: relative;
37
}
48

59
div.timeline__line {
610
background-color: black;
7-
width: 0.5rem;
11+
width: var(--timeline-line-width);
812
height: 100%;
913
margin-inline: auto;
1014
}
1115

1216
.timeline-item {
1317
position: absolute;
14-
width: 45%;
18+
width: 50%;
19+
display: flex;
1520
}
1621

1722
.timeline-item--left {
@@ -21,3 +26,39 @@ div.timeline__line {
2126
.timeline-item--right {
2227
right: 0;
2328
}
29+
30+
.timeline-item__content {
31+
border: 1px solid black;
32+
padding: 1rem;
33+
flex: 1;
34+
}
35+
36+
div.timeline-item__marker {
37+
position: relative;
38+
height: var(--marker-line-width);
39+
margin-top: 2rem;
40+
width: 5rem;
41+
background-color: black;
42+
}
43+
44+
.timeline-item__marker::after {
45+
content: '';
46+
border-radius: 50%;
47+
width: var(--marker-size);
48+
height: var(--marker-size);
49+
background-color: black;
50+
position: absolute;
51+
top: calc(-1 * var(--marker-size) / 2 + var(--marker-line-width) / 2);
52+
}
53+
54+
.timeline-item--left .timeline-item__marker::after {
55+
right: calc(-1 * var(--marker-size) / 2);
56+
}
57+
58+
.timeline-item--right .timeline-item__marker::after {
59+
left: calc(-1 * var(--marker-size) / 2);
60+
}
61+
62+
.timeline-item--left .timeline-item__marker {
63+
order: 1;
64+
}

src/components/Timeline.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export type TimelineProps = {
1414
};
1515

1616
const defaultTimelineConfig: Partial<TimelineProps> = {
17-
gap: 30,
18-
offset: 30,
17+
gap: 50,
18+
offset: 50,
1919
};
2020

2121
export function Timeline(props: TimelineProps) {

src/components/TimelineItem.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ export type TimelineItemProps = PropsWithChildren<{
99
export const TimelineItem = forwardRef<HTMLDivElement, TimelineItemProps>(({ className, title, date, children }, ref) => {
1010
return (
1111
<div ref={ref} className={`${className} timeline-item`}>
12-
<p>{date.toISOString()}</p>
13-
<p>{title}</p>
14-
{children}
12+
<div className="timeline-item__marker" />
13+
<div className="timeline-item__content">
14+
<p>{date.toISOString()}</p>
15+
<p>{title}</p>
16+
{children}
17+
</div>
1518
</div>
1619
);
1720
});

0 commit comments

Comments
 (0)