@fumadocs/base-ui 16.15.18 → 16.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/css/generated/docs.css +1 -1
  2. package/css/generated/flux.css +1 -1
  3. package/css/generated/glass.css +1 -1
  4. package/css/generated/notebook.css +1 -1
  5. package/css/generated/shared.css +1 -1
  6. package/css/generated/spacious.css +1 -0
  7. package/css/lib/base.css +26 -1
  8. package/dist/.translations/index.d.ts +3 -0
  9. package/dist/.translations/keys.js +3 -0
  10. package/dist/components/toc/block.js +4 -2
  11. package/dist/layouts/docs/client.d.ts +1 -0
  12. package/dist/layouts/docs/client.js +9 -3
  13. package/dist/layouts/docs/index.d.ts +2 -1
  14. package/dist/layouts/docs/page/slots/toc.js +2 -1
  15. package/dist/layouts/docs/slots/container.js +1 -8
  16. package/dist/layouts/glass/index.d.ts +11 -13
  17. package/dist/layouts/glass/index.js +11 -6
  18. package/dist/layouts/glass/page/slots/toc.js +3 -1
  19. package/dist/layouts/glass/slots/header.js +1 -1
  20. package/dist/layouts/notebook/client.d.ts +1 -0
  21. package/dist/layouts/notebook/client.js +9 -3
  22. package/dist/layouts/notebook/index.d.ts +2 -1
  23. package/dist/layouts/notebook/page/slots/toc.js +2 -1
  24. package/dist/layouts/notebook/slots/container.js +6 -12
  25. package/dist/layouts/shared/client.d.ts +1 -1
  26. package/dist/layouts/shared/client.js +17 -1
  27. package/dist/layouts/shared/index.d.ts +8 -0
  28. package/dist/layouts/spacious/index.d.ts +37 -0
  29. package/dist/layouts/spacious/index.js +80 -0
  30. package/dist/layouts/spacious/page/index.d.ts +56 -0
  31. package/dist/layouts/spacious/page/index.js +150 -0
  32. package/dist/layouts/spacious/page/slots/breadcrumb.d.ts +10 -0
  33. package/dist/layouts/spacious/page/slots/breadcrumb.js +51 -0
  34. package/dist/layouts/spacious/page/slots/footer.d.ts +15 -0
  35. package/dist/layouts/spacious/page/slots/footer.js +61 -0
  36. package/dist/layouts/spacious/page/slots/toc.d.ts +44 -0
  37. package/dist/layouts/spacious/page/slots/toc.js +208 -0
  38. package/dist/layouts/spacious/slots/actions.d.ts +5 -0
  39. package/dist/layouts/spacious/slots/actions.js +224 -0
  40. package/dist/layouts/spacious/slots/header.d.ts +5 -0
  41. package/dist/layouts/spacious/slots/header.js +34 -0
  42. package/dist/layouts/spacious/slots/sidebar.d.ts +9 -0
  43. package/dist/layouts/spacious/slots/sidebar.js +305 -0
  44. package/dist/style.css +600 -18
  45. package/package.json +17 -9
@@ -0,0 +1,305 @@
1
+ "use client";
2
+ import { cn } from "../../../utils/cn.js";
3
+ import { buttonVariants } from "../../../components/ui/button.js";
4
+ import { useTabsGroups, useTreePath } from "../../../contexts/tree.js";
5
+ import { LinkItem } from "../../shared/client.js";
6
+ import { isLayoutTabActive } from "../../shared/index.js";
7
+ import { SidebarCollapseTrigger, SidebarDrawerContent, SidebarDrawerOverlay, SidebarFolder, SidebarFolderContent as SidebarFolderContent$1, SidebarFolderLink as SidebarFolderLink$1, SidebarFolderTrigger as SidebarFolderTrigger$1, SidebarItem as SidebarItem$1, SidebarProvider as SidebarProvider$1, SidebarSeparator as SidebarSeparator$1, SidebarTrigger, useFolderDepth, useSidebar } from "../../../components/sidebar/base.js";
8
+ import { createPageTreeRenderer } from "../../../components/sidebar/page-tree.js";
9
+ import { createLinkItemRenderer } from "../../../components/sidebar/link-item.js";
10
+ import { useSpaciousLayout } from "../index.js";
11
+ import Link from "fumadocs-core/link";
12
+ import { usePathname } from "fumadocs-core/framework";
13
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
14
+ import { CheckIcon, ChevronsUpDownIcon, LanguagesIcon, MessageCircleIcon, SidebarIcon } from "lucide-react";
15
+ import { cva } from "class-variance-authority";
16
+ import { useTranslations } from "@fuma-translate/react";
17
+ import { ScrollArea } from "@base-ui/react/scroll-area";
18
+ import { Menu } from "@base-ui/react/menu";
19
+ //#region src/layouts/spacious/slots/sidebar.tsx
20
+ /** the hover fill comes from the gliding block of `SidebarItems` */
21
+ const itemVariants = cva("relative flex w-full items-center gap-3 rounded-lg px-2.5 py-2 text-start wrap-anywhere outline-none transition-colors focus-visible:ring-2 focus-visible:ring-fd-ring [&_svg]:size-4 [&_svg]:shrink-0", {
22
+ variants: { active: {
23
+ true: "bg-fd-primary/10 text-fd-primary",
24
+ false: "text-fd-muted-foreground hover:text-fd-accent-foreground"
25
+ } },
26
+ defaultVariants: { active: false }
27
+ });
28
+ const activeLine = /* @__PURE__ */ jsx("span", { className: "absolute -start-1 inset-y-2 w-px bg-fd-primary" });
29
+ function SidebarProvider(props) {
30
+ return /* @__PURE__ */ jsx(SidebarProvider$1, { ...props });
31
+ }
32
+ function Sidebar({ className, ...props }) {
33
+ const { collapsed, mode } = useSidebar();
34
+ const { slots } = useSpaciousLayout();
35
+ if (mode !== "full") return;
36
+ return /* @__PURE__ */ jsx("aside", {
37
+ id: "nd-sidebar",
38
+ "data-collapsed": collapsed,
39
+ inert: collapsed,
40
+ className: cn("[grid-area:sidebar] flex min-h-0 overflow-clip text-sm md:layout:[--fd-sidebar-width:268px] max-md:hidden", collapsed && "md:layout:[--fd-sidebar-col:--spacing(2)]", className),
41
+ ...props,
42
+ children: /* @__PURE__ */ jsxs("div", {
43
+ className: cn("flex flex-col shrink-0 w-(--fd-sidebar-width) transition-[opacity,translate] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none", collapsed && "-translate-x-3 opacity-0 rtl:translate-x-3"),
44
+ children: [
45
+ /* @__PURE__ */ jsxs("div", {
46
+ className: "flex items-center gap-2 h-(--fd-header-height) my-2 ps-5.5 pe-3",
47
+ children: [/* @__PURE__ */ jsx(slots.navTitle, { className: "inline-flex items-center gap-2 min-w-0 me-auto text-[0.9375rem] font-semibold" }), /* @__PURE__ */ jsx(SidebarCollapseTrigger, {
48
+ className: cn(buttonVariants({
49
+ variant: "ghost",
50
+ size: "icon-sm"
51
+ }), "size-8 text-fd-muted-foreground"),
52
+ children: /* @__PURE__ */ jsx(SidebarIcon, {})
53
+ })]
54
+ }),
55
+ /* @__PURE__ */ jsxs("div", {
56
+ className: "flex flex-col gap-2 px-3 empty:hidden",
57
+ children: [/* @__PURE__ */ jsx(TabsMenu, {}), slots.searchTrigger && /* @__PURE__ */ jsx(slots.searchTrigger.full, {
58
+ hideIfDisabled: true,
59
+ className: "h-10 gap-3 rounded-xl ps-[calc(--spacing(2.5)-1px)] pe-2 [&_svg]:shrink-0"
60
+ })]
61
+ }),
62
+ /* @__PURE__ */ jsx(SidebarViewport, {})
63
+ ]
64
+ })
65
+ });
66
+ }
67
+ function SidebarDrawer() {
68
+ const { setOpen } = useSidebar();
69
+ const { slots, menuItems, props: { aiChat } } = useSpaciousLayout();
70
+ const t = useTranslations({ note: "AI chat button" });
71
+ 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__ */ jsxs(SidebarDrawerContent, {
72
+ className: "fixed z-40 inset-e-0 inset-y-0 flex flex-col w-[85%] max-w-[380px] text-[0.9375rem] bg-fd-background border-s shadow-lg data-[state=open]:animate-fd-sidebar-in data-[state=closed]:animate-fd-sidebar-out",
73
+ children: [
74
+ /* @__PURE__ */ jsxs("div", {
75
+ className: "flex items-center gap-1.5 h-(--fd-header-height) ps-3.5 pe-2.5 text-fd-muted-foreground",
76
+ children: [
77
+ /* @__PURE__ */ jsx("div", {
78
+ className: "flex flex-1",
79
+ children: menuItems.map((item, i) => item.type === "icon" && /* @__PURE__ */ jsx(LinkItem, {
80
+ item,
81
+ "aria-label": item.label,
82
+ className: buttonVariants({
83
+ variant: "ghost",
84
+ size: "icon-sm",
85
+ className: "p-2"
86
+ }),
87
+ children: item.icon
88
+ }, i))
89
+ }),
90
+ slots.languageSelect && /* @__PURE__ */ jsxs(slots.languageSelect.root, { children: [/* @__PURE__ */ jsx(LanguagesIcon, { className: "size-4.5" }), /* @__PURE__ */ jsx(slots.languageSelect.text, {})] }),
91
+ slots.themeSwitch && /* @__PURE__ */ jsx(slots.themeSwitch, { className: "p-0" }),
92
+ /* @__PURE__ */ jsx(SidebarTrigger, {
93
+ className: buttonVariants({
94
+ variant: "ghost",
95
+ size: "icon-sm",
96
+ className: "p-2"
97
+ }),
98
+ children: /* @__PURE__ */ jsx(SidebarIcon, {})
99
+ })
100
+ ]
101
+ }),
102
+ /* @__PURE__ */ jsxs("div", {
103
+ className: "flex flex-col gap-2 px-3 empty:hidden",
104
+ children: [/* @__PURE__ */ jsx(TabsMenu, {}), aiChat && /* @__PURE__ */ jsxs("button", {
105
+ type: "button",
106
+ className: cn(itemVariants(), "hover:bg-fd-accent/60"),
107
+ onClick: () => {
108
+ setOpen(false);
109
+ aiChat.onOpenChange(true);
110
+ },
111
+ children: [/* @__PURE__ */ jsx(MessageCircleIcon, {}), t("Ask AI")]
112
+ })]
113
+ }),
114
+ /* @__PURE__ */ jsx(SidebarViewport, {})
115
+ ]
116
+ })] });
117
+ }
118
+ function TabsMenu() {
119
+ const { props: { tabs } } = useSpaciousLayout();
120
+ const t = useTranslations();
121
+ const pathname = usePathname();
122
+ const path = useTreePath();
123
+ const options = useTabsGroups(tabs).findLast((group) => typeof group.active?.root !== "string")?.options ?? [];
124
+ const selected = options.findLast((tab) => isLayoutTabActive(tab, path, pathname));
125
+ if (options.length === 0) return;
126
+ return /* @__PURE__ */ jsxs(Menu.Root, { children: [/* @__PURE__ */ jsxs(Menu.Trigger, {
127
+ className: "flex w-full h-10 items-center gap-3 rounded-xl border bg-fd-secondary/50 ps-[calc(--spacing(2.5)-1px)] pe-2.5 text-start font-medium outline-none transition-colors hover:bg-fd-accent focus-visible:ring-2 focus-visible:ring-fd-ring data-popup-open:bg-fd-accent [&_svg]:size-4 [&_svg]:shrink-0",
128
+ children: [
129
+ selected && /* @__PURE__ */ jsx(TabIcon, { tab: selected }),
130
+ /* @__PURE__ */ jsx("span", {
131
+ className: cn("flex-1 truncate", !selected && "text-fd-muted-foreground"),
132
+ children: selected ? selected.title : t("Layout Tab", { note: "layout tab trigger" })
133
+ }),
134
+ /* @__PURE__ */ jsx(ChevronsUpDownIcon, { className: "size-3.5! text-fd-muted-foreground" })
135
+ ]
136
+ }), /* @__PURE__ */ jsx(Menu.Portal, { children: /* @__PURE__ */ jsx(Menu.Positioner, {
137
+ align: "start",
138
+ sideOffset: 8,
139
+ alignOffset: -4,
140
+ positionMethod: "fixed",
141
+ className: "z-50",
142
+ children: /* @__PURE__ */ jsx(Menu.Popup, {
143
+ className: "flex flex-col w-[calc(var(--anchor-width)+--spacing(2))] max-h-(--available-height) overflow-y-auto p-1 rounded-2xl border bg-fd-popover text-sm text-fd-popover-foreground shadow-lg outline-none origin-(--transform-origin) transition-[opacity,scale] duration-150 ease-[cubic-bezier(0.22,1,0.36,1)] data-starting-style:opacity-0 data-starting-style:scale-95 data-ending-style:opacity-0 data-ending-style:scale-[0.97] data-ending-style:duration-100 motion-reduce:transition-none",
144
+ children: options.map((tab, i) => {
145
+ if (tab.unlisted && tab !== selected) return;
146
+ return /* @__PURE__ */ jsxs(Menu.LinkItem, {
147
+ closeOnClick: true,
148
+ render: /* @__PURE__ */ jsx(Link, {
149
+ href: tab.url,
150
+ ...tab.props
151
+ }),
152
+ className: cn("flex w-full min-h-9 items-start gap-3 rounded-lg px-[calc(--spacing(2.5)-1px)] py-2 text-start outline-none transition-colors duration-100 data-highlighted:bg-fd-accent data-highlighted:text-fd-accent-foreground [&_svg]:size-4 [&_svg]:shrink-0", tab.props?.className),
153
+ children: [
154
+ /* @__PURE__ */ jsx(TabIcon, {
155
+ tab,
156
+ className: "mt-0.5"
157
+ }),
158
+ /* @__PURE__ */ jsxs("span", {
159
+ className: "flex flex-col flex-1 min-w-0",
160
+ children: [/* @__PURE__ */ jsx("span", {
161
+ className: "truncate font-medium",
162
+ children: tab.title
163
+ }), tab.description && /* @__PURE__ */ jsx("span", {
164
+ className: "truncate text-xs text-fd-muted-foreground",
165
+ children: tab.description
166
+ })]
167
+ }),
168
+ tab === selected && /* @__PURE__ */ jsx(CheckIcon, { className: "mt-0.5 text-fd-primary" })
169
+ ]
170
+ }, i);
171
+ })
172
+ })
173
+ }) })] });
174
+ }
175
+ function TabIcon({ tab, className }) {
176
+ return /* @__PURE__ */ jsx("span", {
177
+ className: cn("flex items-center justify-center shrink-0 size-4 font-medium", !tab.icon && "rounded bg-fd-muted text-[10px] text-fd-muted-foreground", className),
178
+ children: tab.icon ?? (typeof tab.title === "string" ? tab.title.charAt(0) : null)
179
+ });
180
+ }
181
+ function SidebarViewport() {
182
+ return /* @__PURE__ */ jsxs(ScrollArea.Root, {
183
+ className: "min-h-0 flex-1 mt-2",
184
+ children: [/* @__PURE__ */ jsx(ScrollArea.Viewport, {
185
+ className: "size-full overscroll-contain px-3 pt-4 pb-8 mask-[linear-gradient(to_bottom,transparent,white_16px,white_calc(100%-32px),transparent)]",
186
+ children: /* @__PURE__ */ jsx(SidebarItems, {})
187
+ }), /* @__PURE__ */ jsx(ScrollArea.Scrollbar, {
188
+ className: (s) => cn("flex w-1.5 py-2 select-none transition-opacity", !s.hovering && "opacity-0"),
189
+ children: /* @__PURE__ */ jsx(ScrollArea.Thumb, { className: "flex-1 rounded-full bg-fd-border" })
190
+ })]
191
+ });
192
+ }
193
+ function SidebarItems() {
194
+ const { menuItems } = useSpaciousLayout();
195
+ const links = menuItems.filter((item) => item.type !== "icon");
196
+ return /* @__PURE__ */ jsxs("div", {
197
+ ref: follow,
198
+ className: "relative flex flex-col",
199
+ children: [
200
+ /* @__PURE__ */ jsx("div", {
201
+ "aria-hidden": true,
202
+ className: "absolute top-0 left-0 py-0.5 rounded-lg bg-fd-accent/60 bg-clip-content opacity-0 pointer-events-none transition-opacity duration-200 ease-[cubic-bezier(0.22,1,0.36,1)] motion-safe:transition-[translate,width,height,opacity]"
203
+ }),
204
+ links.map((item, i) => /* @__PURE__ */ jsx(SidebarLinkItem, {
205
+ item,
206
+ className: cn(i === links.length - 1 && "mb-6")
207
+ }, i)),
208
+ /* @__PURE__ */ jsx("div", {
209
+ className: "flex flex-col",
210
+ children: /* @__PURE__ */ jsx(SidebarPageTree, {})
211
+ })
212
+ ]
213
+ });
214
+ }
215
+ /** a soft block glides to the item under the mouse or keyboard focus */
216
+ function follow(area) {
217
+ const block = area?.firstElementChild;
218
+ if (!area || !(block instanceof HTMLElement)) return;
219
+ let current = null;
220
+ const show = (item) => {
221
+ if (item === current) return;
222
+ block.style.transitionProperty = current ? "" : "opacity";
223
+ current = item;
224
+ if (!item) {
225
+ block.style.opacity = "0";
226
+ return;
227
+ }
228
+ const rect = item.getBoundingClientRect();
229
+ const origin = area.getBoundingClientRect();
230
+ block.style.translate = `${rect.left - origin.left}px ${rect.top - origin.top}px`;
231
+ block.style.width = `${rect.width}px`;
232
+ block.style.height = `${rect.height}px`;
233
+ block.style.opacity = item.matches("[data-active=true]") ? "0" : "1";
234
+ };
235
+ const itemOf = (target) => target instanceof Element ? target.closest("a[href], button") : null;
236
+ const controller = new AbortController();
237
+ const { signal } = controller;
238
+ area.addEventListener("pointerover", (e) => {
239
+ const item = itemOf(e.target);
240
+ if (item && e.pointerType === "mouse") show(item);
241
+ }, { signal });
242
+ area.addEventListener("pointerleave", () => show(null), { signal });
243
+ area.addEventListener("focusin", (e) => {
244
+ if (e.target instanceof Element && e.target.matches(":focus-visible")) show(itemOf(e.target));
245
+ }, { signal });
246
+ area.addEventListener("focusout", () => {
247
+ if (!area.matches(":hover")) show(null);
248
+ }, { signal });
249
+ return () => controller.abort();
250
+ }
251
+ function SidebarSeparator({ className, ...props }) {
252
+ const depth = useFolderDepth();
253
+ return /* @__PURE__ */ jsx(SidebarSeparator$1, {
254
+ className: cn("mb-1.5 px-2.5 text-xs font-medium text-fd-muted-foreground [&_svg]:size-3.5 [&_svg]:shrink-0", depth > 0 && "mt-4 first:mt-1", className),
255
+ ...props
256
+ });
257
+ }
258
+ function SidebarItem({ active, className, children, ...props }) {
259
+ const depth = useFolderDepth();
260
+ return /* @__PURE__ */ jsxs(SidebarItem$1, {
261
+ active,
262
+ className: cn(itemVariants({ active }), className),
263
+ ...props,
264
+ children: [active && depth > 0 && activeLine, children]
265
+ });
266
+ }
267
+ function SidebarFolderTrigger(props) {
268
+ return /* @__PURE__ */ jsx(SidebarFolderTrigger$1, {
269
+ ...props,
270
+ className: cn(itemVariants(), "[&>[data-icon]]:size-3.5")
271
+ });
272
+ }
273
+ function SidebarFolderLink({ active, className, children, ...props }) {
274
+ const depth = useFolderDepth();
275
+ return /* @__PURE__ */ jsxs(SidebarFolderLink$1, {
276
+ active,
277
+ className: cn(itemVariants({ active }), "[&>[data-icon]]:size-3.5", className),
278
+ ...props,
279
+ children: [active && depth > 1 && activeLine, children]
280
+ });
281
+ }
282
+ function SidebarFolderContent({ children, ...props }) {
283
+ return /* @__PURE__ */ jsxs(SidebarFolderContent$1, {
284
+ ...props,
285
+ className: "relative flex flex-col ms-3 ps-1",
286
+ children: [/* @__PURE__ */ jsx("span", { className: "absolute start-0 inset-y-1 w-px bg-fd-border" }), children]
287
+ });
288
+ }
289
+ const SidebarPageTree = createPageTreeRenderer({
290
+ SidebarFolder,
291
+ SidebarFolderContent,
292
+ SidebarFolderLink,
293
+ SidebarFolderTrigger,
294
+ SidebarItem,
295
+ SidebarSeparator
296
+ });
297
+ const SidebarLinkItem = createLinkItemRenderer({
298
+ SidebarFolder,
299
+ SidebarFolderContent,
300
+ SidebarFolderLink,
301
+ SidebarFolderTrigger,
302
+ SidebarItem
303
+ });
304
+ //#endregion
305
+ export { Sidebar, SidebarDrawer, SidebarProvider };