import cx from "classnames"; import type { ForwardedRef } from "react"; import React from "react"; const getMaxValue = (radius: number): number => Math.PI * (radius + radius * 0.22) * 2; const getStrokeDasharray = (max: number, percentage: number): string => { const fullCircleLength = max; const strokeLength = (max / 2) * (percentage / 100); return `${strokeLength}, ${fullCircleLength}`; }; const clamp = (num: number, min = 0, max = 100): number => { return Math.min(Math.max(num, min), max); }; const CLASS_ROOT = "gauge"; export interface GaugeProps { /** Text inside the gauge */ children?: React.ReactNode; /** Value filling the gauge */ percentage?: number; className?: string; [key: string]: any; } const Gauge = React.forwardRef( ( { children, className, percentage = 0, ...other }: GaugeProps, ref: ForwardedRef, ) => { const radius = 100; const maxValue = getMaxValue(radius); const circleAttrs = { r: radius, cx: 110, cy: 110, strokeWidth: 15, fill: "none", transform: "rotate(160, 110, 110)", } as const; return (
{children}
); }, ); Gauge.displayName = "Gauge"; export { Gauge };