Skip to content

Commit 1433327

Browse files
authored
Merge pull request #57 from kleros/feat/custom-timeline-states
feat: custom-timeline-states
2 parents 51f8e80 + d0d8894 commit 1433327

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

src/examples/timeline.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const TimelineProgress = () => (
9393
party: "No",
9494
subtitle: "06 Jul 2023 12:00 UTC",
9595
variant: "#ca2314",
96+
state: "loading",
9697
},
9798
]}
9899
/>

src/lib/progress/timeline/bullet.tsx

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useRef } from "react";
2-
import styled from "styled-components";
2+
import styled, { css, keyframes } from "styled-components";
33
import Spine, { VariantProp, variantColor } from "./spine";
44
export type { VariantProp };
55
import { h2, p, small } from "../../../styles/common-style";
@@ -8,10 +8,40 @@ export interface SideProp {
88
rightSided?: boolean;
99
}
1010

11-
const Wrapper = styled.div<SideProp>`
11+
export interface StateProp {
12+
state?: "loading" | "disabled" | "active";
13+
}
14+
15+
const loading = keyframes`
16+
0%{
17+
opacity: 1;
18+
}
19+
50%{
20+
opacity: 0.5;
21+
}
22+
100%{
23+
opacity: 1;
24+
}
25+
`;
26+
27+
const Wrapper = styled.div<SideProp & StateProp>`
1228
display: flex;
29+
position: relative;
1330
justify-content: ${({ rightSided }) =>
1431
rightSided ? "flex-start" : "flex-end"};
32+
${({ state }) => {
33+
if (state === "disabled")
34+
return css`
35+
opacity: 0.5;
36+
`;
37+
if (state === "loading")
38+
return css`
39+
animation: ${loading} 2s ease-in-out infinite normal;
40+
`;
41+
return css`
42+
opacity: 1;
43+
`;
44+
}}
1545
`;
1646

1747
const StyledTitle = styled.h2``;
@@ -78,7 +108,7 @@ const PartyTitleContainer = styled.div<SideProp>`
78108
rightSided ? "flex-start" : "flex-end"};
79109
`;
80110

81-
interface BulletProps extends VariantProp, SideProp {
111+
interface BulletProps extends VariantProp, SideProp, StateProp {
82112
title: string;
83113
party: string | React.ReactElement;
84114
subtitle: string;
@@ -90,14 +120,17 @@ interface BulletProps extends VariantProp, SideProp {
90120

91121
const Bullet: React.FC<BulletProps> = (props) => {
92122
const { title, party, subtitle, ...restProps } = props;
93-
const { rightSided, variant, line, Icon, isLast, ...wrapperProps } =
123+
const { rightSided, variant, line, Icon, isLast, state, ...wrapperProps } =
94124
restProps;
95125
const titleRef = useRef<HTMLHeadingElement>(null);
96126

97127
return (
98-
<Wrapper {...{ rightSided }} {...wrapperProps}>
128+
<Wrapper {...{ rightSided, state }} {...wrapperProps}>
99129
<Spine {...{ variant, line, Icon, titleRef }} />
100-
<TextContainer {...{ variant, rightSided, isLast }}>
130+
<TextContainer
131+
className="text-container"
132+
{...{ variant, rightSided, isLast }}
133+
>
101134
<PartyTitleContainer {...{ rightSided }}>
102135
<StyledTitle ref={titleRef}>{title}</StyledTitle>
103136
{typeof party === `string` ? (

src/lib/progress/timeline/custom.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from "react";
22
import styled from "styled-components";
3-
import Bullet, { SideProp, VariantProp } from "./bullet";
3+
import Bullet, { SideProp, StateProp, VariantProp } from "./bullet";
44
import { borderBox } from "../../../styles/common-style";
55

6-
interface TimelineItem extends SideProp, VariantProp {
6+
interface TimelineItem extends SideProp, VariantProp, StateProp {
77
title: string;
88
party: string | React.ReactElement;
99
subtitle: string;

0 commit comments

Comments
 (0)