@soul-refiner/design-system 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -6,5 +6,7 @@ export { Loader } from './loader';
|
|
|
6
6
|
export type { LoaderProps } from './loader';
|
|
7
7
|
export { Notification } from './notification';
|
|
8
8
|
export type { NotificationProps } from './notification';
|
|
9
|
+
export { Progress } from './progress';
|
|
10
|
+
export type { ProgressProps } from './progress';
|
|
9
11
|
export { Toast } from './toast';
|
|
10
12
|
export type { ToastProps } from './toast';
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
import { colorReference } from 'common';
|
|
4
|
+
import { Box, P } from 'components';
|
|
5
|
+
import { CheckmarkCircle, Checkmarks, Close, MinusCircle, Pause } from 'icons';
|
|
6
|
+
|
|
7
|
+
type ProgressType = 'compact' | 'detailed';
|
|
8
|
+
|
|
9
|
+
export interface ProgressProps {
|
|
10
|
+
hasError?: boolean;
|
|
11
|
+
hasIcon?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* @param progress a percentage until complete
|
|
14
|
+
*/
|
|
15
|
+
progress: number;
|
|
16
|
+
subtitle?: string;
|
|
17
|
+
sx?: string;
|
|
18
|
+
title?: string;
|
|
19
|
+
type?: ProgressType;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const Progress = ({
|
|
23
|
+
hasError,
|
|
24
|
+
progress,
|
|
25
|
+
subtitle,
|
|
26
|
+
sx,
|
|
27
|
+
title,
|
|
28
|
+
type,
|
|
29
|
+
}: ProgressProps) => {
|
|
30
|
+
const isComplete = !hasError && progress > 99;
|
|
31
|
+
const isDetailed = type === 'detailed';
|
|
32
|
+
const percent = hasError || isComplete ? 100 : progress;
|
|
33
|
+
const displayPercent = hasError ? '-' : percent + '%';
|
|
34
|
+
|
|
35
|
+
const color = hasError ? 'red-4' : isComplete ? 'green-3' : 'primary-blue-2';
|
|
36
|
+
const gradientColors: Record<'start' | 'end' | 'empty' | 'bg', string> =
|
|
37
|
+
hasError
|
|
38
|
+
? {
|
|
39
|
+
start: 'var(--color-red-6)',
|
|
40
|
+
end: 'var(--color-red-4)',
|
|
41
|
+
empty: 'var(--color-red-8)',
|
|
42
|
+
bg: 'var(--color-red-9)',
|
|
43
|
+
}
|
|
44
|
+
: isComplete
|
|
45
|
+
? {
|
|
46
|
+
start: 'var(--color-green-5)',
|
|
47
|
+
end: 'var(--color-green-3)',
|
|
48
|
+
empty: 'var(--color-green-8)',
|
|
49
|
+
bg: 'var(--color-green-9)',
|
|
50
|
+
}
|
|
51
|
+
: {
|
|
52
|
+
start: '#abcfed',
|
|
53
|
+
end: 'var(--color-primary-blue-2)',
|
|
54
|
+
empty: 'var(--color-primary-blue-3)',
|
|
55
|
+
bg: 'var(--color-primary-blue-4)',
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const icon = hasError ? (
|
|
59
|
+
<Close size={24} color={color} />
|
|
60
|
+
) : isComplete ? (
|
|
61
|
+
<Checkmarks size={24} color={color} />
|
|
62
|
+
) : (
|
|
63
|
+
<Pause size={24} color={color} />
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<Box $align="center" $dir="row" $gap={16} sx={sx}>
|
|
68
|
+
{isDetailed && (
|
|
69
|
+
<IconWrapper
|
|
70
|
+
$completedDegree={Math.round(percent * 3.6)}
|
|
71
|
+
$gradientColors={gradientColors}
|
|
72
|
+
>
|
|
73
|
+
<IconInnerWrapper $bg={gradientColors.bg}>{icon}</IconInnerWrapper>
|
|
74
|
+
</IconWrapper>
|
|
75
|
+
)}
|
|
76
|
+
<Box $dir="column" $flex={1} $gap={8}>
|
|
77
|
+
<Box>
|
|
78
|
+
{title && (
|
|
79
|
+
<P $color="grey-2" $fontSize={14} $lineHeight={20}>
|
|
80
|
+
{title}
|
|
81
|
+
</P>
|
|
82
|
+
)}
|
|
83
|
+
{isComplete && (
|
|
84
|
+
<CheckmarkCircle
|
|
85
|
+
color="green-3"
|
|
86
|
+
size={24}
|
|
87
|
+
sx="margin-left: auto;"
|
|
88
|
+
/>
|
|
89
|
+
)}
|
|
90
|
+
{hasError && (
|
|
91
|
+
<MinusCircle color="red-4" size={24} sx="margin-left: auto;" />
|
|
92
|
+
)}
|
|
93
|
+
</Box>
|
|
94
|
+
<BarWrapper>
|
|
95
|
+
<Bar $color={colorReference[color]} $percent={percent} />
|
|
96
|
+
</BarWrapper>
|
|
97
|
+
{subtitle && (
|
|
98
|
+
<P $color="grey-4" $fontSize={12} $lineHeight={16}>
|
|
99
|
+
{subtitle}
|
|
100
|
+
</P>
|
|
101
|
+
)}
|
|
102
|
+
</Box>
|
|
103
|
+
{isDetailed && (
|
|
104
|
+
<P $color="grey-4" $textAlign="center" sx="width: 72px;">
|
|
105
|
+
{displayPercent}
|
|
106
|
+
</P>
|
|
107
|
+
)}
|
|
108
|
+
</Box>
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const BarWrapper = styled.div`
|
|
113
|
+
position: relative;
|
|
114
|
+
width: 100%;
|
|
115
|
+
height: 12px;
|
|
116
|
+
border-radius: 32px;
|
|
117
|
+
background-color: var(--color-grey-8);
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
const Bar = styled.div<{
|
|
121
|
+
$color: string;
|
|
122
|
+
$percent: number;
|
|
123
|
+
}>`
|
|
124
|
+
width: ${({ $percent }) => $percent}%;
|
|
125
|
+
height: 12px;
|
|
126
|
+
background-color: ${({ $color }) => $color};
|
|
127
|
+
border-radius: 32px;
|
|
128
|
+
`;
|
|
129
|
+
|
|
130
|
+
const IconWrapper = styled.div<{
|
|
131
|
+
$completedDegree: number;
|
|
132
|
+
$gradientColors: Record<'start' | 'end' | 'empty' | 'bg', string>;
|
|
133
|
+
}>`
|
|
134
|
+
position: relative;
|
|
135
|
+
display: block;
|
|
136
|
+
width: 45px;
|
|
137
|
+
height: 45px;
|
|
138
|
+
display: flex;
|
|
139
|
+
align-items: center;
|
|
140
|
+
justify-content: center;
|
|
141
|
+
border-radius: 50%;
|
|
142
|
+
flex-shrink: 0;
|
|
143
|
+
background: conic-gradient(
|
|
144
|
+
${({ $gradientColors }) => $gradientColors.start},
|
|
145
|
+
${({ $gradientColors }) => $gradientColors.end}
|
|
146
|
+
${({ $completedDegree }) => $completedDegree}deg,
|
|
147
|
+
${({ $gradientColors }) => $gradientColors.empty}
|
|
148
|
+
${({ $completedDegree }) => $completedDegree}deg 360deg
|
|
149
|
+
);
|
|
150
|
+
border: 1px solid ${({ $gradientColors }) => $gradientColors.bg};
|
|
151
|
+
`;
|
|
152
|
+
|
|
153
|
+
const IconInnerWrapper = styled.div<{ $bg: string }>`
|
|
154
|
+
display: flex;
|
|
155
|
+
justify-content: center;
|
|
156
|
+
align-items: center;
|
|
157
|
+
height: 39px;
|
|
158
|
+
width: 39px;
|
|
159
|
+
border-radius: 50%;
|
|
160
|
+
background-color: ${({ $bg }) => $bg};
|
|
161
|
+
`;
|