forked from stack-auth/stack-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.tsx
More file actions
89 lines (81 loc) · 2.01 KB
/
shared.tsx
File metadata and controls
89 lines (81 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import type { PageTree } from 'fumadocs-core/server';
import {
getSidebarTabs,
type GetSidebarTabsOptions,
} from 'fumadocs-ui/utils/get-sidebar-tabs';
import type { ReactNode } from 'react';
import type { Option } from '../../layout/root-toggle';
import {
type SidebarComponents,
SidebarFolder,
SidebarFolderContent,
SidebarFolderLink,
SidebarFolderTrigger,
SidebarItem,
type SidebarProps,
} from '../../layout/sidebar';
import type { LinkItemType } from '../links';
export const layoutVariables = {
'--fd-layout-offset': 'max(calc(50vw - var(--fd-layout-width) / 2), 0px)',
};
export type SidebarOptions = {
components?: Partial<SidebarComponents>,
/**
* Root Toggle options
*/
tabs?: Option[] | GetSidebarTabsOptions | false,
banner?: ReactNode,
footer?: ReactNode,
} & SidebarProps
export function SidebarLinkItem({
item,
...props
}: {
item: LinkItemType,
className?: string,
}) {
if (item.type === 'menu')
return (
<SidebarFolder {...props}>
{item.url ? (
<SidebarFolderLink href={item.url}>
{item.icon}
{item.text}
</SidebarFolderLink>
) : (
<SidebarFolderTrigger>
{item.icon}
{item.text}
</SidebarFolderTrigger>
)}
<SidebarFolderContent>
{item.items.map((child, i) => (
<SidebarLinkItem key={i} item={child} />
))}
</SidebarFolderContent>
</SidebarFolder>
);
if (item.type === 'custom') return <div {...props}>{item.children}</div>;
return (
<SidebarItem
href={item.url}
icon={item.icon}
external={item.external}
{...props}
>
{item.text}
</SidebarItem>
);
}
export function getSidebarTabsFromOptions(
options: SidebarOptions['tabs'],
tree: PageTree.Root,
) {
if (Array.isArray(options)) {
return options;
} else if (typeof options === 'object') {
return getSidebarTabs(tree, options);
} else if (options !== false) {
return getSidebarTabs(tree);
}
}