UNPKG

fumadocs-ui

Version:

The Radix UI version of Fumadocs UI

93 lines (92 loc) 3.08 kB
"use client"; import { cn } from "../../../utils/cn.js"; import { buttonVariants } from "../../../components/ui/button.js"; import { MarkdownCopyButton, ViewOptionsPopover } from "../../shared/page-actions.js"; import { Footer } from "./slots/footer.js"; import { Breadcrumb } from "./slots/breadcrumb.js"; import { TOC, TOCProvider } from "./slots/toc.js"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; import { Edit } from "lucide-react"; import { createContext, use, useEffect, useState } from "react"; import { useTranslations } from "@fuma-translate/react"; //#region src/layouts/glass/page/index.tsx const PageContext = createContext(null); function useDocsPage() { const context = use(PageContext); if (!context) throw new Error("Please use page components under <DocsPage /> (`fumadocs-ui/layouts/glass/page`)."); return context; } const Empty = []; function DocsPage({ full = false, toc = Empty, tableOfContent, children }) { return /* @__PURE__ */ jsx(PageContext, { value: { full }, children: /* @__PURE__ */ jsxs(TOCProvider, { toc, children: [/* @__PURE__ */ jsxs("div", { "data-fd-full": full, className: cn("flex flex-col gap-2 p-6 pb-16 min-w-0 [grid-area:main] md:pt-16 md:pb-8", full && "layout:[--fd-main-width:1200px]"), children: [ /* @__PURE__ */ jsx(Breadcrumb, {}), children, /* @__PURE__ */ jsx(Footer, {}) ] }), /* @__PURE__ */ jsx(TOC, { ...tableOfContent })] }) }); } function EditOnGitHub(props) { const t = useTranslations({ note: "edit page" }); return /* @__PURE__ */ jsx("a", { target: "_blank", rel: "noreferrer noopener", ...props, className: cn(buttonVariants({ color: "secondary", size: "sm" }), "gap-1.5 not-prose", props.className), children: props.children ?? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Edit, { className: "size-3.5" }), t("Edit on GitHub")] }) }); } /** * Add typography styles */ function DocsBody({ children, className, ...props }) { return /* @__PURE__ */ jsx("div", { ...props, className: cn("prose flex-1", className), children }); } function DocsDescription({ children, className, ...props }) { if (children === void 0) return null; return /* @__PURE__ */ jsx("p", { ...props, className: cn("mb-8 text-lg text-fd-muted-foreground", className), children }); } function DocsTitle({ children, className, ...props }) { return /* @__PURE__ */ jsx("h1", { ...props, className: cn("text-[1.75em] font-semibold", className), children }); } function PageLastUpdate({ date: value, ...props }) { const t = useTranslations({ note: "page footer" }); const [date, setDate] = useState(""); useEffect(() => { setDate(value.toLocaleDateString()); }, [value]); return /* @__PURE__ */ jsxs("p", { ...props, className: cn("text-sm text-fd-muted-foreground", props.className), children: [ t("Last updated on"), " ", date ] }); } //#endregion export { DocsBody, DocsDescription, DocsPage, DocsTitle, EditOnGitHub, MarkdownCopyButton, PageLastUpdate, ViewOptionsPopover, useDocsPage };