fumadocs-core 11.2.2 → 11.3.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.
- package/dist/sidebar.d.ts +14 -7
- package/dist/sidebar.js +22 -13
- package/package.json +1 -1
package/dist/sidebar.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactNode, ElementType, ComponentPropsWithoutRef } from 'react';
|
|
1
|
+
import { ReactNode, ElementType, ReactElement, ComponentPropsWithoutRef } from 'react';
|
|
2
2
|
|
|
3
3
|
interface SidebarProviderProps {
|
|
4
4
|
open?: boolean;
|
|
@@ -6,14 +6,21 @@ interface SidebarProviderProps {
|
|
|
6
6
|
children: ReactNode;
|
|
7
7
|
}
|
|
8
8
|
declare function SidebarProvider(props: SidebarProviderProps): React.ReactElement;
|
|
9
|
-
type
|
|
9
|
+
type AsProps<T extends ElementType> = Omit<ComponentPropsWithoutRef<T>, 'as'> & {
|
|
10
10
|
as?: T;
|
|
11
11
|
};
|
|
12
|
-
type SidebarTriggerProps<T extends ElementType> =
|
|
13
|
-
declare function SidebarTrigger<T extends ElementType = 'button'>({ as, ...props }: SidebarTriggerProps<T>):
|
|
14
|
-
type SidebarContentProps<T extends ElementType> =
|
|
12
|
+
type SidebarTriggerProps<T extends ElementType> = AsProps<T>;
|
|
13
|
+
declare function SidebarTrigger<T extends ElementType = 'button'>({ as, ...props }: SidebarTriggerProps<T>): ReactElement;
|
|
14
|
+
type SidebarContentProps<T extends ElementType> = AsProps<T> & {
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use `blockScrollingWidth` instead
|
|
17
|
+
*/
|
|
15
18
|
minWidth?: number;
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Disable scroll blocking when the viewport width is larger than a certain number (in pixels)
|
|
21
|
+
*/
|
|
22
|
+
blockScrollingWidth?: number;
|
|
23
|
+
};
|
|
24
|
+
declare function SidebarList<T extends ElementType = 'aside'>({ as, minWidth, blockScrollingWidth, ...props }: SidebarContentProps<T>): ReactElement;
|
|
18
25
|
|
|
19
26
|
export { type SidebarContentProps, SidebarList, SidebarProvider, type SidebarProviderProps, SidebarTrigger, type SidebarTriggerProps };
|
package/dist/sidebar.js
CHANGED
|
@@ -6,7 +6,13 @@ import {
|
|
|
6
6
|
|
|
7
7
|
// src/sidebar.tsx
|
|
8
8
|
import { usePathname } from "next/navigation";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
useCallback,
|
|
11
|
+
createContext,
|
|
12
|
+
useContext,
|
|
13
|
+
useEffect,
|
|
14
|
+
useState
|
|
15
|
+
} from "react";
|
|
10
16
|
import { RemoveScroll } from "react-remove-scroll";
|
|
11
17
|
import { jsx } from "react/jsx-runtime";
|
|
12
18
|
var SidebarContext = createContext(void 0);
|
|
@@ -26,7 +32,7 @@ function SidebarProvider(props) {
|
|
|
26
32
|
const pathname = usePathname();
|
|
27
33
|
useEffect(() => {
|
|
28
34
|
setOpen(false);
|
|
29
|
-
}, [pathname]);
|
|
35
|
+
}, [pathname, setOpen]);
|
|
30
36
|
return /* @__PURE__ */ jsx(SidebarContext.Provider, { value: [open, setOpen], children: props.children });
|
|
31
37
|
}
|
|
32
38
|
function SidebarTrigger(_a) {
|
|
@@ -40,44 +46,47 @@ function SidebarTrigger(_a) {
|
|
|
40
46
|
return /* @__PURE__ */ jsx(
|
|
41
47
|
As,
|
|
42
48
|
__spreadValues({
|
|
49
|
+
"aria-label": "Toggle Sidebar",
|
|
43
50
|
"data-open": open,
|
|
44
|
-
onClick: () => {
|
|
51
|
+
onClick: useCallback(() => {
|
|
45
52
|
setOpen(!open);
|
|
46
|
-
}
|
|
53
|
+
}, [open, setOpen])
|
|
47
54
|
}, props)
|
|
48
55
|
);
|
|
49
56
|
}
|
|
50
57
|
function SidebarList(_a) {
|
|
51
58
|
var _b = _a, {
|
|
52
59
|
as,
|
|
53
|
-
minWidth
|
|
60
|
+
minWidth,
|
|
61
|
+
blockScrollingWidth = minWidth
|
|
54
62
|
} = _b, props = __objRest(_b, [
|
|
55
63
|
"as",
|
|
56
|
-
"minWidth"
|
|
64
|
+
"minWidth",
|
|
65
|
+
"blockScrollingWidth"
|
|
57
66
|
]);
|
|
58
67
|
const [open] = useSidebarContext();
|
|
59
|
-
const [
|
|
68
|
+
const [isBlocking, setIsBlocking] = useState(false);
|
|
60
69
|
useEffect(() => {
|
|
61
|
-
if (
|
|
70
|
+
if (!blockScrollingWidth)
|
|
62
71
|
return;
|
|
63
72
|
const mediaQueryList = window.matchMedia(
|
|
64
|
-
`(min-width: ${
|
|
73
|
+
`(min-width: ${blockScrollingWidth.toString()}px)`
|
|
65
74
|
);
|
|
66
75
|
const handleChange = () => {
|
|
67
|
-
|
|
76
|
+
setIsBlocking(!mediaQueryList.matches);
|
|
68
77
|
};
|
|
69
78
|
handleChange();
|
|
70
79
|
mediaQueryList.addEventListener("change", handleChange);
|
|
71
80
|
return () => {
|
|
72
81
|
mediaQueryList.removeEventListener("change", handleChange);
|
|
73
82
|
};
|
|
74
|
-
}, [
|
|
83
|
+
}, [blockScrollingWidth]);
|
|
75
84
|
return /* @__PURE__ */ jsx(
|
|
76
85
|
RemoveScroll,
|
|
77
86
|
__spreadProps(__spreadValues({
|
|
78
87
|
as: as != null ? as : "aside",
|
|
79
|
-
"data-open":
|
|
80
|
-
enabled:
|
|
88
|
+
"data-open": open,
|
|
89
|
+
enabled: Boolean(isBlocking && open)
|
|
81
90
|
}, props), {
|
|
82
91
|
children: props.children
|
|
83
92
|
})
|