fumadocs-ui
Version:
The Radix UI version of Fumadocs UI
147 lines (144 loc) • 6.88 kB
JavaScript
'use client';
import { SidebarCollapseTrigger as SidebarCollapseTrigger$1, SidebarContent as SidebarContent$1, SidebarDrawerContent, SidebarDrawerOverlay, SidebarFolder as SidebarFolder$1, SidebarFolderContent as SidebarFolderContent$1, SidebarFolderLink as SidebarFolderLink$1, SidebarFolderTrigger as SidebarFolderTrigger$1, SidebarItem as SidebarItem$1, SidebarProvider, SidebarSeparator as SidebarSeparator$1, SidebarTrigger as SidebarTrigger$1, SidebarViewport as SidebarViewport$1, useFolder, useFolderDepth } from "../../components/sidebar/base.js";
import { LayoutContext } from "./client.js";
import { createLinkItemRenderer } from "../../components/sidebar/link-item.js";
import { createPageTreeRenderer } from "../../components/sidebar/page-tree.js";
import { cn } from "@fumadocs/ui/cn";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
import { use, useRef } from "react";
import { cva } from "class-variance-authority";
import { mergeRefs } from "@fumadocs/ui/merge-refs";
//#region src/layouts/notebook/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 Sidebar(props) {
return /* @__PURE__ */ jsx(SidebarProvider, { ...props });
}
function SidebarFolder(props) {
return /* @__PURE__ */ jsx(SidebarFolder$1, { ...props });
}
function SidebarCollapseTrigger(props) {
return /* @__PURE__ */ jsx(SidebarCollapseTrigger$1, { ...props });
}
function SidebarViewport(props) {
return /* @__PURE__ */ jsx(SidebarViewport$1, { ...props });
}
function SidebarTrigger(props) {
return /* @__PURE__ */ jsx(SidebarTrigger$1, { ...props });
}
function SidebarContent({ ref: refProp, className, children, ...props }) {
const { navMode } = use(LayoutContext);
const ref = useRef(null);
return /* @__PURE__ */ jsx(SidebarContent$1, { children: ({ collapsed, hovered, ref: asideRef, ...rest }) => /* @__PURE__ */ jsxs("div", {
"data-sidebar-placeholder": "",
className: cn("sticky z-20 [grid-area:sidebar] pointer-events-none *:pointer-events-auto md:layout:[--fd-sidebar-width:268px] max-md:hidden", navMode === "auto" ? "top-(--fd-docs-row-1) h-[calc(var(--fd-docs-height)-var(--fd-docs-row-1))]" : "top-(--fd-docs-row-2) h-[calc(var(--fd-docs-height)-var(--fd-docs-row-2))]"),
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 text-sm duration-250 *:w-(--fd-sidebar-width)", navMode === "auto" && "bg-fd-card border-e", collapsed && ["inset-y-2 rounded-xl bg-fd-card 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
})]
}) });
}
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 { Sidebar, SidebarCollapseTrigger, SidebarContent, SidebarDrawer, SidebarFolder, SidebarFolderContent, SidebarFolderLink, SidebarFolderTrigger, SidebarItem, SidebarLinkItem, SidebarPageTree, SidebarSeparator, SidebarTrigger, SidebarViewport };
//# sourceMappingURL=sidebar.js.map