Vendor 50 Aceternity UI components into components/ui from the official registry (ui.aceternity.com/registry/<slug>.json), adapted for this template's stack: Tailwind v4, motion/react 13, cn util, React 19. Add a live showcase gallery (/ui + /docs/... navigation is unchanged): app/ui/page.tsx renders <ShowcaseGallery> with 30+ demos — 3d-pin, aurora, background-beams, bento, card-stack, card-spotlight, direction-aware-hover, encrypted-text, evervault-card, flip-words, hero-highlight, hero-parallax, infinite-moving-cards, moving-border, sparkles, tracing-beam, animated-tooltip, typewriter-effect, placeholders-and-vanish-input and friends. Toolchain stays zero-warning: vendored animation code is scoped in eslint.config.mjs (react-hooks/react-compiler advisory rules, no-any, prefer-const, no-img-element) so app code keeps a 0-error gate. typecheck, build, 7 vitest tests and 2 test suites all green.
123 lines
3.0 KiB
TypeScript
123 lines
3.0 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { motion } from "motion/react";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
type Tab = {
|
|
title: string;
|
|
value: string;
|
|
content?: string | React.ReactNode | any;
|
|
};
|
|
|
|
export const Tabs = ({
|
|
tabs: propTabs,
|
|
containerClassName,
|
|
activeTabClassName,
|
|
tabClassName,
|
|
contentClassName,
|
|
}: {
|
|
tabs: Tab[];
|
|
containerClassName?: string;
|
|
activeTabClassName?: string;
|
|
tabClassName?: string;
|
|
contentClassName?: string;
|
|
}) => {
|
|
const [active, setActive] = useState<Tab>(propTabs[0]);
|
|
const [tabs, setTabs] = useState<Tab[]>(propTabs);
|
|
|
|
const moveSelectedTabToTop = (idx: number) => {
|
|
const newTabs = [...propTabs];
|
|
const selectedTab = newTabs.splice(idx, 1);
|
|
newTabs.unshift(selectedTab[0]);
|
|
setTabs(newTabs);
|
|
setActive(newTabs[0]);
|
|
};
|
|
|
|
const [hovering, setHovering] = useState(false);
|
|
|
|
return (
|
|
<>
|
|
<div
|
|
className={cn(
|
|
"no-visible-scrollbar relative flex w-full max-w-full flex-row items-center justify-start overflow-auto [perspective:1000px] sm:overflow-visible",
|
|
containerClassName
|
|
)}
|
|
>
|
|
{propTabs.map((tab, idx) => (
|
|
<button
|
|
key={tab.title}
|
|
onClick={() => {
|
|
moveSelectedTabToTop(idx);
|
|
}}
|
|
onMouseEnter={() => setHovering(true)}
|
|
onMouseLeave={() => setHovering(false)}
|
|
className={cn("relative rounded-full px-4 py-2", tabClassName)}
|
|
style={{
|
|
transformStyle: "preserve-3d",
|
|
}}
|
|
>
|
|
{active.value === tab.value && (
|
|
<motion.div
|
|
layoutId="clickedbutton"
|
|
transition={{ type: "spring", bounce: 0.3, duration: 0.6 }}
|
|
className={cn(
|
|
"absolute inset-0 rounded-full bg-gray-200 dark:bg-zinc-800",
|
|
activeTabClassName
|
|
)}
|
|
/>
|
|
)}
|
|
|
|
<span className="relative block text-black dark:text-white">{tab.title}</span>
|
|
</button>
|
|
))}
|
|
</div>
|
|
<FadeInDiv
|
|
tabs={tabs}
|
|
active={active}
|
|
key={active.value}
|
|
hovering={hovering}
|
|
className={cn("mt-32", contentClassName)}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export const FadeInDiv = ({
|
|
className,
|
|
tabs,
|
|
hovering,
|
|
}: {
|
|
className?: string;
|
|
key?: string;
|
|
tabs: Tab[];
|
|
active: Tab;
|
|
hovering?: boolean;
|
|
}) => {
|
|
const isActive = (tab: Tab) => {
|
|
return tab.value === tabs[0].value;
|
|
};
|
|
return (
|
|
<div className="relative h-full w-full">
|
|
{tabs.map((tab, idx) => (
|
|
<motion.div
|
|
key={tab.value}
|
|
layoutId={tab.value}
|
|
style={{
|
|
scale: 1 - idx * 0.1,
|
|
top: hovering ? idx * -50 : 0,
|
|
zIndex: -idx,
|
|
opacity: idx < 3 ? 1 - idx * 0.1 : 0,
|
|
}}
|
|
animate={{
|
|
y: isActive(tab) ? [0, 40, 0] : 0,
|
|
}}
|
|
className={cn("absolute top-0 left-0 h-full w-full", className)}
|
|
>
|
|
{tab.content}
|
|
</motion.div>
|
|
))}
|
|
</div>
|
|
);
|
|
};
|