Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom-timeline-states #57

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/examples/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const TimelineProgress = () => (
party: "No",
subtitle: "06 Jul 2023 12:00 UTC",
variant: "#ca2314",
state: "loading",
},
]}
/>
Expand Down
45 changes: 39 additions & 6 deletions src/lib/progress/timeline/bullet.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useRef } from "react";
import styled from "styled-components";
import styled, { css, keyframes } from "styled-components";
import Spine, { VariantProp, variantColor } from "./spine";
export type { VariantProp };
import { h2, p, small } from "../../../styles/common-style";
Expand All @@ -8,10 +8,40 @@ export interface SideProp {
rightSided?: boolean;
}

const Wrapper = styled.div<SideProp>`
export interface StateProp {
state?: "loading" | "disabled" | "active";
}

const loading = keyframes`
0%{
opacity: 1;
}
50%{
opacity: 0.5;
}
100%{
opacity: 1;
}
`;

const Wrapper = styled.div<SideProp & StateProp>`
display: flex;
position: relative;
justify-content: ${({ rightSided }) =>
rightSided ? "flex-start" : "flex-end"};
${({ state }) => {
if (state === "disabled")
return css`
opacity: 0.5;
`;
if (state === "loading")
return css`
animation: ${loading} 2s ease-in-out infinite normal;
`;
return css`
opacity: 1;
`;
}}
`;

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

interface BulletProps extends VariantProp, SideProp {
interface BulletProps extends VariantProp, SideProp, StateProp {
title: string;
party: string | React.ReactElement;
subtitle: string;
Expand All @@ -90,14 +120,17 @@ interface BulletProps extends VariantProp, SideProp {

const Bullet: React.FC<BulletProps> = (props) => {
const { title, party, subtitle, ...restProps } = props;
const { rightSided, variant, line, Icon, isLast, ...wrapperProps } =
const { rightSided, variant, line, Icon, isLast, state, ...wrapperProps } =
restProps;
const titleRef = useRef<HTMLHeadingElement>(null);

return (
<Wrapper {...{ rightSided }} {...wrapperProps}>
<Wrapper {...{ rightSided, state }} {...wrapperProps}>
<Spine {...{ variant, line, Icon, titleRef }} />
<TextContainer {...{ variant, rightSided, isLast }}>
<TextContainer
className="text-container"
{...{ variant, rightSided, isLast }}
>
Harman-singh-waraich marked this conversation as resolved.
Show resolved Hide resolved
<PartyTitleContainer {...{ rightSided }}>
<StyledTitle ref={titleRef}>{title}</StyledTitle>
{typeof party === `string` ? (
Expand Down
4 changes: 2 additions & 2 deletions src/lib/progress/timeline/custom.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import styled from "styled-components";
import Bullet, { SideProp, VariantProp } from "./bullet";
import Bullet, { SideProp, StateProp, VariantProp } from "./bullet";
import { borderBox } from "../../../styles/common-style";

interface TimelineItem extends SideProp, VariantProp {
interface TimelineItem extends SideProp, VariantProp, StateProp {
title: string;
party: string | React.ReactElement;
subtitle: string;
Expand Down
Loading