-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathSegmentedProgressBar.tsx
More file actions
46 lines (41 loc) · 1.11 KB
/
SegmentedProgressBar.tsx
File metadata and controls
46 lines (41 loc) · 1.11 KB
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
import React from 'react';
import { Box } from '@metamask/design-system-react-native';
export interface SegmentedProgressBarProps {
/**
* 1-based count of completed steps used to compute the filled segments.
*/
current: number;
/**
* Total number of steps. Guarded against non-positive values to avoid
* divide-by-zero when the caller hasn't wired this yet.
*/
total: number;
/**
* Optional testID forwarded to the outer track.
*/
testID?: string;
}
enum SegmentState {
Completed = 'completed',
Upcoming = 'upcoming',
}
const Segment = ({ state }: { state: SegmentState }) => (
<Box
twClassName={`flex-1 h-1 rounded-lg ${state === SegmentState.Completed ? 'bg-success-default' : 'bg-muted-hover'}`}
/>
);
const SegmentedProgressBar = ({
current,
total,
testID,
}: SegmentedProgressBarProps) => (
<Box twClassName="flex-row gap-1" testID={testID}>
{Array.from({ length: total }, (_, index) => (
<Segment
key={index}
state={index < current ? SegmentState.Completed : SegmentState.Upcoming}
/>
))}
</Box>
);
export default SegmentedProgressBar;