Skip to content

Commit 524e6f7

Browse files
authored
Merge pull request #18 from filecoin-project/bp/badge-component
[UXIT-3444] Badge component
2 parents 4f2a904 + e34431b commit 524e6f7

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/components/ui/badge-status.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { CircleCheck, LoaderCircle } from 'lucide-react'
2+
import { cva, type VariantProps } from 'class-variance-authority'
3+
import { cn } from '../../utils/cn.ts'
4+
import type { UploadProgress } from '../upload/upload-progress.tsx'
5+
6+
type Status = UploadProgress['status'] | 'pinned'
7+
8+
type BadgeStatusProps = VariantProps<typeof badgeVariants> & {
9+
status: Status
10+
}
11+
12+
const badgeVariants = cva('inline-flex items-center gap-1 pl-1.5 pr-2 py-0.5 rounded-full text-sm font-medium', {
13+
variants: {
14+
status: {
15+
'in-progress': 'bg-badge-in-progress text-badge-in-progress-text border border-badge-in-progress-border',
16+
completed: 'bg-badge-success text-brand-50 border border-badge-success-border',
17+
pinned: 'bg-badge-success text-brand-50 border border-badge-success-border',
18+
error: null,
19+
pending: 'bg-zinc-800 border border-zinc-700 text-zinc-300',
20+
},
21+
},
22+
defaultVariants: {
23+
status: 'in-progress',
24+
},
25+
})
26+
27+
const statusIcons: Record<Status, React.ReactNode> = {
28+
'in-progress': <LoaderCircle size={12} />,
29+
completed: <CircleCheck size={12} />,
30+
pinned: <CircleCheck size={12} />,
31+
error: null,
32+
pending: null,
33+
}
34+
35+
const statusLabels: Record<Status, string | null> = {
36+
'in-progress': 'In progress',
37+
completed: 'Complete',
38+
pinned: 'Pinned',
39+
error: null,
40+
pending: 'Pending',
41+
}
42+
43+
function BadgeStatus({ status }: BadgeStatusProps) {
44+
return (
45+
<span className={cn(badgeVariants({ status }))}>
46+
{statusIcons[status]} {statusLabels[status]}
47+
</span>
48+
)
49+
}
50+
51+
export { BadgeStatus }

src/index.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
--color-button-brand: #086dc5;
99
--color-button-brand-disabled: #005280;
10+
11+
--color-badge-in-progress: #3b1400;
12+
--color-badge-in-progress-text: #ff8c3b;
13+
--color-badge-in-progress-border: #662100;
14+
15+
--color-badge-success: #001d3b;
16+
--color-badge-success-border: #003669;
1017
}
1118

1219
:root {

0 commit comments

Comments
 (0)