UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
🐛 fix: add pager, add share links back
Dillion Verma49c0d60ff10e
diff --git a/app/(docs)/components/[slug]/page.tsx b/app/(docs)/components/[slug]/page.tsxindex c653e076..379c1624 100644--- a/app/(docs)/components/[slug]/page.tsx+++ b/app/(docs)/components/[slug]/page.tsx@@ -1,4 +1,8 @@+import Facebook from "@/components/icons/facebook";+import LinkedIn from "@/components/icons/linkedin";+import Twitter from "@/components/icons/twitter";import { Mdx } from "@/components/mdx-components";+import { ComponentPager } from "@/components/pager";import { DashboardTableOfContents } from "@/components/toc";import { ScrollArea } from "@/components/ui/scroll-area";import { getTableOfContents } from "@/lib/toc";@@ -116,10 +120,10 @@ export default async function Component({ params }: Props) {)}</div>- {/* <div className="mt-4 flex items-center justify-between">+ <div className="mt-4 flex items-center justify-between"><div className="flex items-center space-x-6"><Link- href={`https://twitter.com/intent/tweet?text=${component.title}&url=magicuikit.com/components/${component.slugAsParams}&via=${component.author}`}+ href={`https://twitter.com/intent/tweet?text=${component.title}&url=magicui.design/components/${component.slugAsParams}&via=${component.author}`}target="_blank"rel="noopener noreferrer">@@ -127,23 +131,26 @@ export default async function Component({ params }: Props) {</Link><Linkhref={`- http://www.linkedin.com/shareArticle?mini=true&url=https://magicuikit.com/components/${component.slugAsParams}`}+ http://www.linkedin.com/shareArticle?mini=true&url=https://magicui.design/components/${component.slugAsParams}`}target="_blank"rel="noopener noreferrer"><LinkedIn className="h-6 w-6" /></Link><Link- href={`https://www.facebook.com/sharer/sharer.php?u=https://magicuikit.com/components/${component.slugAsParams}`}+ href={`https://www.facebook.com/sharer/sharer.php?u=https://magicui.design/components/${component.slugAsParams}`}target="_blank"rel="noopener noreferrer"><Facebook className="h-6 w-6" /></Link></div>- </div> */}+ </div>- <Mdx code={component.body.code} />+ <div className="pb-12 pt-8">+ <Mdx code={component.body.code} />+ </div>+ <ComponentPager doc={component} /></div>{component.toc && (diff --git a/components/pager.tsx b/components/pager.tsxnew file mode 100644index 00000000..111d3983--- /dev/null+++ b/components/pager.tsx@@ -0,0 +1,66 @@+import { buttonVariants } from "@/components/ui/button";+import { docsConfig } from "@/config/docs";+import { cn } from "@/lib/utils";+import { NavItem, NavItemWithChildren } from "@/types";+import { ChevronLeftIcon, ChevronRightIcon } from "@radix-ui/react-icons";+import { Component } from "contentlayer/generated";+import Link from "next/link";++interface DocsPagerProps {+ doc: Component;+}++export function ComponentPager({ doc }: DocsPagerProps) {+ const pager = getPagerForDoc(doc);++ if (!pager) {+ return null;+ }++ return (+ <div className="flex flex-row items-center justify-between">+ {pager?.prev?.href && (+ <Link+ href={pager.prev.href}+ className={buttonVariants({ variant: "outline" })}+ >+ <ChevronLeftIcon className="mr-2 h-4 w-4" />+ {pager.prev.title}+ </Link>+ )}+ {pager?.next?.href && (+ <Link+ href={pager.next.href}+ className={cn(buttonVariants({ variant: "outline" }), "ml-auto")}+ >+ {pager.next.title}+ <ChevronRightIcon className="ml-2 h-4 w-4" />+ </Link>+ )}+ </div>+ );+}++export function getPagerForDoc(doc: Component) {+ const flattenedLinks = [null, ...flatten(docsConfig.sidebarNav), null];+ const activeIndex = flattenedLinks.findIndex(+ (link) => doc.slug === link?.href,+ );+ const prev = activeIndex !== 0 ? flattenedLinks[activeIndex - 1] : null;+ const next =+ activeIndex !== flattenedLinks.length - 1+ ? flattenedLinks[activeIndex + 1]+ : null;+ return {+ prev,+ next,+ };+}++export function flatten(links: NavItemWithChildren[]): NavItem[] {+ return links+ .reduce<NavItem[]>((flat, link) => {+ return flat.concat(link.items?.length ? flatten(link.items) : link);+ }, [])+ .filter((link) => !link?.disabled);+}