Badge
scificn/badgeFreeComponent
Status indicator with ACTIVE, OFFLINE, WARNING, CRITICAL, and SCANNING variants.
Live preview
live · rendered by the registry
Rendered by scificn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.scificn.dev/r/badge.jsonSource
1import * as React from 'react'2import { cva, type VariantProps } from 'class-variance-authority'3import { cn } from '@/lib/utils'45const badgeVariants = cva(6 [7 'inline-flex items-center gap-1.5',8 'px-2 py-0.5',9 'text-[0.65rem] font-mono font-medium uppercase tracking-widest',10 'border border-solid',11 'rounded-none',12 'whitespace-nowrap',13 ],14 {15 variants: {16 variant: {17 ACTIVE: [18 'border-[var(--color-green)]',19 'text-[var(--color-green)]',20 ],21 OFFLINE: [22 'border-[var(--border)]',23 'text-[var(--text-muted)]',24 ],25 WARNING: [26 'border-[var(--color-amber)]',27 'text-[var(--color-amber)]',28 ],29 CRITICAL: [30 'border-[var(--color-red)]',31 'text-[var(--color-red)]',32 ],33 SCANNING: [34 'border-[var(--color-green)]',35 'text-[var(--color-green)]',36 ],37 },38 },39 defaultVariants: {40 variant: 'ACTIVE',41 },42 }43)4445export interface BadgeProps46 extends React.HTMLAttributes<HTMLSpanElement>,47 VariantProps<typeof badgeVariants> {}4849function Badge({ className, variant, children, ...props }: BadgeProps) {50 const isScanning = variant === 'SCANNING'5152 return (53 <span54 className={cn(badgeVariants({ variant }), className)}55 style={56 variant === 'ACTIVE'57 ? { textShadow: 'var(--text-glow-green)', boxShadow: 'inset 0 0 8px #00ed3f11' }58 : variant === 'CRITICAL'59 ? { textShadow: 'var(--text-glow-red)', boxShadow: 'inset 0 0 8px #cc220011' }60 : undefined61 }62 {...props}63 >64 {isScanning && (65 <span66 style={{67 display: 'inline-block',68 animation: 'blink-cursor 1s step-end infinite',69 }}70 >71 ●72 </span>73 )}74 {!isScanning && variant === 'ACTIVE' && <span>●</span>}75 {!isScanning && variant === 'OFFLINE' && <span>○</span>}76 {!isScanning && variant === 'WARNING' && <span>⚠</span>}77 {!isScanning && variant === 'CRITICAL' && <span>✕</span>}78 {children}79 </span>80 )81}8283export { Badge, badgeVariants }
What it pulls in
npm packages
More from scificn
All 33 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Alertalert | scificn | Components | Free | 1 dep | |
| Bar Chartbar-chart | scificn | Components | Free | no deps | |
| Breadcrumbbreadcrumb | scificn | Components | Free | no deps | |
| Buttonbutton | scificn | Components | Free | 2 deps | |
| Cardcard | scificn | Components | Free | no deps | |
| Checkboxcheckbox | scificn | Components | Free | 1 dep | |
| Dialogdialog | scificn | Components | Free | 1 dep | |
| Gridgrid | scificn | Components | Free | no deps |
