Morphing Navigation Bar
Morphing Navigation Bar é um componente de texto para React e Tailwind CSS, da biblioteca Kokonut UI, com licença MIT. Copia e cola no teu projeto.
Kokonut UI
MIT
text
O que é
Morphing Navigation Bar é um componente de texto para React e Tailwind CSS, da biblioteca Kokonut UI, com licença MIT. Copia e cola no teu projeto.
Como usar
Abre o componente no catálogo, carrega em copiar, e cola no teu projeto. O prompt copiado leva o código e as regras para o teu agente o reproduzir sem alterar nada.
Cinco cópias grátis por mês. Sem cartão.
Precisa de
npm i clsx
Licença
Este componente vem de Kokonut UI e é redistribuído sob a licença MIT, que permite uso comercial. O aviso de copyright viaja com o código.
Morphing Navigation Bar
"use client";
import clsx from "clsx";
import Link from "next/link";
import { useState } from "react";
interface NavItem {
name: string;
}
interface MorphicNavbarProps {
items?: Record<string, NavItem>;
defaultPath?: string;
className?: string;
}
const DEFAULT_NAV_ITEMS: Record<string, NavItem> = {
"/": { name: "home" },
"/works": { name: "works" },
"/blog": { name: "blog" },
"/about": { name: "about" },
};
export function MorphicNavbar({
items = DEFAULT_NAV_ITEMS,
defaultPath = "/",
className,
}: MorphicNavbarProps) {
const [activePath, setActivePath] = useState(defaultPath);
const isActiveLink = (path: string) => {
if (path === "/") {
return activePath === "/";
}
return activePath.startsWith(path);
};
return (
<nav className={clsx("mx-auto max-w-4xl px-4 py-2", className)}>
<div className="flex items-center justify-center">
<div className="glass flex items-center justify-between overflow-hidden rounded-xl">
{Object.entries(items).map(([path, { name }], index, array) => {
const isActive = isActiveLink(path);
const isFirst = index === 0;
const isLast = index === array.length - 1;
const prevPath = index > 0 ? array[index - 1][0] : null;
const nextPath =
index < array.length - 1 ? array[index + 1][0] : null;
return (
<Link
className={clsx(
"flex items-center justify-center bg-black p-1.5 px-4 text-sm text-white transition-all duration-300 dark:bg-white dark:text-black",
isActive
? "mx-2 rounded-xl font-semibold text-sm"
: clsx(
(isActiveLink(prevPath || "") || isFirst) &&
"rounded-l-xl",
(isActiveLink(nextPath || "") || isLast) &&
"rounded-r-xl"
)
)}
href="#"
key={path}
onClick={() => setActivePath(path)}
>
{name}
</Link>
);
})}
</div>
</div>
</nav>
);
}
export default MorphicNavbar;