-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Refactor site header and site header tabs components
- Loading branch information
1 parent
d7f0f57
commit 8b830d9
Showing
2 changed files
with
44 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,58 @@ | ||
"use client"; | ||
'use client' | ||
|
||
import { cn } from "@ui/lib/utils"; | ||
import Link from "next/link"; | ||
import { usePathname } from "next/navigation"; | ||
import { motion } from "framer-motion"; | ||
import { cn } from '@ui/lib/utils' | ||
import { motion } from 'framer-motion' | ||
import Link from 'next/link' | ||
import { usePathname } from 'next/navigation' | ||
|
||
function SiteHeaderTabs() { | ||
const pathname = usePathname(); | ||
const acitvePath = pathname.split("/")[1]; | ||
const pathname = usePathname() | ||
const acitvePath = pathname.split('/')[1] | ||
const tabs = [ | ||
{ | ||
name: "Palette", | ||
href: "/", | ||
isActive: acitvePath === "", | ||
href: '/', | ||
isActive: acitvePath === '', | ||
name: 'Palette', | ||
}, | ||
{ | ||
name: "Visualizer", | ||
href: "/visualizer", | ||
isActive: acitvePath === "visualizer", | ||
href: '/visualizer', | ||
isActive: acitvePath === 'visualizer', | ||
name: 'Visualizer', | ||
}, | ||
{ | ||
name: "Code", | ||
href: "/code", | ||
isActive: acitvePath === "code", | ||
href: '/code', | ||
isActive: acitvePath === 'code', | ||
name: 'Code', | ||
}, | ||
]; | ||
] | ||
return ( | ||
<div className="max-w-xs"> | ||
<div className="grid w-full grid-cols-3 items-center justify-center rounded-md border border-border bg-muted p-1 text-muted-foreground"> | ||
<div className="transition-bg grid w-full grid-cols-3 items-center justify-center rounded-md border border-border bg-muted p-1 text-muted-foreground"> | ||
{tabs.map((tab, index) => ( | ||
<Link | ||
key={index} | ||
className={cn( | ||
"relative inline-flex items-center justify-center whitespace-nowrap rounded-sm px-2.5 py-[0.1875rem] text-sm ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", | ||
"hover:text-foreground focus:text-foreground", | ||
tab.isActive ? "text-foreground" : "text-muted-foreground", | ||
'relative inline-flex items-center justify-center whitespace-nowrap rounded-sm px-2.5 py-[0.1875rem] text-sm ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50', | ||
'hover:text-foreground focus:text-foreground', | ||
tab.isActive ? 'text-foreground' : 'text-muted-foreground' | ||
)} | ||
href={tab.href} | ||
key={index} | ||
> | ||
<span className="relative isolate z-10">{tab.name}</span> | ||
{tab.isActive && ( | ||
<motion.span | ||
layoutId="site-header-tab-indicator" | ||
className={cn( | ||
"absolute inset-0 z-0 h-full w-full rounded-sm", | ||
tab.isActive && "bg-background shadow", | ||
'transition-bg absolute inset-0 z-0 h-full w-full rounded-sm', | ||
tab.isActive && 'bg-background shadow' | ||
)} | ||
layoutId="site-header-tab-indicator" | ||
/> | ||
)} | ||
</Link> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
) | ||
} | ||
|
||
export default SiteHeaderTabs; | ||
export default SiteHeaderTabs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters