@fumadocs/base-ui 16.12.1 → 16.14.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.
@@ -12,7 +12,7 @@ function DefaultSearchDialog({ type, defaultTag, tags = [], api, delayMs, allowC
12
12
  const { locale } = useI18n();
13
13
  const [tag, setTag] = useState(defaultTag);
14
14
  let client;
15
- if (type === "static") client = use(STATIC ??= import("fumadocs-core/search/client/orama-static")).oramaStaticClient({
15
+ if (type === "static") client = use(STATIC ??= import("fumadocs-core/search/client/orama-static")).staticClient({
16
16
  from: api,
17
17
  locale,
18
18
  tag
@@ -3,7 +3,7 @@ import { VariantProps } from "class-variance-authority";
3
3
  declare const buttonVariants: (props?: ({
4
4
  variant?: "primary" | "outline" | "ghost" | "secondary" | null | undefined;
5
5
  color?: "primary" | "outline" | "ghost" | "secondary" | null | undefined;
6
- size?: "sm" | "icon" | "icon-sm" | "icon-xs" | null | undefined;
6
+ size?: "icon" | "sm" | "icon-sm" | "icon-xs" | null | undefined;
7
7
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
8
8
  type ButtonProps = VariantProps<typeof buttonVariants>;
9
9
  //#endregion
@@ -1,7 +1,7 @@
1
1
  import { ComponentProps } from "react";
2
2
  //#region src/layouts/home/slots/header.d.ts
3
3
  declare const navItemVariants: (props?: ({
4
- variant?: "button" | "main" | "icon" | null | undefined;
4
+ variant?: "main" | "icon" | "button" | null | undefined;
5
5
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
6
6
  declare function Header(props: ComponentProps<'header'>): import("react").JSX.Element;
7
7
  //#endregion
@@ -18,6 +18,14 @@ interface ThemeOptions extends ThemeProviderProps {
18
18
  * @defaultValue true
19
19
  */
20
20
  enabled?: boolean;
21
+ /**
22
+ * Hotkey for toggling between light/dark mode, pass `false` to disable it.
23
+ *
24
+ * It is ignored while typing in an editable element (e.g. `<input />`), or when a dialog is opened.
25
+ *
26
+ * @defaultValue `d`
27
+ */
28
+ hotKey?: string | ((e: KeyboardEvent) => boolean) | false;
21
29
  }
22
30
  interface RootProviderProps {
23
31
  /**
@@ -1,24 +1,65 @@
1
1
  "use client";
2
2
  import { I18nProvider } from "../contexts/i18n.js";
3
3
  import { SearchProvider } from "../contexts/search.js";
4
- import { jsx } from "react/jsx-runtime";
5
- import { ThemeProvider, useTheme } from "next-themes";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ import { useEffect, useEffectEvent } from "react";
6
+ import { ThemeProvider, useTheme, useTheme as useTheme$1 } from "next-themes";
7
+ import { flushSync } from "react-dom";
6
8
  import { DirectionProvider } from "@base-ui/react/direction-provider";
7
9
  //#region src/provider/base.tsx
10
+ /**
11
+ * Whether the event should be ignored because the user is interacting with an editable element,
12
+ * or an opened dialog (e.g. the search dialog).
13
+ */
14
+ function isTypingTarget(target) {
15
+ if (!(target instanceof HTMLElement)) return false;
16
+ if (target.isContentEditable) return true;
17
+ if ([
18
+ "INPUT",
19
+ "TEXTAREA",
20
+ "SELECT"
21
+ ].includes(target.tagName)) return true;
22
+ return target.closest("[role=\"dialog\"]") !== null;
23
+ }
24
+ /**
25
+ * Toggle between light/dark mode with a hotkey, must be placed under `next-themes` provider.
26
+ */
27
+ function ThemeHotKey({ hotKey }) {
28
+ const { setTheme, resolvedTheme } = useTheme$1();
29
+ const onKeyDown = useEffectEvent((e) => {
30
+ if (e.defaultPrevented || e.isComposing) return;
31
+ if (isTypingTarget(e.target)) return;
32
+ if (!(typeof hotKey === "string" ? !e.metaKey && !e.ctrlKey && !e.altKey && e.key.toLowerCase() === hotKey.toLowerCase() : hotKey(e))) return;
33
+ e.preventDefault();
34
+ const next = resolvedTheme === "dark" ? "light" : "dark";
35
+ if (document?.startViewTransition) document.startViewTransition(() => flushSync(() => setTheme(next)));
36
+ else setTheme(next);
37
+ });
38
+ useEffect(() => {
39
+ window.addEventListener("keydown", onKeyDown);
40
+ return () => {
41
+ window.removeEventListener("keydown", onKeyDown);
42
+ };
43
+ }, []);
44
+ return null;
45
+ }
8
46
  function RootProvider({ children, dir = "ltr", theme = {}, search, i18n }) {
9
47
  let body = children;
10
48
  if (search?.enabled !== false) body = /* @__PURE__ */ jsx(SearchProvider, {
11
49
  ...search,
12
50
  children: body
13
51
  });
14
- if (theme?.enabled !== false) body = /* @__PURE__ */ jsx(ThemeProvider, {
15
- attribute: "class",
16
- defaultTheme: "system",
17
- enableSystem: true,
18
- disableTransitionOnChange: true,
19
- ...theme,
20
- children: body
21
- });
52
+ if (theme?.enabled !== false) {
53
+ const { enabled: _, hotKey = "d", ...themeProps } = theme;
54
+ body = /* @__PURE__ */ jsxs(ThemeProvider, {
55
+ attribute: "class",
56
+ defaultTheme: "system",
57
+ enableSystem: true,
58
+ disableTransitionOnChange: true,
59
+ ...themeProps,
60
+ children: [hotKey !== false && /* @__PURE__ */ jsx(ThemeHotKey, { hotKey }), body]
61
+ });
62
+ }
22
63
  if (i18n) body = /* @__PURE__ */ jsx(I18nProvider, {
23
64
  ...i18n,
24
65
  children: body
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fumadocs/base-ui",
3
- "version": "16.12.1",
3
+ "version": "16.14.0",
4
4
  "description": "The Base UI version of Fumadocs UI",
5
5
  "keywords": [
6
6
  "Docs",
@@ -129,9 +129,9 @@
129
129
  "@base-ui/react": "^1.6.0",
130
130
  "@fuma-translate/react": "^1.0.2",
131
131
  "class-variance-authority": "^0.7.1",
132
- "cnfast": "^0.0.8",
133
- "lucide-react": "^1.25.0",
134
- "motion": "^12.42.2",
132
+ "cnfast": "^0.1.0",
133
+ "lucide-react": "^1.27.0",
134
+ "motion": "^12.43.0",
135
135
  "next-themes": "^0.4.6",
136
136
  "react-remove-scroll": "^2.7.2",
137
137
  "rehype-raw": "^7.0.0",
@@ -143,19 +143,19 @@
143
143
  "devDependencies": {
144
144
  "@tailwindcss/cli": "^4.3.3",
145
145
  "@tailwindcss/oxide": "^4.3.3",
146
- "@tsdown/css": "^0.22.13",
146
+ "@tsdown/css": "^0.22.14",
147
147
  "@types/hast": "^3.0.5",
148
148
  "@types/mdx": "^2.0.14",
149
- "@types/node": "^26.1.1",
149
+ "@types/node": "^26.1.2",
150
150
  "@types/react": "^19.2.17",
151
151
  "@types/react-dom": "^19.2.3",
152
152
  "fuma-cli": "^0.1.1",
153
153
  "react-medium-image-zoom": "^5.4.8",
154
154
  "tailwindcss": "^4.3.3",
155
- "tsdown": "0.22.13",
155
+ "tsdown": "0.22.14",
156
156
  "unified": "^11.0.5",
157
157
  "@fumadocs/cli": "1.4.1",
158
- "fumadocs-core": "16.12.1",
158
+ "fumadocs-core": "16.14.0",
159
159
  "tsconfig": "0.0.0"
160
160
  },
161
161
  "peerDependencies": {
@@ -165,7 +165,7 @@
165
165
  "react": "^19.2.0",
166
166
  "react-dom": "^19.2.0",
167
167
  "takumi-js": "*",
168
- "fumadocs-core": "16.12.1"
168
+ "fumadocs-core": "16.14.0"
169
169
  },
170
170
  "peerDependenciesMeta": {
171
171
  "next": {
@@ -185,11 +185,9 @@
185
185
  "react-medium-image-zoom": "5.4.8"
186
186
  },
187
187
  "scripts": {
188
- "build": "pnpm build:layout && pnpm build:tailwind",
189
- "build:layout": "tsdown",
190
- "build:tailwind": "tailwindcss -i css/style.css -o ./dist/style.css",
188
+ "build": "tsdown",
191
189
  "clean": "rimraf dist",
192
- "dev": "concurrently \"tsdown --watch --clean false\" \"tailwindcss -i css/style.css -o ./dist/style.css -w\"",
190
+ "dev": "tsdown --watch --clean false",
193
191
  "lint": "oxlint .",
194
192
  "types:check": "tsc --noEmit"
195
193
  }