Skip to content

Commit 0aa53fb

Browse files
committed
feat: support-element-as-party-in-timeline
1 parent 11fc42f commit 0aa53fb

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

src/lib/progress/timeline/bullet.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useRef } from "react";
22
import styled from "styled-components";
33
import Spine, { VariantProp, variantColor } from "./spine";
44
export type { VariantProp };
@@ -17,6 +17,9 @@ const Wrapper = styled.div<SideProp>`
1717
const StyledTitle = styled.h2``;
1818
const StyledParty = styled.p``;
1919
const StyledSubtitle = styled.small``;
20+
const PartyElementWrapper = styled.div`
21+
display: inline-flex;
22+
`;
2023

2124
const TextContainer = styled.div<SideProp & VariantProp & { isLast: boolean }>`
2225
margin-${({ rightSided }) => (rightSided ? "left" : "right")}: 20px;
@@ -49,6 +52,12 @@ const TextContainer = styled.div<SideProp & VariantProp & { isLast: boolean }>`
4952
line-height: 19px;
5053
color: ${variantColor};
5154
}
55+
56+
& ${PartyElementWrapper} {
57+
order: ${({ rightSided }) => (rightSided ? 2 : 1)};
58+
max-height: 32px;
59+
overflow: hidden;
60+
}
5261
5362
& ${StyledSubtitle} {
5463
${small}
@@ -60,6 +69,8 @@ const TextContainer = styled.div<SideProp & VariantProp & { isLast: boolean }>`
6069

6170
const PartyTitleContainer = styled.div<SideProp>`
6271
display: flex;
72+
position: relative;
73+
align-items: center;
6374
flex-direction: row;
6475
flex-wrap: wrap;
6576
gap: 4px 8px;
@@ -69,7 +80,7 @@ const PartyTitleContainer = styled.div<SideProp>`
6980

7081
interface BulletProps extends VariantProp, SideProp {
7182
title: string;
72-
party: string;
83+
party: string | React.ReactElement;
7384
subtitle: string;
7485
active?: boolean;
7586
Icon?: React.FC<React.SVGAttributes<SVGElement>>;
@@ -81,14 +92,21 @@ const Bullet: React.FC<BulletProps> = (props) => {
8192
const { title, party, subtitle, ...restProps } = props;
8293
const { rightSided, variant, line, Icon, isLast, ...wrapperProps } =
8394
restProps;
95+
const titleRef = useRef<HTMLHeadingElement>(null);
8496

8597
return (
8698
<Wrapper {...{ rightSided }} {...wrapperProps}>
87-
<Spine {...{ variant, line, Icon }} />
99+
<Spine {...{ variant, line, Icon, titleRef }} />
88100
<TextContainer {...{ variant, rightSided, isLast }}>
89101
<PartyTitleContainer {...{ rightSided }}>
90-
<StyledTitle>{title}</StyledTitle>
91-
<StyledParty>{party}</StyledParty>
102+
<StyledTitle ref={titleRef}>{title}</StyledTitle>
103+
{typeof party === `string` ? (
104+
<StyledParty>{party}</StyledParty>
105+
) : (
106+
<PartyElementWrapper className="party-wrapper">
107+
{party}
108+
</PartyElementWrapper>
109+
)}
92110
</PartyTitleContainer>
93111
<StyledSubtitle>{subtitle}</StyledSubtitle>
94112
</TextContainer>

src/lib/progress/timeline/custom.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { borderBox } from "../../../styles/common-style";
55

66
interface TimelineItem extends SideProp, VariantProp {
77
title: string;
8-
party: string;
8+
party: string | React.ReactElement;
99
subtitle: string;
1010
Icon?: React.FC<React.SVGAttributes<SVGElement>>;
1111
}

src/lib/progress/timeline/spine.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useEffect, useState } from "react";
22
import styled, { css } from "styled-components";
33

44
const Wrapper = styled.div`
@@ -31,24 +31,36 @@ const Circle = styled.div<VariantProp>`
3131
border: 2px solid ${variantColor};
3232
`;
3333

34-
const Line = styled.div`
35-
height: auto;
34+
const Line = styled.div<{ topHeight?: number }>`
35+
height: ${({ topHeight }) => (topHeight ? `${topHeight}px` : "auto")};
3636
width: 0px;
37-
flex-grow: 1;
37+
flex-grow: ${({ topHeight }) => (topHeight ? 0 : 1)};
3838
border-left: 1px solid ${({ theme }) => theme.klerosUIComponentsStroke};
3939
`;
4040

4141
interface SpineProps extends VariantProp {
4242
active?: boolean;
4343
line?: boolean;
4444
Icon?: React.FC<React.SVGAttributes<SVGElement>>;
45+
titleRef?: React.RefObject<HTMLHeadingElement>;
4546
}
4647

47-
const Spine: React.FC<SpineProps> = ({ variant, line, Icon }) => (
48-
<Wrapper>
49-
{Icon ? <Icon /> : <Circle {...{ variant }} />}
50-
{line && <Line />}
51-
</Wrapper>
52-
);
48+
const Spine: React.FC<SpineProps> = ({ variant, line, Icon, titleRef }) => {
49+
const [topHeight, setTopHeight] = useState<number>();
50+
51+
useEffect(() => {
52+
if (titleRef?.current) {
53+
setTopHeight(titleRef.current.offsetTop);
54+
}
55+
}, [titleRef]);
56+
57+
return (
58+
<Wrapper>
59+
{topHeight ? <Line topHeight={topHeight} /> : null}
60+
{Icon ? <Icon /> : <Circle {...{ variant }} />}
61+
{line && <Line />}
62+
</Wrapper>
63+
);
64+
};
5365

5466
export default Spine;

0 commit comments

Comments
 (0)