UNPKG

lightswind

Version:

A collection of beautifully crafted React Components, Blocks & Templates for Modern Developers. Create stunning web applications effortlessly by using our 160+ professional and animated react components.

81 lines 4.18 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Progress = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const React = __importStar(require("react")); const utils_1 = require("@/components/lib/utils"); const Progress = React.forwardRef(({ className, value = 0, max = 100, indicatorClassName, indeterminate = false, color = "default", size = "md", showValue = false, animationSpeed = "normal", ...props }, ref) => { const percentage = value ? (value / max) * 100 : 0; const [prevPercentage, setPrevPercentage] = React.useState(percentage); const [isAnimating, setIsAnimating] = React.useState(false); React.useEffect(() => { // Only animate when the value actually changes if (percentage !== prevPercentage) { setIsAnimating(true); setPrevPercentage(percentage); // Reset the animation state after the transition is complete const timeout = setTimeout(() => { setIsAnimating(false); }, 1000); // This should match the CSS transition duration return () => clearTimeout(timeout); } }, [percentage, prevPercentage]); // Color variants const colorVariants = { default: "bg-primary", primary: "bg-primary", secondary: "bg-secondary", success: "bg-green-500", warning: "bg-yellow-500", danger: "bg-red-500" }; // Size variants const sizeVariants = { sm: "h-2", md: "h-4", lg: "h-6" }; // Animation speed variants const animationVariants = { slow: "duration-1000", normal: "duration-700", fast: "duration-300" }; return ((0, jsx_runtime_1.jsxs)("div", { ref: ref, role: "progressbar", "aria-valuemin": 0, "aria-valuemax": max, "aria-valuenow": indeterminate ? undefined : value, "aria-valuetext": indeterminate ? undefined : `${Math.round(percentage)}%`, className: (0, utils_1.cn)("relative w-full overflow-hidden rounded-full bg-secondary", sizeVariants[size], className), ...props, children: [(0, jsx_runtime_1.jsx)("div", { className: (0, utils_1.cn)("h-full w-full flex-1", colorVariants[color], indeterminate ? "animate-progress-indeterminate origin-left" : "", isAnimating ? "transition-all ease-out" : "", animationVariants[animationSpeed], indicatorClassName), style: indeterminate ? {} : { transform: `translateX(-${100 - percentage}%)` } }), showValue && ((0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.cn)("absolute inset-0 flex items-center justify-center text-xs font-semibold", isAnimating ? "transition-opacity duration-300" : ""), children: [Math.round(percentage), "%"] }))] })); }); exports.Progress = Progress; Progress.displayName = "Progress"; //# sourceMappingURL=progress.js.map