UNPKG

fumadocs-ui

Version:

The Radix UI version of Fumadocs UI

147 lines (144 loc) 6.92 kB
'use client'; import { buttonVariants } from "../../components/ui/button.js"; import { SidebarCollapseTrigger, SidebarContent as SidebarContent$1, SidebarDrawerContent, SidebarDrawerOverlay, SidebarFolder, SidebarFolderContent as SidebarFolderContent$1, SidebarFolderLink as SidebarFolderLink$1, SidebarFolderTrigger as SidebarFolderTrigger$1, SidebarItem as SidebarItem$1, SidebarProvider, SidebarSeparator as SidebarSeparator$1, SidebarTrigger, SidebarViewport, useFolder, useFolderDepth } from "../../components/sidebar/base.js"; import { createLinkItemRenderer } from "../../components/sidebar/link-item.js"; import { createPageTreeRenderer } from "../../components/sidebar/page-tree.js"; import { SearchToggle } from "../shared/search-toggle.js"; import { cn } from "@fumadocs/ui/cn"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; import { Sidebar } from "lucide-react"; import { useRef } from "react"; import { cva } from "class-variance-authority"; import { mergeRefs } from "@fumadocs/ui/merge-refs"; //#region src/layouts/docs/sidebar.tsx const itemVariants = cva("relative flex flex-row items-center gap-2 rounded-lg p-2 text-start text-fd-muted-foreground wrap-anywhere [&_svg]:size-4 [&_svg]:shrink-0", { variants: { variant: { link: "transition-colors hover:bg-fd-accent/50 hover:text-fd-accent-foreground/80 hover:transition-none data-[active=true]:bg-fd-primary/10 data-[active=true]:text-fd-primary data-[active=true]:hover:transition-colors", button: "transition-colors hover:bg-fd-accent/50 hover:text-fd-accent-foreground/80 hover:transition-none" }, highlight: { true: "data-[active=true]:before:content-[''] data-[active=true]:before:bg-fd-primary data-[active=true]:before:absolute data-[active=true]:before:w-px data-[active=true]:before:inset-y-2.5 data-[active=true]:before:start-2.5" } } }); function getItemOffset(depth) { return `calc(${2 + 3 * depth} * var(--spacing))`; } function SidebarContent({ ref: refProp, className, children, ...props }) { const ref = useRef(null); return /* @__PURE__ */ jsx(SidebarContent$1, { children: ({ collapsed, hovered, ref: asideRef, ...rest }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", { "data-sidebar-placeholder": "", className: "sticky top-(--fd-docs-row-1) z-20 [grid-area:sidebar] pointer-events-none *:pointer-events-auto h-[calc(var(--fd-docs-height)-var(--fd-docs-row-1))] md:layout:[--fd-sidebar-width:268px] max-md:hidden", children: [collapsed && /* @__PURE__ */ jsx("div", { className: "absolute start-0 inset-y-0 w-4", ...rest }), /* @__PURE__ */ jsx("aside", { id: "nd-sidebar", ref: mergeRefs(ref, refProp, asideRef), "data-collapsed": collapsed, "data-hovered": collapsed && hovered, className: cn("absolute flex flex-col w-full start-0 inset-y-0 items-end bg-fd-card text-sm border-e duration-250 *:w-(--fd-sidebar-width)", collapsed && ["inset-y-2 rounded-xl transition-transform border w-(--fd-sidebar-width)", hovered ? "shadow-lg translate-x-2 rtl:-translate-x-2" : "-translate-x-(--fd-sidebar-width) rtl:translate-x-full"], ref.current && ref.current.getAttribute("data-collapsed") === "true" !== collapsed && "transition-[width,inset-block,translate,background-color]", className), ...props, ...rest, children })] }), /* @__PURE__ */ jsxs("div", { "data-sidebar-panel": "", className: cn("fixed flex top-[calc(--spacing(4)+var(--fd-docs-row-3))] start-4 shadow-lg transition-opacity rounded-xl p-0.5 border bg-fd-muted text-fd-muted-foreground z-10", (!collapsed || hovered) && "pointer-events-none opacity-0"), children: [/* @__PURE__ */ jsx(SidebarCollapseTrigger, { className: cn(buttonVariants({ color: "ghost", size: "icon-sm", className: "rounded-lg" })), children: /* @__PURE__ */ jsx(Sidebar, {}) }), /* @__PURE__ */ jsx(SearchToggle, { className: "rounded-lg", hideIfDisabled: true })] })] }) }); } function SidebarDrawer({ children, className, ...props }) { return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(SidebarDrawerOverlay, { className: "fixed z-40 inset-0 backdrop-blur-xs data-[state=open]:animate-fd-fade-in data-[state=closed]:animate-fd-fade-out" }), /* @__PURE__ */ jsx(SidebarDrawerContent, { className: cn("fixed text-[0.9375rem] flex flex-col shadow-lg border-s end-0 inset-y-0 w-[85%] max-w-[380px] z-40 bg-fd-background data-[state=open]:animate-fd-sidebar-in data-[state=closed]:animate-fd-sidebar-out", className), ...props, children })] }); } function SidebarSeparator({ className, style, children, ...props }) { const depth = useFolderDepth(); return /* @__PURE__ */ jsx(SidebarSeparator$1, { className: cn("[&_svg]:size-4 [&_svg]:shrink-0", className), style: { paddingInlineStart: getItemOffset(depth), ...style }, ...props, children }); } function SidebarItem({ className, style, children, ...props }) { const depth = useFolderDepth(); return /* @__PURE__ */ jsx(SidebarItem$1, { className: cn(itemVariants({ variant: "link", highlight: depth >= 1 }), className), style: { paddingInlineStart: getItemOffset(depth), ...style }, ...props, children }); } function SidebarFolderTrigger({ className, style, ...props }) { const { depth, collapsible } = useFolder(); return /* @__PURE__ */ jsx(SidebarFolderTrigger$1, { className: cn(itemVariants({ variant: collapsible ? "button" : null }), "w-full", className), style: { paddingInlineStart: getItemOffset(depth - 1), ...style }, ...props, children: props.children }); } function SidebarFolderLink({ className, style, ...props }) { const depth = useFolderDepth(); return /* @__PURE__ */ jsx(SidebarFolderLink$1, { className: cn(itemVariants({ variant: "link", highlight: depth > 1 }), "w-full", className), style: { paddingInlineStart: getItemOffset(depth - 1), ...style }, ...props, children: props.children }); } function SidebarFolderContent({ className, children, ...props }) { const depth = useFolderDepth(); return /* @__PURE__ */ jsx(SidebarFolderContent$1, { className: cn("relative", depth === 1 && "before:content-[''] before:absolute before:w-px before:inset-y-1 before:bg-fd-border before:start-2.5", className), ...props, children }); } const SidebarPageTree = createPageTreeRenderer({ SidebarFolder, SidebarFolderContent, SidebarFolderLink, SidebarFolderTrigger, SidebarItem, SidebarSeparator }); const SidebarLinkItem = createLinkItemRenderer({ SidebarFolder, SidebarFolderContent, SidebarFolderLink, SidebarFolderTrigger, SidebarItem }); //#endregion export { SidebarProvider as Sidebar, SidebarCollapseTrigger, SidebarContent, SidebarDrawer, SidebarFolder, SidebarFolderContent, SidebarFolderLink, SidebarFolderTrigger, SidebarItem, SidebarLinkItem, SidebarPageTree, SidebarSeparator, SidebarTrigger, SidebarViewport }; //# sourceMappingURL=sidebar.js.map