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.
141 lines • 6.73 kB
JavaScript
;
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.confettiButtonVariants = exports.ConfettiButton = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importStar(require("react"));
const utils_1 = require("@/components/lib/utils");
const lucide_react_1 = require("lucide-react");
const class_variance_authority_1 = require("class-variance-authority");
// Variants for button styling
const confettiButtonVariants = (0, class_variance_authority_1.cva)("inline-flex items-center justify-center gap-2 font-medium transition-all duration-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none", {
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/90",
outline: "border bg-background hover:bg-accent hover:text-accent-foreground",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
gradient: "bg-gradient-to-r from-primarylw to-purple-600 text-white hover:from-primarylw hover:to-purple-700",
},
size: {
default: "h-10 px-4 py-2 rounded-md",
sm: "h-8 px-3 py-1 rounded-md text-sm",
lg: "h-12 px-6 py-3 rounded-md text-lg",
xl: "h-14 px-8 py-4 rounded-md text-xl",
icon: "h-10 w-10 rounded-full",
pill: "h-10 px-6 py-2 rounded-full",
},
animation: {
none: "",
pulse: "animate-pulse",
bounce: "hover:animate-bounce",
scale: "active:scale-95",
shake: "hover:animate-[wiggle_0.3s_ease-in-out]",
glow: "hover:shadow-[0_0_15px_rgba(255,255,255,0.5)]",
expand: "active:scale-110 transition-transform",
},
},
defaultVariants: {
variant: "default",
size: "default",
animation: "scale",
},
});
exports.confettiButtonVariants = confettiButtonVariants;
const ConfettiButton = react_1.default.forwardRef(({ className, variant, size, animation, asChild = false, children, icon, iconPosition = "left", loading = false, confettiOptions = {
particleCount: 100,
spread: 70,
}, autoConfetti = false, triggerOnHover = false, ...props }, ref) => {
const [scriptLoaded, setScriptLoaded] = (0, react_1.useState)(false);
const buttonRef = (0, react_1.useRef)(null);
// Load confetti script dynamically
(0, react_1.useEffect)(() => {
if (!window.confetti) {
const script = document.createElement("script");
script.src =
"https://cdn.jsdelivr.net/npm/canvas-confetti@1.4.0/dist/confetti.browser.min.js";
script.async = true;
script.onload = () => setScriptLoaded(true);
document.body.appendChild(script);
return () => {
if (script.parentNode) {
script.parentNode.removeChild(script);
}
};
}
else {
setScriptLoaded(true);
}
}, []);
// Auto confetti on mount if needed
(0, react_1.useEffect)(() => {
if (scriptLoaded && autoConfetti && window.confetti && buttonRef.current) {
const rect = buttonRef.current.getBoundingClientRect();
const x = (rect.left + rect.width / 2) / window.innerWidth;
const y = (rect.top + rect.height / 2) / window.innerHeight;
window.confetti({
...confettiOptions,
origin: { x, y },
});
}
}, [scriptLoaded, autoConfetti, confettiOptions]);
const triggerConfetti = () => {
if (scriptLoaded && window.confetti && buttonRef.current) {
const rect = buttonRef.current.getBoundingClientRect();
const x = (rect.left + rect.width / 2) / window.innerWidth;
const y = (rect.top + rect.height / 2) / window.innerHeight;
window.confetti({
...confettiOptions,
origin: { x, y },
});
}
};
return ((0, jsx_runtime_1.jsxs)("button", { ref: (node) => {
if (typeof ref === "function")
ref(node);
else if (ref)
ref.current = node;
buttonRef.current = node;
}, className: (0, utils_1.cn)(confettiButtonVariants({ variant, size, animation }), className), onClick: (e) => {
if (scriptLoaded) {
triggerConfetti();
}
props.onClick?.(e);
}, onMouseEnter: triggerOnHover ? () => triggerConfetti() : undefined, disabled: loading || props.disabled, ...props, children: [loading && (0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { className: "h-4 w-4 mr-2 animate-spin" }), !loading && icon && iconPosition === "left" && ((0, jsx_runtime_1.jsx)("span", { className: "mr-1", children: icon })), children, !loading && icon && iconPosition === "right" && ((0, jsx_runtime_1.jsx)("span", { className: "ml-1", children: icon }))] }));
});
exports.ConfettiButton = ConfettiButton;
ConfettiButton.displayName = "ConfettiButton";
//# sourceMappingURL=confetti-button.js.map