UNPKG

@sikka/hawa

Version:

Modern UI Kit made with Tailwind

110 lines (107 loc) 3.09 kB
"use client"; // elements/progressCircle/ProgressCircle.tsx import React from "react"; // util/index.ts import { clsx } from "clsx"; import { twMerge } from "tailwind-merge"; function cn(...inputs) { return twMerge(clsx(inputs)); } // elements/progressCircle/ProgressCircle.tsx var size2config = { xs: { radius: 15, strokeWidth: 3 }, sm: { radius: 19, strokeWidth: 4 }, md: { radius: 32, strokeWidth: 6 }, lg: { radius: 52, strokeWidth: 8 }, xl: { radius: 80, strokeWidth: 10 } }; function getLimitedValue(input) { if (input === void 0) { return 0; } else if (input > 100) { return 100; } else { return input; } } var ProgressCircle = React.forwardRef((props, ref) => { const { value: inputValue, size = "md", className, showAnimation = true, color, tooltip, radius: inputRadius, strokeWidth: inputStrokeWidth, children, ...other } = props; const value = getLimitedValue(inputValue); const radius = inputRadius != null ? inputRadius : size2config[size].radius; const strokeWidth = inputStrokeWidth != null ? inputStrokeWidth : size2config[size].strokeWidth; const normalizedRadius = radius - strokeWidth / 2; const circumference = normalizedRadius * 2 * Math.PI; const strokeDashoffset = value / 100 * circumference; const offset = circumference - strokeDashoffset; return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement( "div", { ref, className: cn( "hawa-flex hawa-flex-col hawa-items-center hawa-justify-center", className ) }, /* @__PURE__ */ React.createElement( "svg", { width: radius * 2, height: radius * 2, viewBox: `0 0 ${radius * 2} ${radius * 2}`, className: "hawa-rotate-180 hawa-transform" }, /* @__PURE__ */ React.createElement( "circle", { r: normalizedRadius, cx: radius, cy: radius, strokeWidth, fill: "transparent", stroke: "", strokeLinecap: "round", className: cn( "hawa-transition-colors hawa-ease-linear", "hawa-stroke-primary/20" ) } ), value > 0 ? /* @__PURE__ */ React.createElement( "circle", { r: normalizedRadius, cx: radius, cy: radius, strokeWidth, strokeDasharray: circumference + " " + circumference, strokeDashoffset: offset, fill: "transparent", stroke: "", strokeLinecap: "round", className: cn( "hawa-transition-colors hawa-ease-linear", "hawa-stroke-primary", showAnimation ? "hawa-transition-all hawa-duration-300 hawa-ease-in-out" : "" ) } ) : null ), /* @__PURE__ */ React.createElement("div", { className: cn("hawa-absolute hawa-flex") }, children) )); }); ProgressCircle.displayName = "ProgressCircle"; export { ProgressCircle }; //# sourceMappingURL=index.mjs.map