@sikka/hawa
Version:
Modern UI Kit made with Tailwind
146 lines (142 loc) • 4.97 kB
JavaScript
"use client";
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// elements/progressCircle/index.ts
var progressCircle_exports = {};
__export(progressCircle_exports, {
ProgressCircle: () => ProgressCircle
});
module.exports = __toCommonJS(progressCircle_exports);
// elements/progressCircle/ProgressCircle.tsx
var import_react = __toESM(require("react"));
// util/index.ts
var import_clsx = require("clsx");
var import_tailwind_merge = require("tailwind-merge");
function cn(...inputs) {
return (0, import_tailwind_merge.twMerge)((0, import_clsx.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 = import_react.default.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__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
"div",
{
ref,
className: cn(
"hawa-flex hawa-flex-col hawa-items-center hawa-justify-center",
className
)
},
/* @__PURE__ */ import_react.default.createElement(
"svg",
{
width: radius * 2,
height: radius * 2,
viewBox: `0 0 ${radius * 2} ${radius * 2}`,
className: "hawa-rotate-180 hawa-transform"
},
/* @__PURE__ */ import_react.default.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__ */ import_react.default.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__ */ import_react.default.createElement("div", { className: cn("hawa-absolute hawa-flex") }, children)
));
});
ProgressCircle.displayName = "ProgressCircle";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ProgressCircle
});
//# sourceMappingURL=index.js.map