import type { ReactNode } from 'react' import { cn } from '../../lib/cn' export type ProgressRingSize = 'sm' | 'md' | 'lg' const SIZES: Record = { sm: { box: 36, stroke: 4 }, md: { box: 56, stroke: 5 }, lg: { box: 88, stroke: 7 }, } export interface ProgressRingProps { value?: number max?: number /** Accessible name — what is progressing. */ label: string size?: ProgressRingSize /** Centre content — a percentage, a figure, an icon. */ children?: ReactNode /** Merged last, so it wins. */ className?: string } /** * The same value as `Progress`, drawn as an arc. Use it where the slot is * square rather than wide — a tile corner, a compact summary. */ export function ProgressRing({ value = 0, max = 100, label, size = 'md', children, className, }: ProgressRingProps) { const { box, stroke } = SIZES[size] const radius = (box - stroke) / 2 const circumference = 2 * Math.PI * radius const percent = max === 0 ? 0 : Math.min(1, Math.max(0, value / max)) return (
{children && {children}}
) }