mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import * as React from "react"
|
|
import { cn } from "@/lib/utils"
|
|
|
|
interface CircularProgressProps {
|
|
value?: number;
|
|
size?: number;
|
|
strokeWidth?: number;
|
|
className?: string;
|
|
children?: React.ReactNode;
|
|
}
|
|
|
|
const CircularProgress = React.forwardRef<
|
|
SVGSVGElement,
|
|
CircularProgressProps
|
|
>(({ value = 0, size = 24, strokeWidth = 2, className, children }, ref) => {
|
|
const radius = (size - strokeWidth) / 2;
|
|
const circumference = 2 * Math.PI * radius;
|
|
const strokeDasharray = circumference;
|
|
const strokeDashoffset = circumference - (value / 100) * circumference;
|
|
|
|
return (
|
|
<div className={cn("relative inline-flex items-center justify-center", className)}>
|
|
<svg
|
|
ref={ref}
|
|
width={size}
|
|
height={size}
|
|
className="transform -rotate-90"
|
|
viewBox={`0 0 ${size} ${size}`}
|
|
>
|
|
{/* Background circle */}
|
|
<circle
|
|
cx={size / 2}
|
|
cy={size / 2}
|
|
r={radius}
|
|
fill="none"
|
|
stroke="currentColor"
|
|
strokeWidth={strokeWidth}
|
|
className="text-muted/30"
|
|
/>
|
|
{/* Progress circle */}
|
|
<circle
|
|
cx={size / 2}
|
|
cy={size / 2}
|
|
r={radius}
|
|
fill="none"
|
|
stroke="currentColor"
|
|
strokeWidth={strokeWidth}
|
|
strokeLinecap="round"
|
|
strokeDasharray={strokeDasharray}
|
|
strokeDashoffset={strokeDashoffset}
|
|
className="text-primary transition-all duration-300 ease-in-out"
|
|
/>
|
|
</svg>
|
|
{children && (
|
|
<div className="absolute inset-0 flex items-center justify-center">
|
|
{children}
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
});
|
|
|
|
CircularProgress.displayName = "CircularProgress";
|
|
|
|
export { CircularProgress }; |