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.
92 lines • 7.01 kB
JavaScript
;
"use client";
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 });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importStar(require("react"));
const framer_motion_1 = require("framer-motion");
const utils_1 = require("../lib/utils");
function MarqueeRow({ item, rowHeight, imageWidth, gap, duration, copies }) {
const safeCount = Math.max(2, copies);
// Render exactly 2 identical sets so the strip is 2× the visible content.
// The CSS animation translates -50% → back to the start = seamless loop.
const singleSet = Array.from({ length: safeCount });
return ((0, jsx_runtime_1.jsx)("div", { className: "overflow-hidden w-full", style: { height: rowHeight }, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)("div", { className: "flex items-center w-max", style: {
height: rowHeight,
gap,
paddingLeft: gap,
animation: `marquee-lw ${duration}s linear infinite`,
}, children: [0, 1].flatMap((set) => singleSet.map((_, i) => ((0, jsx_runtime_1.jsxs)(react_1.default.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: "text-sm sm:text-base font-semibold shrink-0 whitespace-nowrap text-foreground/70", style: { fontFamily: "inherit" }, children: item.name }), (0, jsx_runtime_1.jsx)("img", { src: item.src, alt: item.alt ?? item.name, draggable: false, loading: "lazy", className: "shrink-0 object-cover", style: {
width: imageWidth,
height: Math.round(rowHeight * 0.72),
aspectRatio: "3 / 1",
borderRadius: 9999,
} })] }, `${set}-${i}`)))) }) }));
}
// ─────────────────────────────────────────────────────────────────────────────
// Main component
// ─────────────────────────────────────────────────────────────────────────────
const MarqueeMenu = ({ items = [], defaultIndex = 0, rowHeight = 72, imageWidth = 140, marqueeGap = 40, marqueeDuration = 12, copies = 4, className, onSelect, align = "center", showDividers = true, menuItemClassName, marqueeBg, }) => {
const [activeIndex, setActiveIndex] = (0, react_1.useState)(Math.max(0, Math.min(defaultIndex, items.length - 1)));
const groupId = (0, react_1.useId)();
const total = items.length;
const handleSelect = (index) => {
setActiveIndex(index);
onSelect?.(index, items[index]);
};
// ── Clip-path for the marquee overlay ────────────────────────────────────
const topPct = (activeIndex / total) * 100;
const bottomPct = ((activeIndex + 1) / total) * 100;
const clipPath = `polygon(0 ${topPct}%, 100% ${topPct}%, 100% ${bottomPct}%, 0 ${bottomPct}%)`;
const alignClass = align === "left"
? "justify-start text-left"
: align === "right"
? "justify-end text-right"
: "justify-center text-center";
if (!items.length)
return null;
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("style", { children: `
@keyframes marquee-lw {
to { transform: translateX(-50%); }
}
` }), (0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.cn)("relative select-none w-full max-w-lg mx-auto", className), style: { "--row-h": `${rowHeight}px` }, children: [(0, jsx_runtime_1.jsx)("div", { className: "relative z-10 w-full", children: items.map((item, i) => ((0, jsx_runtime_1.jsxs)("label", { htmlFor: `${groupId}-${i}`, className: (0, utils_1.cn)("relative flex items-center cursor-pointer", "transition-colors duration-200", showDividers && "border-b border-border/60 last:border-b-0", alignClass, menuItemClassName), style: { height: rowHeight }, children: [(0, jsx_runtime_1.jsx)("input", { id: `${groupId}-${i}`, type: "radio", name: groupId, value: item.name, checked: activeIndex === i, onChange: () => handleSelect(i), className: "sr-only" }), (0, jsx_runtime_1.jsx)(framer_motion_1.motion.span, { className: (0, utils_1.cn)("text-lg sm:text-2xl md:text-3xl font-semibold tracking-tight transition-colors duration-200", activeIndex === i
? "text-foreground"
: "text-muted-foreground/60"), animate: { opacity: activeIndex === i ? 1 : 0.45 }, transition: { duration: 0.25 }, children: item.name })] }, item.name))) }), (0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { "aria-hidden": "true", className: (0, utils_1.cn)("absolute inset-0 pointer-events-none z-20", marqueeBg ?? "bg-background"), style: {
maskImage: "linear-gradient(90deg, transparent 0%, #000 10%, #000 90%, transparent 100%)",
WebkitMaskImage: "linear-gradient(90deg, transparent 0%, #000 10%, #000 90%, transparent 100%)",
}, animate: { clipPath }, transition: { type: "spring", bounce: 0.1, duration: 0.55 }, children: items.map((item) => ((0, jsx_runtime_1.jsx)(MarqueeRow, { item: item, rowHeight: rowHeight, imageWidth: imageWidth, gap: marqueeGap, duration: marqueeDuration, copies: copies }, item.name))) })] })] }));
};
exports.default = MarqueeMenu;
//# sourceMappingURL=marquee-menu.js.map