fumadocs-ui
Version:
The Radix UI version of Fumadocs UI
66 lines (63 loc) • 2.23 kB
JavaScript
'use client';
import { i18n_exports } from "../../contexts/i18n.js";
import { SearchDialog, SearchDialogClose, SearchDialogContent, SearchDialogFooter, SearchDialogHeader, SearchDialogIcon, SearchDialogInput, SearchDialogList, SearchDialogOverlay, TagsList, TagsListItem } from "./search.js";
import { jsx, jsxs } from "react/jsx-runtime";
import { useMemo, useState } from "react";
import { useOnChange } from "fumadocs-core/utils/use-on-change";
import { useDocsSearch } from "fumadocs-core/search/client";
//#region src/components/dialog/search-default.tsx
function DefaultSearchDialog({ defaultTag, tags = [], api, delayMs, type = "fetch", allowClear = false, links = [], footer, ...props }) {
const { locale } = (0, i18n_exports.useI18n)();
const [tag, setTag] = useState(defaultTag);
const { search, setSearch, query } = useDocsSearch(type === "fetch" ? {
type: "fetch",
api,
locale,
tag,
delayMs
} : {
type: "static",
from: api,
locale,
tag,
delayMs
});
const defaultItems = useMemo(() => {
if (links.length === 0) return null;
return links.map(([name, link]) => ({
type: "page",
id: name,
content: name,
url: link
}));
}, [links]);
useOnChange(defaultTag, (v) => {
setTag(v);
});
return /* @__PURE__ */ jsxs(SearchDialog, {
search,
onSearchChange: setSearch,
isLoading: query.isLoading,
...props,
children: [
/* @__PURE__ */ jsx(SearchDialogOverlay, {}),
/* @__PURE__ */ jsxs(SearchDialogContent, { children: [/* @__PURE__ */ jsxs(SearchDialogHeader, { children: [
/* @__PURE__ */ jsx(SearchDialogIcon, {}),
/* @__PURE__ */ jsx(SearchDialogInput, {}),
/* @__PURE__ */ jsx(SearchDialogClose, {})
] }), /* @__PURE__ */ jsx(SearchDialogList, { items: query.data !== "empty" ? query.data : defaultItems })] }),
/* @__PURE__ */ jsxs(SearchDialogFooter, { children: [tags.length > 0 && /* @__PURE__ */ jsx(TagsList, {
tag,
onTagChange: setTag,
allowClear,
children: tags.map((tag$1) => /* @__PURE__ */ jsx(TagsListItem, {
value: tag$1.value,
children: tag$1.name
}, tag$1.value))
}), footer] })
]
});
}
//#endregion
export { DefaultSearchDialog as default };
//# sourceMappingURL=search-default.js.map