A dynamic, animated pill-shaped navigation component that morphs to highlight the active and hovered states.
To add the Morphing Pill to your project, run the following command:
Before you begin, ensure your project meets the following requirements:
Follow these steps to integrate the Morphing Pill into your project.
Install the necessary dependencies for the component and its underlying libraries:
You'll also need tailwindcss-animate if you haven't already installed it for other shadcn/ui components:
tailwind.config.jsEnsure tailwindcss-animate is added to your Tailwind CSS configuration:
// tailwind.config.js
module.exports = {
// ... other configurations
plugins: [
require("tailwindcss-animate"),
// ... other plugins
],
};cn Utility FunctionIf you don't already have it from installing other shadcn/ui components, create a utility file, typically utils.ts (or utils.js), inside a lib folder (e.g., @/lib/utils.ts or src/lib/utils.ts). This file will contain a helper function cn for conditionally joining class names.
Paste the following code into lib/utils.ts:
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}Ensure your tsconfig.json or jsconfig.json is set up for path aliases if you're using them (e.g., "@/lib/cn"). Example for tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"] // Adjust if your lib folder is not in src
}
// ... other compiler options
}
}.center)The MorphingPill component internally uses a class center. If not already defined globally in your project (e.g. from other components or a general utility stylesheet), you can add it:
/* Your global CSS file (e.g., app.css, globals.css, index.css) */
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer utilities {
.center {
@apply flex items-center justify-center;
}
/* Add other custom utilities here if needed */
}Alternatively, you can modify the component's source code to use flex items-center justify-center directly where center is used.
After installation and setup, you can import and use the MorphingPill component in your React application:
import MorphingPill from "@/components/ui/morphing-pill"; // Adjust path based on your installation location
export default function MyPage() {
return (
<div className="flex h-screen items-center justify-center">
<MorphingPill />
</div>
);
}The MorphingPill component is self-contained and manages its own state for the interactive elements. The default items are defined within the component. For customization (e.g., different items, icons, colors), you would need to modify the component's source code directly after installation.