Status indicator
8starlabs-ui/status-indicatorFreeComponent
A status indicator component
Install it
npx shadcn@latest add https://ui.8starlabs.com/r/status-indicator.jsonSource
1import React from "react";2import { cn } from "@/lib/utils";34interface StatusIndicatorProps {5 state: "active" | "down" | "fixing" | "idle";6 color?: string;7 label?: string;8 className?: string;9 size?: "sm" | "md" | "lg";10 labelClassName?: string;11}1213const getStateColors = (state: StatusIndicatorProps["state"]) => {14 switch (state) {15 case "active":16 return { dot: "bg-green-500", ping: "bg-green-300" };17 case "down":18 return { dot: "bg-red-500", ping: "bg-red-300" };19 case "fixing":20 return { dot: "bg-yellow-500", ping: "bg-yellow-300" };21 case "idle":22 default:23 return { dot: "bg-slate-700", ping: "bg-slate-400" };24 }25};2627const getSizeClasses = (size: StatusIndicatorProps["size"]) => {28 switch (size) {29 case "sm":30 return { dot: "h-2 w-2", ping: "h-2 w-2" };31 case "lg":32 return { dot: "h-4 w-4", ping: "h-4 w-4" };33 case "md":34 default:35 return { dot: "h-3 w-3", ping: "h-3 w-3" };36 }37};3839const StatusIndicator: React.FC<StatusIndicatorProps> = ({40 state = "idle",41 color,42 label,43 className,44 size = "md",45 labelClassName46}) => {47 const shouldAnimate =48 state === "active" || state === "fixing" || state === "down";49 const colors = getStateColors(state);50 const sizeClasses = getSizeClasses(size);5152 return (53 <div className={cn("flex items-center gap-2", className)}>54 <div className="relative flex items-center">55 {shouldAnimate && (56 <span57 className={cn(58 "absolute inline-flex rounded-full opacity-75 animate-ping",59 sizeClasses.ping,60 colors.ping61 )}62 />63 )}64 <span65 className={cn(66 "relative inline-flex rounded-full",67 sizeClasses.dot,68 colors.dot69 )}70 />71 </div>72 {label && (73 <p74 className={cn(75 "text-sm text-slate-700 dark:text-slate-300",76 labelClassName77 )}78 >79 {label}80 </p>81 )}82 </div>83 );84};8586export default StatusIndicator;
Files it writes
More from 8starlabs-ui
All 74 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Buttonbutton | 8starlabs-ui | Components | Free | 2 deps | |
| Collapsiblecollapsible | 8starlabs-ui | Components | Free | 1 dep | |
| Dropdown Menudropdown-menu | 8starlabs-ui | Components | Free | 2 deps | |
| Flip clockflip-clock | 8starlabs-ui | Components | Free | no deps | |
| Heatmapheatmap | 8starlabs-ui | Components | Free | no deps | |
| Inputinput | 8starlabs-ui | Components | Free | no deps | |
| JSON Viewerjson-viewer | 8starlabs-ui | Components | Free | 1 dep · 3 files | |
| Labellabel | 8starlabs-ui | Components | Free | no deps |
