Files
shadcn-ui/apps/www/components/examples-nav.tsx
shadcn f78a4aaa28 chore(www): site updates (#829)
* chore(www): update to latest Next.js

* feat(www): replace lucide icons
2023-07-04 17:04:22 +04:00

104 lines
2.8 KiB
TypeScript

"use client"
import Link from "next/link"
import { usePathname } from "next/navigation"
import { ArrowRightIcon } from "@radix-ui/react-icons"
import { cn } from "@/lib/utils"
import { ScrollArea, ScrollBar } from "@/registry/new-york/ui/scroll-area"
const examples = [
{
name: "Dashboard",
href: "/examples/dashboard",
code: "https://github.com/shadcn/ui/tree/main/apps/www/app/examples/dashboard",
},
{
name: "Cards",
href: "/examples/cards",
code: "https://github.com/shadcn/ui/tree/main/apps/www/app/examples/cards",
},
{
name: "Tasks",
href: "/examples/tasks",
code: "https://github.com/shadcn/ui/tree/main/apps/www/app/examples/tasks",
},
{
name: "Playground",
href: "/examples/playground",
code: "https://github.com/shadcn/ui/tree/main/apps/www/app/examples/playground",
},
{
name: "Forms",
href: "/examples/forms",
code: "https://github.com/shadcn/ui/tree/main/apps/www/app/examples/forms",
},
{
name: "Music",
href: "/examples/music",
code: "https://github.com/shadcn/ui/tree/main/apps/www/app/examples/music",
},
{
name: "Authentication",
href: "/examples/authentication",
code: "https://github.com/shadcn/ui/tree/main/apps/www/app/examples/authentication",
},
]
interface ExamplesNavProps extends React.HTMLAttributes<HTMLDivElement> {}
export function ExamplesNav({ className, ...props }: ExamplesNavProps) {
const pathname = usePathname()
return (
<div className="relative">
<ScrollArea className="max-w-[600px] lg:max-w-none">
<div className={cn("mb-4 flex items-center", className)} {...props}>
{examples.map((example) => (
<Link
href={example.href}
key={example.href}
className={cn(
"flex items-center px-4",
pathname?.startsWith(example.href)
? "font-bold text-primary"
: "font-medium text-muted-foreground"
)}
>
{example.name}
</Link>
))}
</div>
<ScrollBar orientation="horizontal" className="invisible" />
</ScrollArea>
<ExampleCodeLink
pathname={pathname === "/" ? "/examples/dashboard" : pathname}
/>
</div>
)
}
interface ExampleCodeLinkProps {
pathname: string | null
}
export function ExampleCodeLink({ pathname }: ExampleCodeLinkProps) {
const example = examples.find((example) => pathname?.startsWith(example.href))
if (!example?.code) {
return null
}
return (
<Link
href={example?.code}
target="_blank"
rel="nofollow"
className="absolute right-0 top-0 hidden items-center rounded-[0.5rem] text-sm font-medium md:flex"
>
View code
<ArrowRightIcon className="ml-1 h-4 w-4" />
</Link>
)
}