This repository was archived by the owner on Feb 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProgressModal.tsx
173 lines (166 loc) · 4.98 KB
/
ProgressModal.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
"use client";
import { Check, X } from "lucide-react";
import { Modal } from "@/primitives/Modal";
import { ProgressStatus, Step } from "@/types";
import { Dialog, DialogHeader, DialogTitle, DialogDescription } from "@/ui-shadcn/dialog";
export interface ProgressModalProps {
steps: Step[];
isOpen?: boolean;
onOpenChange?: (isOpen: boolean) => void;
heading?: string;
subheading?: string;
}
export const ProgressModal = ({
isOpen,
onOpenChange,
heading = "Processing...",
subheading = "Please hold while your operation is in progress.",
steps,
}: ProgressModalProps) => {
return (
<Dialog open={isOpen} onOpenChange={onOpenChange}>
<Modal className="w-[450px] flex-col gap-8 rounded-2xl p-8">
<DialogHeader className="flex flex-col gap-1">
<DialogTitle className="text-base font-semibold text-black">{heading}</DialogTitle>
<DialogDescription className="text-[14px]/[24px] text-grey-900">
{subheading}
</DialogDescription>
</DialogHeader>
<div className="overflow-hidden ">
{steps.map((step, stepIdx) => (
<div
key={stepIdx}
className={`relative ${stepIdx !== steps.length - 1 ? "pb-10" : ""}`}
data-testid={`${step.name}-${step.status}`}
>
<ModalStep
step={step}
status={step.status}
isLastStep={stepIdx === steps.length - 1}
/>
</div>
))}
</div>
</Modal>
</Dialog>
);
};
function ModalStep({
step,
status,
isLastStep,
}: {
step: Step;
status: ProgressStatus;
isLastStep: boolean;
}) {
const { icon, line, nameColor, descriptionColor } = getStepAttributes(status, isLastStep);
return (
<>
{!isLastStep && line}
<div className="relative flex">
<span className="flex h-9 items-center" aria-hidden="true">
{icon}
</span>
<span className="ml-4 flex min-w-0 flex-col">
<span
className={`font-ui-sans text-[14px]/[16px] font-semibold uppercase tracking-wide ${nameColor}`}
>
{step.name}
</span>
<span className={`text-[14px]/[24px] ${descriptionColor}`}>{step.description}</span>
</span>
</div>
</>
);
}
function getStepAttributes(
status: ProgressStatus,
isLastStep: boolean,
): {
icon: JSX.Element;
line: JSX.Element | null;
nameColor: string;
descriptionColor: string;
} {
switch (status) {
case ProgressStatus.IS_SUCCESS:
return {
icon: (
<span
className="relative z-10 flex size-8 items-center justify-center rounded-full bg-moss-700"
data-testid="complete-icon"
>
<Check className="size-5 text-white" aria-hidden="true" />
</span>
),
line: !isLastStep ? (
<div
className="absolute inset-y-4 left-4 z-10 -ml-px h-full w-0.5 bg-moss-700"
aria-hidden="true"
/>
) : null,
nameColor: "text-black",
descriptionColor: "text-black",
};
case ProgressStatus.IN_PROGRESS:
return {
icon: (
<span className="relative z-20 flex size-8 items-center justify-center rounded-full border-2 border-grey-900 bg-white">
<span
className="animate-pulse-scale size-2.5 rounded-full bg-grey-900"
data-testid="current-icon"
/>
</span>
),
line: !isLastStep ? (
<div
className="absolute left-4 top-4 -ml-px mt-0.5 h-full w-0.5 bg-grey-100"
aria-hidden="true"
/>
) : null,
nameColor: "text-black",
descriptionColor: "text-black",
};
case ProgressStatus.IS_ERROR:
return {
icon: (
<span className="relative z-10 flex size-8 items-center justify-center rounded-full border-2 border-red-700 bg-white">
<X className="size-5 text-red-700" data-testid="error-icon" />
</span>
),
line: !isLastStep ? (
<div
className="absolute left-4 top-4 -ml-px mt-0.5 h-full w-0.5 bg-grey-100"
aria-hidden="true"
/>
) : null,
nameColor: "text-grey-900",
descriptionColor: "text-grey-900",
};
case ProgressStatus.NOT_STARTED:
return {
icon: (
<span
className="relative z-10 flex size-8 items-center justify-center rounded-full border-2 border-grey-500 bg-white"
data-testid="upcoming-icon"
></span>
),
line: !isLastStep ? (
<div
className="absolute left-4 top-4 -ml-px mt-0.5 h-full w-0.5 bg-grey-100"
aria-hidden="true"
/>
) : null,
nameColor: "text-grey-900",
descriptionColor: "text-grey-900",
};
default:
return {
icon: <></>,
line: null,
nameColor: "",
descriptionColor: "",
};
}
}