fumadocs-ui 14.1.1 → 14.2.0

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.
@@ -1,295 +0,0 @@
1
- import {
2
- buttonVariants
3
- } from "./chunk-QKOA6KEZ.js";
4
- import {
5
- FileText,
6
- Hash,
7
- LoaderCircle,
8
- Search,
9
- Text
10
- } from "./chunk-5QPVK7QM.js";
11
- import {
12
- twMerge
13
- } from "./chunk-TK3TM3MR.js";
14
- import {
15
- useSearchContext
16
- } from "./chunk-ET4TW6M5.js";
17
- import {
18
- useSidebar
19
- } from "./chunk-27HFSL7N.js";
20
- import {
21
- useI18n
22
- } from "./chunk-EFMHXXHW.js";
23
-
24
- // src/components/dialog/search.tsx
25
- import { useRouter } from "next/navigation";
26
- import {
27
- useMemo
28
- } from "react";
29
- import { cva } from "class-variance-authority";
30
-
31
- // src/components/ui/command.tsx
32
- import { Command as CommandPrimitive } from "cmdk";
33
- import * as React from "react";
34
- import { jsx, jsxs } from "react/jsx-runtime";
35
- var CommandInput = React.forwardRef(({ className, onClose, children, ...props }, ref) => /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center gap-2 px-3", children: [
36
- children,
37
- /* @__PURE__ */ jsx(
38
- CommandPrimitive.Input,
39
- {
40
- ref,
41
- className: twMerge(
42
- "w-0 flex-1 bg-transparent py-3 text-base placeholder:text-fd-muted-foreground focus-visible:outline-none",
43
- className
44
- ),
45
- ...props
46
- }
47
- ),
48
- /* @__PURE__ */ jsx(
49
- "button",
50
- {
51
- type: "button",
52
- "aria-label": "Close Search",
53
- onClick: onClose,
54
- className: twMerge(
55
- buttonVariants({
56
- color: "outline",
57
- className: "text-xs p-1.5"
58
- })
59
- ),
60
- children: "Esc"
61
- }
62
- )
63
- ] }));
64
- CommandInput.displayName = CommandPrimitive.Input.displayName;
65
- var CommandList = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
66
- CommandPrimitive.List,
67
- {
68
- ref,
69
- className: twMerge("max-h-[460px] overflow-y-auto border-t p-2", className),
70
- ...props
71
- }
72
- ));
73
- CommandList.displayName = CommandPrimitive.List.displayName;
74
- var CommandEmpty = React.forwardRef((props, ref) => /* @__PURE__ */ jsx(
75
- CommandPrimitive.Empty,
76
- {
77
- ref,
78
- className: "py-12 text-center text-sm",
79
- ...props
80
- }
81
- ));
82
- CommandEmpty.displayName = CommandPrimitive.Empty.displayName;
83
- var CommandGroup = React.forwardRef(({ className, heading, ...props }, ref) => /* @__PURE__ */ jsx(
84
- CommandPrimitive.Group,
85
- {
86
- ref,
87
- heading: heading ? /* @__PURE__ */ jsx("div", { className: "px-3 py-2 text-xs font-medium", children: heading }) : void 0,
88
- className: twMerge("overflow-hidden", className),
89
- ...props
90
- }
91
- ));
92
- CommandGroup.displayName = CommandPrimitive.Group.displayName;
93
- var CommandSeparator = React.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx(
94
- CommandPrimitive.Separator,
95
- {
96
- ref,
97
- className: twMerge("h-px bg-fd-border", className),
98
- ...props
99
- }
100
- ));
101
- CommandSeparator.displayName = CommandPrimitive.Separator.displayName;
102
- var CommandItem = React.forwardRef(({ className, icon, nested = false, children, ...props }, ref) => /* @__PURE__ */ jsx(
103
- CommandPrimitive.Item,
104
- {
105
- ref,
106
- className: twMerge(
107
- "select-none rounded-lg px-2 text-sm aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-selected:bg-fd-accent aria-selected:text-fd-accent-foreground",
108
- className
109
- ),
110
- ...props,
111
- children: /* @__PURE__ */ jsxs(
112
- "div",
113
- {
114
- className: twMerge(
115
- "flex min-h-10 flex-row items-center gap-3",
116
- nested && "ms-2 gap-2 border-s ps-4"
117
- ),
118
- children: [
119
- /* @__PURE__ */ jsx("div", { className: "text-fd-muted-foreground [&_svg]:size-4", children: icon }),
120
- /* @__PURE__ */ jsx("p", { className: "w-0 flex-1 truncate", children })
121
- ]
122
- }
123
- )
124
- }
125
- ));
126
- CommandItem.displayName = CommandPrimitive.Item.displayName;
127
- var CommandDialog = React.forwardRef(
128
- ({ children, ...props }, ref) => /* @__PURE__ */ jsx(
129
- CommandPrimitive.Dialog,
130
- {
131
- ref,
132
- shouldFilter: false,
133
- loop: true,
134
- contentClassName: "fixed left-1/2 top-[10vh] z-50 w-[98vw] max-w-screen-sm origin-left -translate-x-1/2 rounded-lg border bg-fd-popover text-fd-popover-foreground shadow-lg data-[state=closed]:animate-fd-dialog-out data-[state=open]:animate-fd-dialog-in",
135
- overlayClassName: "fixed inset-0 z-50 bg-fd-background/50 backdrop-blur-sm data-[state=closed]:animate-fd-fade-out data-[state=open]:animate-fd-fade-in",
136
- ...props,
137
- children
138
- }
139
- )
140
- );
141
- CommandDialog.displayName = CommandPrimitive.Dialog.displayName;
142
-
143
- // src/components/dialog/search.tsx
144
- import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
145
- function SearchDialog({
146
- open,
147
- onOpenChange,
148
- footer,
149
- links = [],
150
- ...props
151
- }) {
152
- const defaultItems = useMemo(
153
- () => links.map(([name, link]) => ({
154
- type: "page",
155
- id: name,
156
- content: name,
157
- url: link
158
- })),
159
- [links]
160
- );
161
- return /* @__PURE__ */ jsxs2(CommandDialog, { open, onOpenChange, children: [
162
- /* @__PURE__ */ jsx2(
163
- Search2,
164
- {
165
- ...props,
166
- items: props.results === "empty" ? defaultItems : props.results,
167
- hideResults: props.results === "empty" && defaultItems.length === 0
168
- }
169
- ),
170
- footer ? /* @__PURE__ */ jsx2("div", { className: "mt-auto flex flex-col border-t p-3", children: footer }) : null
171
- ] });
172
- }
173
- var icons = {
174
- text: /* @__PURE__ */ jsx2(Text, {}),
175
- heading: /* @__PURE__ */ jsx2(Hash, {}),
176
- page: /* @__PURE__ */ jsx2(FileText, {})
177
- };
178
- function Search2({
179
- search,
180
- onSearchChange,
181
- items,
182
- isLoading,
183
- hideResults = false
184
- }) {
185
- const { text } = useI18n();
186
- const router = useRouter();
187
- const { setOpenSearch } = useSearchContext();
188
- const sidebar = useSidebar();
189
- const onOpen = (url) => {
190
- router.push(url);
191
- setOpenSearch(false);
192
- if (location.pathname === url.split("#")[0]) {
193
- sidebar.setOpen(false);
194
- }
195
- };
196
- return /* @__PURE__ */ jsxs2(Fragment, { children: [
197
- /* @__PURE__ */ jsx2(
198
- CommandInput,
199
- {
200
- value: search,
201
- onValueChange: onSearchChange,
202
- onClose: () => {
203
- setOpenSearch(false);
204
- },
205
- placeholder: text.search,
206
- children: /* @__PURE__ */ jsxs2("div", { className: "relative size-4", children: [
207
- /* @__PURE__ */ jsx2(
208
- LoaderCircle,
209
- {
210
- className: twMerge(
211
- "absolute size-full animate-spin text-fd-primary transition-opacity",
212
- !isLoading && "opacity-0"
213
- )
214
- }
215
- ),
216
- /* @__PURE__ */ jsx2(
217
- Search,
218
- {
219
- className: twMerge(
220
- "absolute size-full text-fd-muted-foreground transition-opacity",
221
- isLoading && "opacity-0"
222
- )
223
- }
224
- )
225
- ] })
226
- }
227
- ),
228
- /* @__PURE__ */ jsxs2(CommandList, { className: twMerge(hideResults && "hidden"), children: [
229
- /* @__PURE__ */ jsx2(CommandEmpty, { children: text.searchNoResult }),
230
- /* @__PURE__ */ jsx2(CommandGroup, { value: "result", children: items.map((item) => /* @__PURE__ */ jsx2(
231
- CommandItem,
232
- {
233
- value: item.id,
234
- onSelect: () => {
235
- onOpen(item.url);
236
- },
237
- icon: icons[item.type],
238
- nested: item.type !== "page",
239
- children: item.content
240
- },
241
- item.id
242
- )) })
243
- ] })
244
- ] });
245
- }
246
- var itemVariants = cva(
247
- "rounded-md border px-2 py-0.5 text-xs font-medium text-fd-muted-foreground transition-colors",
248
- {
249
- variants: {
250
- active: {
251
- true: "bg-fd-accent text-fd-accent-foreground"
252
- }
253
- }
254
- }
255
- );
256
- function TagsList({
257
- tag,
258
- onTagChange,
259
- items,
260
- allowClear,
261
- ...props
262
- }) {
263
- return /* @__PURE__ */ jsxs2(
264
- "div",
265
- {
266
- ...props,
267
- className: twMerge("flex flex-row items-center gap-1", props.className),
268
- children: [
269
- items.map((item) => /* @__PURE__ */ jsx2(
270
- "button",
271
- {
272
- type: "button",
273
- className: twMerge(itemVariants({ active: tag === item.value })),
274
- onClick: () => {
275
- if (tag === item.value && allowClear) {
276
- onTagChange(void 0);
277
- } else {
278
- onTagChange(item.value);
279
- }
280
- },
281
- tabIndex: -1,
282
- children: item.name
283
- },
284
- item.value
285
- )),
286
- props.children
287
- ]
288
- }
289
- );
290
- }
291
-
292
- export {
293
- SearchDialog,
294
- TagsList
295
- };