@codefast/ui 0.3.16-canary.2 → 0.3.16-canary.3
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/CHANGELOG.md +21 -0
- package/README.md +1 -1
- package/dist/components/accordion.mjs +2 -2
- package/dist/components/alert-dialog.d.mts +1 -1
- package/dist/components/alert-dialog.mjs +4 -4
- package/dist/components/alert.d.mts +3 -13
- package/dist/components/alert.mjs +3 -23
- package/dist/components/badge.d.mts +3 -15
- package/dist/components/badge.mjs +2 -44
- package/dist/components/breadcrumb.mjs +1 -1
- package/dist/components/button-group.d.mts +3 -13
- package/dist/components/button-group.mjs +3 -24
- package/dist/components/button.d.mts +3 -25
- package/dist/components/button.mjs +2 -72
- package/dist/components/calendar.mjs +2 -1
- package/dist/components/carousel.d.mts +1 -2
- package/dist/components/chart.d.mts +2 -4
- package/dist/components/checkbox.mjs +2 -2
- package/dist/components/context-menu.mjs +2 -2
- package/dist/components/dialog.d.mts +1 -1
- package/dist/components/dialog.mjs +4 -4
- package/dist/components/drawer.d.mts +1 -1
- package/dist/components/drawer.mjs +2 -2
- package/dist/components/dropdown-menu.mjs +2 -2
- package/dist/components/empty.d.mts +3 -13
- package/dist/components/empty.mjs +3 -18
- package/dist/components/field.d.mts +3 -14
- package/dist/components/field.mjs +3 -32
- package/dist/components/form.d.mts +2 -4
- package/dist/components/hover-card.mjs +1 -1
- package/dist/components/input-group.d.mts +4 -31
- package/dist/components/input-group.mjs +3 -90
- package/dist/components/input-number.mjs +4 -4
- package/dist/components/input-otp.mjs +2 -2
- package/dist/components/input.mjs +1 -1
- package/dist/components/item.d.mts +4 -29
- package/dist/components/item.mjs +3 -56
- package/dist/components/menubar.mjs +2 -2
- package/dist/components/native-select.mjs +1 -1
- package/dist/components/navigation-menu.d.mts +1 -6
- package/dist/components/navigation-menu.mjs +8 -15
- package/dist/components/pagination.d.mts +1 -1
- package/dist/components/pagination.mjs +1 -1
- package/dist/components/popover.mjs +1 -1
- package/dist/components/progress-circle.d.mts +3 -47
- package/dist/components/progress-circle.mjs +2 -47
- package/dist/components/progress.mjs +1 -1
- package/dist/components/radio-group.mjs +1 -1
- package/dist/components/radio.mjs +1 -1
- package/dist/components/scroll-area.d.mts +3 -19
- package/dist/components/scroll-area.mjs +4 -61
- package/dist/components/select.d.mts +1 -1
- package/dist/components/select.mjs +3 -3
- package/dist/components/separator.d.mts +3 -18
- package/dist/components/separator.mjs +3 -23
- package/dist/components/sheet.d.mts +6 -18
- package/dist/components/sheet.mjs +6 -49
- package/dist/components/sidebar.d.mts +4 -19
- package/dist/components/sidebar.mjs +10 -46
- package/dist/components/skeleton.mjs +1 -1
- package/dist/components/slider.mjs +1 -1
- package/dist/components/spinner.mjs +1 -1
- package/dist/components/switch.mjs +2 -2
- package/dist/components/table.mjs +1 -1
- package/dist/components/tabs.mjs +1 -1
- package/dist/components/textarea.mjs +1 -1
- package/dist/components/toggle-group.d.mts +3 -2
- package/dist/components/toggle-group.mjs +1 -1
- package/dist/components/toggle.d.mts +2 -21
- package/dist/components/toggle.mjs +2 -39
- package/dist/components/tooltip.mjs +1 -1
- package/dist/index.d.mts +31 -16
- package/dist/index.mjs +30 -15
- package/dist/lib/utils.d.mts +1 -12
- package/dist/lib/utils.mjs +1 -9
- package/dist/primitives/checkbox-group.d.mts +1 -2
- package/dist/primitives/input-number.d.mts +1 -2
- package/dist/primitives/input.d.mts +1 -2
- package/dist/primitives/progress-circle.d.mts +1 -2
- package/dist/variants/alert.d.mts +18 -0
- package/dist/variants/alert.mjs +25 -0
- package/dist/variants/badge.d.mts +20 -0
- package/dist/variants/badge.mjs +46 -0
- package/dist/variants/button-group.d.mts +18 -0
- package/dist/variants/button-group.mjs +26 -0
- package/dist/variants/button.d.mts +30 -0
- package/dist/variants/button.mjs +76 -0
- package/dist/variants/empty.d.mts +18 -0
- package/dist/variants/empty.mjs +20 -0
- package/dist/variants/field.d.mts +19 -0
- package/dist/variants/field.mjs +34 -0
- package/dist/variants/input-group.d.mts +43 -0
- package/dist/variants/input-group.mjs +93 -0
- package/dist/variants/item.d.mts +37 -0
- package/dist/variants/item.mjs +60 -0
- package/dist/variants/navigation-menu.d.mts +13 -0
- package/dist/variants/navigation-menu.mjs +12 -0
- package/dist/variants/progress-circle.d.mts +52 -0
- package/dist/variants/progress-circle.mjs +49 -0
- package/dist/variants/scroll-area.d.mts +24 -0
- package/dist/variants/scroll-area.mjs +63 -0
- package/dist/variants/separator.d.mts +23 -0
- package/dist/variants/separator.mjs +25 -0
- package/dist/variants/sheet.d.mts +20 -0
- package/dist/variants/sheet.mjs +50 -0
- package/dist/variants/sidebar.d.mts +23 -0
- package/dist/variants/sidebar.mjs +42 -0
- package/dist/variants/toggle.d.mts +23 -0
- package/dist/variants/toggle.mjs +43 -0
- package/package.json +168 -20
- package/src/components/accordion.tsx +156 -0
- package/src/components/alert-dialog.tsx +314 -0
- package/src/components/alert.tsx +86 -0
- package/src/components/aspect-ratio.tsx +28 -0
- package/src/components/avatar.tsx +84 -0
- package/src/components/badge.tsx +38 -0
- package/src/components/breadcrumb.tsx +197 -0
- package/src/components/button-group.tsx +107 -0
- package/src/components/button.tsx +66 -0
- package/src/components/calendar.tsx +277 -0
- package/src/components/card.tsx +175 -0
- package/src/components/carousel.tsx +367 -0
- package/src/components/chart.tsx +587 -0
- package/src/components/checkbox-cards.tsx +92 -0
- package/src/components/checkbox-group.tsx +83 -0
- package/src/components/checkbox.tsx +65 -0
- package/src/components/collapsible.tsx +60 -0
- package/src/components/command.tsx +311 -0
- package/src/components/context-menu.tsx +489 -0
- package/src/components/dialog.tsx +295 -0
- package/src/components/drawer.tsx +271 -0
- package/src/components/dropdown-menu.tsx +498 -0
- package/src/components/empty.tsx +169 -0
- package/src/components/field.tsx +362 -0
- package/src/components/form.tsx +300 -0
- package/src/components/hover-card.tsx +116 -0
- package/src/components/input-group.tsx +224 -0
- package/src/components/input-number.tsx +161 -0
- package/src/components/input-otp.tsx +151 -0
- package/src/components/input-password.tsx +74 -0
- package/src/components/input-search.tsx +98 -0
- package/src/components/input.tsx +52 -0
- package/src/components/item.tsx +280 -0
- package/src/components/kbd.tsx +59 -0
- package/src/components/label.tsx +44 -0
- package/src/components/menubar.tsx +531 -0
- package/src/components/native-select.tsx +96 -0
- package/src/components/navigation-menu.tsx +295 -0
- package/src/components/pagination.tsx +204 -0
- package/src/components/popover.tsx +139 -0
- package/src/components/progress-circle.tsx +203 -0
- package/src/components/progress.tsx +54 -0
- package/src/components/radio-cards.tsx +85 -0
- package/src/components/radio-group.tsx +79 -0
- package/src/components/radio.tsx +61 -0
- package/src/components/resizable.tsx +99 -0
- package/src/components/scroll-area.tsx +115 -0
- package/src/components/select.tsx +319 -0
- package/src/components/separator.tsx +74 -0
- package/src/components/sheet.tsx +278 -0
- package/src/components/sidebar.tsx +1056 -0
- package/src/components/skeleton.tsx +37 -0
- package/src/components/slider.tsx +95 -0
- package/src/components/sonner.tsx +47 -0
- package/src/components/spinner.tsx +75 -0
- package/src/components/switch.tsx +66 -0
- package/src/components/table.tsx +200 -0
- package/src/components/tabs.tsx +128 -0
- package/src/components/textarea.tsx +49 -0
- package/src/components/toggle-group.tsx +141 -0
- package/src/components/toggle.tsx +39 -0
- package/src/components/tooltip.tsx +141 -0
- package/src/css/amber.css +59 -22
- package/src/css/blue.css +59 -22
- package/src/css/cyan.css +59 -22
- package/src/css/emerald.css +59 -22
- package/src/css/fuchsia.css +59 -22
- package/src/css/gray.css +59 -22
- package/src/css/green.css +59 -22
- package/src/css/indigo.css +59 -22
- package/src/css/lime.css +59 -22
- package/src/css/neutral.css +59 -22
- package/src/css/orange.css +59 -22
- package/src/css/pink.css +59 -22
- package/src/css/preset.css +32 -13
- package/src/css/purple.css +59 -22
- package/src/css/red.css +59 -22
- package/src/css/rose.css +59 -22
- package/src/css/sky.css +59 -22
- package/src/css/slate.css +59 -22
- package/src/css/stone.css +59 -22
- package/src/css/teal.css +59 -22
- package/src/css/violet.css +59 -22
- package/src/css/yellow.css +59 -22
- package/src/css/zinc.css +59 -22
- package/src/hooks/use-animated-value.ts +97 -0
- package/src/hooks/use-copy-to-clipboard.ts +63 -0
- package/src/hooks/use-is-mobile.ts +27 -0
- package/src/hooks/use-media-query.ts +71 -0
- package/src/hooks/use-mutation-observer.ts +54 -0
- package/src/hooks/use-pagination.ts +166 -0
- package/src/index.ts +720 -0
- package/src/lib/utils.ts +5 -0
- package/src/primitives/checkbox-group.tsx +360 -0
- package/src/primitives/input-number.tsx +1013 -0
- package/src/primitives/input.tsx +243 -0
- package/src/primitives/progress-circle.tsx +537 -0
- package/src/variants/alert.ts +45 -0
- package/src/variants/badge.ts +66 -0
- package/src/variants/button-group.ts +49 -0
- package/src/variants/button.ts +93 -0
- package/src/variants/empty.ts +43 -0
- package/src/variants/field.ts +50 -0
- package/src/variants/input-group.ts +132 -0
- package/src/variants/item.ts +90 -0
- package/src/variants/navigation-menu.ts +32 -0
- package/src/variants/progress-circle.ts +47 -0
- package/src/variants/scroll-area.ts +79 -0
- package/src/variants/separator.ts +41 -0
- package/src/variants/sheet.ts +70 -0
- package/src/variants/sidebar.ts +61 -0
- package/src/variants/toggle.ts +59 -0
- package/dist/node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/clsx.d.mts +0 -6
|
@@ -0,0 +1,1056 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type { SidebarMenuButtonVariants } from "#/variants/sidebar";
|
|
4
|
+
import type { ComponentProps, CSSProperties, Dispatch, JSX, SetStateAction } from "react";
|
|
5
|
+
|
|
6
|
+
import { cn } from "#/lib/utils";
|
|
7
|
+
|
|
8
|
+
import { sidebarMenuButtonVariants } from "#/variants/sidebar";
|
|
9
|
+
import { createContext } from "@radix-ui/react-context";
|
|
10
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
11
|
+
import { PanelLeftIcon } from "lucide-react";
|
|
12
|
+
import { useCallback, useEffect, useState } from "react";
|
|
13
|
+
|
|
14
|
+
import { Button } from "#/components/button";
|
|
15
|
+
import { Input } from "#/components/input";
|
|
16
|
+
import { Separator } from "#/components/separator";
|
|
17
|
+
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from "#/components/sheet";
|
|
18
|
+
import { Skeleton } from "#/components/skeleton";
|
|
19
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "#/components/tooltip";
|
|
20
|
+
import { useIsMobile } from "#/hooks/use-is-mobile";
|
|
21
|
+
|
|
22
|
+
const SIDEBAR_COOKIE_NAME = "sidebar_state";
|
|
23
|
+
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
|
|
24
|
+
const SIDEBAR_WIDTH = "16rem";
|
|
25
|
+
const SIDEBAR_WIDTH_MOBILE = "18rem";
|
|
26
|
+
const SIDEBAR_WIDTH_ICON = "3.0625rem";
|
|
27
|
+
const SIDEBAR_KEYBOARD_SHORTCUT = "b";
|
|
28
|
+
|
|
29
|
+
interface SidebarContextValue {
|
|
30
|
+
isMobile: boolean;
|
|
31
|
+
open: boolean;
|
|
32
|
+
openMobile: boolean;
|
|
33
|
+
setOpen: (open: boolean) => void;
|
|
34
|
+
setOpenMobile: Dispatch<SetStateAction<boolean>>;
|
|
35
|
+
state: "collapsed" | "expanded";
|
|
36
|
+
toggleSidebar: () => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* -----------------------------------------------------------------------------
|
|
40
|
+
* Context: SidebarProvider
|
|
41
|
+
* -------------------------------------------------------------------------- */
|
|
42
|
+
|
|
43
|
+
const SIDEBAR_PROVIDER_NAME = "SidebarProvider";
|
|
44
|
+
|
|
45
|
+
const [SidebarContextProvider, useSidebar] =
|
|
46
|
+
createContext<SidebarContextValue>(SIDEBAR_PROVIDER_NAME);
|
|
47
|
+
|
|
48
|
+
/* -----------------------------------------------------------------------------
|
|
49
|
+
* Component: SidebarProvider
|
|
50
|
+
* -------------------------------------------------------------------------- */
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @since 0.3.16-canary.0
|
|
54
|
+
*/
|
|
55
|
+
interface SidebarProviderProps extends ComponentProps<"div"> {
|
|
56
|
+
defaultOpen?: boolean;
|
|
57
|
+
onOpenChange?: (open: boolean) => void;
|
|
58
|
+
open?: boolean;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @since 0.3.16-canary.0
|
|
63
|
+
*/
|
|
64
|
+
function SidebarProvider({
|
|
65
|
+
children,
|
|
66
|
+
className,
|
|
67
|
+
defaultOpen = true,
|
|
68
|
+
onOpenChange: setOpenProperty,
|
|
69
|
+
open: openProperty,
|
|
70
|
+
style,
|
|
71
|
+
...props
|
|
72
|
+
}: SidebarProviderProps): JSX.Element {
|
|
73
|
+
const isMobile = useIsMobile();
|
|
74
|
+
const [openMobile, setOpenMobile] = useState(false);
|
|
75
|
+
|
|
76
|
+
// This is the internal state of the sidebar.
|
|
77
|
+
// We use openProp and setOpenProp for control from outside the component.
|
|
78
|
+
const [isOpen, setIsOpen] = useState(defaultOpen);
|
|
79
|
+
const open = openProperty ?? isOpen;
|
|
80
|
+
const setOpen = useCallback(
|
|
81
|
+
(value: ((value: boolean) => boolean) | boolean) => {
|
|
82
|
+
const openState = typeof value === "function" ? value(open) : value;
|
|
83
|
+
|
|
84
|
+
if (setOpenProperty) {
|
|
85
|
+
setOpenProperty(openState);
|
|
86
|
+
} else {
|
|
87
|
+
setIsOpen(openState);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//
|
|
91
|
+
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState.toString()}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE.toString()}`;
|
|
92
|
+
},
|
|
93
|
+
[setOpenProperty, open],
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// Helper to toggle the sidebar.
|
|
97
|
+
const toggleSidebar = useCallback(() => {
|
|
98
|
+
if (isMobile) {
|
|
99
|
+
setOpenMobile((currentValue) => !currentValue);
|
|
100
|
+
} else {
|
|
101
|
+
setOpen((currentValue) => !currentValue);
|
|
102
|
+
}
|
|
103
|
+
}, [isMobile, setOpen]);
|
|
104
|
+
|
|
105
|
+
// Adds a keyboard shortcut to toggle the sidebar.
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
const handleKeyDown: (event: KeyboardEvent) => void = (event: KeyboardEvent) => {
|
|
108
|
+
if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
toggleSidebar();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
115
|
+
|
|
116
|
+
return (): void => {
|
|
117
|
+
window.removeEventListener("keydown", handleKeyDown);
|
|
118
|
+
};
|
|
119
|
+
}, [toggleSidebar]);
|
|
120
|
+
|
|
121
|
+
// We add a state so that we can do data-state="expanded" or "collapsed".
|
|
122
|
+
// This makes it easier to style the sidebar with Tailwind classes.
|
|
123
|
+
const state = open ? "expanded" : "collapsed";
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<SidebarContextProvider
|
|
127
|
+
isMobile={isMobile}
|
|
128
|
+
open={open}
|
|
129
|
+
openMobile={openMobile}
|
|
130
|
+
setOpen={setOpen}
|
|
131
|
+
setOpenMobile={setOpenMobile}
|
|
132
|
+
state={state}
|
|
133
|
+
toggleSidebar={toggleSidebar}
|
|
134
|
+
>
|
|
135
|
+
<TooltipProvider delayDuration={0}>
|
|
136
|
+
<div
|
|
137
|
+
className={cn(
|
|
138
|
+
"group/sidebar-wrapper flex min-h-svh w-full",
|
|
139
|
+
"has-data-[variant=inset]:bg-sidebar",
|
|
140
|
+
className,
|
|
141
|
+
)}
|
|
142
|
+
data-slot="sidebar-wrapper"
|
|
143
|
+
style={
|
|
144
|
+
{
|
|
145
|
+
"--sidebar-width": SIDEBAR_WIDTH,
|
|
146
|
+
"--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
|
|
147
|
+
...style,
|
|
148
|
+
} as CSSProperties
|
|
149
|
+
}
|
|
150
|
+
{...props}
|
|
151
|
+
>
|
|
152
|
+
{children}
|
|
153
|
+
</div>
|
|
154
|
+
</TooltipProvider>
|
|
155
|
+
</SidebarContextProvider>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/* -----------------------------------------------------------------------------
|
|
160
|
+
* Component: Sidebar
|
|
161
|
+
* -------------------------------------------------------------------------- */
|
|
162
|
+
|
|
163
|
+
const SIDEBAR_NAME = "Sidebar";
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @since 0.3.16-canary.0
|
|
167
|
+
*/
|
|
168
|
+
interface SidebarProps extends ComponentProps<"div"> {
|
|
169
|
+
collapsible?: "icon" | "none" | "offcanvas";
|
|
170
|
+
side?: "left" | "right";
|
|
171
|
+
variant?: "floating" | "inset" | "sidebar";
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @since 0.3.16-canary.0
|
|
176
|
+
*/
|
|
177
|
+
function Sidebar({
|
|
178
|
+
children,
|
|
179
|
+
className,
|
|
180
|
+
collapsible = "offcanvas",
|
|
181
|
+
side = "left",
|
|
182
|
+
variant = "sidebar",
|
|
183
|
+
...props
|
|
184
|
+
}: SidebarProps): JSX.Element {
|
|
185
|
+
const { isMobile, openMobile, setOpenMobile, state } = useSidebar(SIDEBAR_NAME);
|
|
186
|
+
|
|
187
|
+
if (collapsible === "none") {
|
|
188
|
+
return (
|
|
189
|
+
<div
|
|
190
|
+
className={cn(
|
|
191
|
+
"flex h-full w-(--sidebar-width) flex-col",
|
|
192
|
+
"bg-sidebar text-sidebar-foreground",
|
|
193
|
+
className,
|
|
194
|
+
)}
|
|
195
|
+
data-slot="sidebar"
|
|
196
|
+
{...props}
|
|
197
|
+
>
|
|
198
|
+
{children}
|
|
199
|
+
</div>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (isMobile) {
|
|
204
|
+
return (
|
|
205
|
+
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
|
|
206
|
+
<SheetContent
|
|
207
|
+
className={cn(
|
|
208
|
+
"w-(--sidebar-width) p-0",
|
|
209
|
+
"bg-sidebar text-sidebar-foreground",
|
|
210
|
+
"[&>button]:hidden",
|
|
211
|
+
)}
|
|
212
|
+
data-mobile="true"
|
|
213
|
+
data-sidebar="sidebar"
|
|
214
|
+
data-slot="sidebar"
|
|
215
|
+
side={side}
|
|
216
|
+
style={
|
|
217
|
+
{
|
|
218
|
+
"--sidebar-width": SIDEBAR_WIDTH_MOBILE,
|
|
219
|
+
} as CSSProperties
|
|
220
|
+
}
|
|
221
|
+
>
|
|
222
|
+
<SheetHeader className="sr-only">
|
|
223
|
+
<SheetTitle>Sidebar</SheetTitle>
|
|
224
|
+
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
|
225
|
+
</SheetHeader>
|
|
226
|
+
<div className="flex h-full w-full flex-col">{children}</div>
|
|
227
|
+
</SheetContent>
|
|
228
|
+
</Sheet>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return (
|
|
233
|
+
<div
|
|
234
|
+
className={cn("group peer hidden", "text-sidebar-foreground", "md:block", className)}
|
|
235
|
+
data-collapsible={state === "collapsed" ? collapsible : ""}
|
|
236
|
+
data-side={side}
|
|
237
|
+
data-slot="sidebar"
|
|
238
|
+
data-state={state}
|
|
239
|
+
data-variant={variant}
|
|
240
|
+
>
|
|
241
|
+
{/* This is what handles the sidebar gap on desktop */}
|
|
242
|
+
<div
|
|
243
|
+
className={cn(
|
|
244
|
+
"relative",
|
|
245
|
+
"w-(--sidebar-width)",
|
|
246
|
+
"bg-transparent",
|
|
247
|
+
"transition-[width] duration-200 ease-linear",
|
|
248
|
+
"motion-reduce:transition-none motion-reduce:duration-0",
|
|
249
|
+
"group-data-[collapsible=offcanvas]:w-0",
|
|
250
|
+
"group-data-side-right:rotate-180",
|
|
251
|
+
variant === "floating" || variant === "inset"
|
|
252
|
+
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
|
|
253
|
+
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon)",
|
|
254
|
+
)}
|
|
255
|
+
data-slot="sidebar-gap"
|
|
256
|
+
/>
|
|
257
|
+
<div
|
|
258
|
+
className={cn(
|
|
259
|
+
"fixed inset-y-0 z-10 hidden",
|
|
260
|
+
"h-svh w-(--sidebar-width)",
|
|
261
|
+
"transition-[left,right,width] duration-200 ease-linear",
|
|
262
|
+
"motion-reduce:transition-none motion-reduce:duration-0",
|
|
263
|
+
"md:flex",
|
|
264
|
+
side === "left"
|
|
265
|
+
? "left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]"
|
|
266
|
+
: "right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
|
|
267
|
+
variant === "floating" || variant === "inset"
|
|
268
|
+
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
|
|
269
|
+
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-side-right:border-l group-data-side-left:border-r",
|
|
270
|
+
className,
|
|
271
|
+
)}
|
|
272
|
+
data-slot="sidebar-container"
|
|
273
|
+
{...props}
|
|
274
|
+
>
|
|
275
|
+
<div
|
|
276
|
+
className={cn(
|
|
277
|
+
"flex h-full w-full flex-col",
|
|
278
|
+
"bg-sidebar",
|
|
279
|
+
"group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow-sm",
|
|
280
|
+
)}
|
|
281
|
+
data-sidebar="sidebar"
|
|
282
|
+
data-slot="sidebar-inner"
|
|
283
|
+
>
|
|
284
|
+
{children}
|
|
285
|
+
</div>
|
|
286
|
+
</div>
|
|
287
|
+
</div>
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/* -----------------------------------------------------------------------------
|
|
292
|
+
* Component: SidebarTrigger
|
|
293
|
+
* -------------------------------------------------------------------------- */
|
|
294
|
+
|
|
295
|
+
const SIDEBAR_TRIGGER_NAME = "SidebarTrigger";
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @since 0.3.16-canary.0
|
|
299
|
+
*/
|
|
300
|
+
type SidebarTriggerProps = ComponentProps<typeof Button>;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* @since 0.3.16-canary.0
|
|
304
|
+
*/
|
|
305
|
+
function SidebarTrigger({ className, onClick, ...props }: SidebarTriggerProps): JSX.Element {
|
|
306
|
+
const { toggleSidebar } = useSidebar(SIDEBAR_TRIGGER_NAME);
|
|
307
|
+
|
|
308
|
+
return (
|
|
309
|
+
<Button
|
|
310
|
+
className={cn("size-7", className)}
|
|
311
|
+
data-sidebar="trigger"
|
|
312
|
+
data-slot="sidebar-trigger"
|
|
313
|
+
size="icon"
|
|
314
|
+
variant="ghost"
|
|
315
|
+
onClick={(event) => {
|
|
316
|
+
onClick?.(event);
|
|
317
|
+
toggleSidebar();
|
|
318
|
+
}}
|
|
319
|
+
{...props}
|
|
320
|
+
>
|
|
321
|
+
<PanelLeftIcon />
|
|
322
|
+
<span className="sr-only">Toggle Sidebar</span>
|
|
323
|
+
</Button>
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/* -----------------------------------------------------------------------------
|
|
328
|
+
* Component: SidebarRail
|
|
329
|
+
* -------------------------------------------------------------------------- */
|
|
330
|
+
|
|
331
|
+
const SIDEBAR_RAIL_NAME = "SidebarRail";
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* @since 0.3.16-canary.0
|
|
335
|
+
*/
|
|
336
|
+
type SidebarRailProps = ComponentProps<"button">;
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* @since 0.3.16-canary.0
|
|
340
|
+
*/
|
|
341
|
+
function SidebarRail({ className, ...props }: SidebarRailProps): JSX.Element {
|
|
342
|
+
const { toggleSidebar } = useSidebar(SIDEBAR_RAIL_NAME);
|
|
343
|
+
|
|
344
|
+
return (
|
|
345
|
+
<button
|
|
346
|
+
className={cn(
|
|
347
|
+
"absolute inset-y-0 z-20 hidden",
|
|
348
|
+
"w-4 -translate-x-1/2 transition-all ease-linear",
|
|
349
|
+
"motion-reduce:transition-none",
|
|
350
|
+
"in-data-side-right:cursor-e-resize",
|
|
351
|
+
"in-data-side-left:cursor-w-resize",
|
|
352
|
+
"group-data-[collapsible=offcanvas]:translate-x-0",
|
|
353
|
+
"group-data-side-right:left-0",
|
|
354
|
+
"group-data-side-left:-right-4",
|
|
355
|
+
"after:absolute after:inset-y-0 after:left-1/2 after:w-0.5",
|
|
356
|
+
"group-data-[collapsible=offcanvas]:after:left-full",
|
|
357
|
+
"hover:group-data-[collapsible=offcanvas]:bg-sidebar",
|
|
358
|
+
"hover:after:bg-sidebar-border",
|
|
359
|
+
"sm:flex",
|
|
360
|
+
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
|
|
361
|
+
"[[data-side=left][data-state=collapsed]_&]:cursor-e-resize",
|
|
362
|
+
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
|
|
363
|
+
"[[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
|
|
364
|
+
className,
|
|
365
|
+
)}
|
|
366
|
+
data-sidebar="rail"
|
|
367
|
+
data-slot="sidebar-rail"
|
|
368
|
+
title="Toggle Sidebar"
|
|
369
|
+
type="button"
|
|
370
|
+
onClick={toggleSidebar}
|
|
371
|
+
{...props}
|
|
372
|
+
/>
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/* -----------------------------------------------------------------------------
|
|
377
|
+
* Component: SidebarInset
|
|
378
|
+
* -------------------------------------------------------------------------- */
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* @since 0.3.16-canary.0
|
|
382
|
+
*/
|
|
383
|
+
type SidebarInsetProps = ComponentProps<"main">;
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* @since 0.3.16-canary.0
|
|
387
|
+
*/
|
|
388
|
+
function SidebarInset({ className, ...props }: SidebarInsetProps): JSX.Element {
|
|
389
|
+
return (
|
|
390
|
+
<main
|
|
391
|
+
className={cn(
|
|
392
|
+
"relative flex w-full min-w-0 flex-1 flex-col",
|
|
393
|
+
"bg-background",
|
|
394
|
+
"md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm",
|
|
395
|
+
"md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
|
|
396
|
+
className,
|
|
397
|
+
)}
|
|
398
|
+
data-slot="sidebar-inset"
|
|
399
|
+
{...props}
|
|
400
|
+
/>
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/* -----------------------------------------------------------------------------
|
|
405
|
+
* Component: SidebarInput
|
|
406
|
+
* -------------------------------------------------------------------------- */
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* @since 0.3.16-canary.0
|
|
410
|
+
*/
|
|
411
|
+
type SidebarInputProps = ComponentProps<typeof Input>;
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* @since 0.3.16-canary.0
|
|
415
|
+
*/
|
|
416
|
+
function SidebarInput({ className, ...props }: SidebarInputProps): JSX.Element {
|
|
417
|
+
return (
|
|
418
|
+
<Input
|
|
419
|
+
className={cn("h-8 w-full", "bg-background shadow-none", className)}
|
|
420
|
+
data-sidebar="input"
|
|
421
|
+
data-slot="sidebar-input"
|
|
422
|
+
{...props}
|
|
423
|
+
/>
|
|
424
|
+
);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/* -----------------------------------------------------------------------------
|
|
428
|
+
* Component: SidebarHeader
|
|
429
|
+
* -------------------------------------------------------------------------- */
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* @since 0.3.16-canary.0
|
|
433
|
+
*/
|
|
434
|
+
type SidebarHeaderProps = ComponentProps<"div">;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* @since 0.3.16-canary.0
|
|
438
|
+
*/
|
|
439
|
+
function SidebarHeader({ className, ...props }: SidebarHeaderProps): JSX.Element {
|
|
440
|
+
return (
|
|
441
|
+
<div
|
|
442
|
+
className={cn("flex flex-col gap-2", "p-2", className)}
|
|
443
|
+
data-sidebar="header"
|
|
444
|
+
data-slot="sidebar-header"
|
|
445
|
+
{...props}
|
|
446
|
+
/>
|
|
447
|
+
);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/* -----------------------------------------------------------------------------
|
|
451
|
+
* Component: SidebarFooter
|
|
452
|
+
* -------------------------------------------------------------------------- */
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* @since 0.3.16-canary.0
|
|
456
|
+
*/
|
|
457
|
+
type SidebarFooterProps = ComponentProps<"div">;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* @since 0.3.16-canary.0
|
|
461
|
+
*/
|
|
462
|
+
function SidebarFooter({ className, ...props }: SidebarFooterProps): JSX.Element {
|
|
463
|
+
return (
|
|
464
|
+
<div
|
|
465
|
+
className={cn("flex flex-col gap-2", "p-2", className)}
|
|
466
|
+
data-sidebar="footer"
|
|
467
|
+
data-slot="sidebar-footer"
|
|
468
|
+
{...props}
|
|
469
|
+
/>
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/* -----------------------------------------------------------------------------
|
|
474
|
+
* Component: SidebarSeparator
|
|
475
|
+
* -------------------------------------------------------------------------- */
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* @since 0.3.16-canary.0
|
|
479
|
+
*/
|
|
480
|
+
type SidebarSeparatorProps = ComponentProps<typeof Separator>;
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* @since 0.3.16-canary.0
|
|
484
|
+
*/
|
|
485
|
+
function SidebarSeparator({ className, ...props }: SidebarSeparatorProps): JSX.Element {
|
|
486
|
+
return (
|
|
487
|
+
<Separator
|
|
488
|
+
className={cn("mx-2 w-auto", "bg-sidebar-border", className)}
|
|
489
|
+
data-sidebar="separator"
|
|
490
|
+
data-slot="sidebar-separator"
|
|
491
|
+
{...props}
|
|
492
|
+
/>
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/* -----------------------------------------------------------------------------
|
|
497
|
+
* Component: SidebarContent
|
|
498
|
+
* -------------------------------------------------------------------------- */
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* @since 0.3.16-canary.0
|
|
502
|
+
*/
|
|
503
|
+
type SidebarContentProps = ComponentProps<"div">;
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* @since 0.3.16-canary.0
|
|
507
|
+
*/
|
|
508
|
+
function SidebarContent({ className, ...props }: SidebarContentProps): JSX.Element {
|
|
509
|
+
return (
|
|
510
|
+
<div
|
|
511
|
+
className={cn(
|
|
512
|
+
"flex min-h-0 flex-1 flex-col gap-2 overflow-auto",
|
|
513
|
+
"group-data-[collapsible=icon]:overflow-hidden",
|
|
514
|
+
className,
|
|
515
|
+
)}
|
|
516
|
+
data-sidebar="content"
|
|
517
|
+
data-slot="sidebar-content"
|
|
518
|
+
{...props}
|
|
519
|
+
/>
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/* -----------------------------------------------------------------------------
|
|
524
|
+
* Component: SidebarGroup
|
|
525
|
+
* -------------------------------------------------------------------------- */
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* @since 0.3.16-canary.0
|
|
529
|
+
*/
|
|
530
|
+
type SidebarGroupProps = ComponentProps<"div">;
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* @since 0.3.16-canary.0
|
|
534
|
+
*/
|
|
535
|
+
function SidebarGroup({ className, ...props }: SidebarGroupProps): JSX.Element {
|
|
536
|
+
return (
|
|
537
|
+
<div
|
|
538
|
+
className={cn("relative flex w-full min-w-0 flex-col", "p-2", className)}
|
|
539
|
+
data-sidebar="group"
|
|
540
|
+
data-slot="sidebar-group"
|
|
541
|
+
{...props}
|
|
542
|
+
/>
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/* -----------------------------------------------------------------------------
|
|
547
|
+
* Component: SidebarGroupLabel
|
|
548
|
+
* -------------------------------------------------------------------------- */
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* @since 0.3.16-canary.0
|
|
552
|
+
*/
|
|
553
|
+
interface SidebarGroupLabelProps extends ComponentProps<"div"> {
|
|
554
|
+
asChild?: boolean;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* @since 0.3.16-canary.0
|
|
559
|
+
*/
|
|
560
|
+
function SidebarGroupLabel({
|
|
561
|
+
asChild = false,
|
|
562
|
+
className,
|
|
563
|
+
...props
|
|
564
|
+
}: SidebarGroupLabelProps): JSX.Element {
|
|
565
|
+
const Component = asChild ? Slot : "div";
|
|
566
|
+
|
|
567
|
+
return (
|
|
568
|
+
<Component
|
|
569
|
+
className={cn(
|
|
570
|
+
"flex h-8 shrink-0 items-center px-2",
|
|
571
|
+
"rounded-md ring-sidebar-ring outline-hidden",
|
|
572
|
+
"truncate text-xs font-medium text-sidebar-foreground/70",
|
|
573
|
+
"transition-[margin,opacity] duration-200 ease-linear",
|
|
574
|
+
"motion-reduce:transition-none motion-reduce:duration-0",
|
|
575
|
+
"group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
|
|
576
|
+
"focus-visible:ring-3",
|
|
577
|
+
"[&>svg]:size-4 [&>svg]:shrink-0",
|
|
578
|
+
className,
|
|
579
|
+
)}
|
|
580
|
+
data-sidebar="group-label"
|
|
581
|
+
data-slot="sidebar-group-label"
|
|
582
|
+
{...props}
|
|
583
|
+
/>
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/* -----------------------------------------------------------------------------
|
|
588
|
+
* Component: SidebarGroupAction
|
|
589
|
+
* -------------------------------------------------------------------------- */
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* @since 0.3.16-canary.0
|
|
593
|
+
*/
|
|
594
|
+
interface SidebarGroupActionProps extends ComponentProps<"button"> {
|
|
595
|
+
asChild?: boolean;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* @since 0.3.16-canary.0
|
|
600
|
+
*/
|
|
601
|
+
function SidebarGroupAction({
|
|
602
|
+
asChild = false,
|
|
603
|
+
className,
|
|
604
|
+
...props
|
|
605
|
+
}: SidebarGroupActionProps): JSX.Element {
|
|
606
|
+
const Component = asChild ? Slot : "button";
|
|
607
|
+
|
|
608
|
+
return (
|
|
609
|
+
<Component
|
|
610
|
+
className={cn(
|
|
611
|
+
"absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center p-0",
|
|
612
|
+
"rounded-md ring-sidebar-ring outline-hidden",
|
|
613
|
+
"text-sidebar-foreground",
|
|
614
|
+
"transition-transform",
|
|
615
|
+
"motion-reduce:transition-none",
|
|
616
|
+
"group-data-[collapsible=icon]:hidden",
|
|
617
|
+
"after:absolute after:-inset-2",
|
|
618
|
+
"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
|
619
|
+
"focus-visible:ring-3",
|
|
620
|
+
"md:after:hidden",
|
|
621
|
+
"[&>svg]:size-4 [&>svg]:shrink-0",
|
|
622
|
+
className,
|
|
623
|
+
)}
|
|
624
|
+
data-sidebar="group-action"
|
|
625
|
+
data-slot="sidebar-group-action"
|
|
626
|
+
{...props}
|
|
627
|
+
/>
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/* -----------------------------------------------------------------------------
|
|
632
|
+
* Component: SidebarGroupContent
|
|
633
|
+
* -------------------------------------------------------------------------- */
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* @since 0.3.16-canary.0
|
|
637
|
+
*/
|
|
638
|
+
type SidebarGroupContentProps = ComponentProps<"div">;
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* @since 0.3.16-canary.0
|
|
642
|
+
*/
|
|
643
|
+
function SidebarGroupContent({ className, ...props }: SidebarGroupContentProps): JSX.Element {
|
|
644
|
+
return (
|
|
645
|
+
<div
|
|
646
|
+
className={cn("w-full", "text-sm", className)}
|
|
647
|
+
data-sidebar="group-content"
|
|
648
|
+
data-slot="sidebar-group-content"
|
|
649
|
+
{...props}
|
|
650
|
+
/>
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/* -----------------------------------------------------------------------------
|
|
655
|
+
* Component: SidebarMenu
|
|
656
|
+
* -------------------------------------------------------------------------- */
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* @since 0.3.16-canary.0
|
|
660
|
+
*/
|
|
661
|
+
type SidebarMenuProps = ComponentProps<"ul">;
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* @since 0.3.16-canary.0
|
|
665
|
+
*/
|
|
666
|
+
function SidebarMenu({ className, ...props }: SidebarMenuProps): JSX.Element {
|
|
667
|
+
return (
|
|
668
|
+
<ul
|
|
669
|
+
className={cn("flex w-full min-w-0 flex-col gap-1", className)}
|
|
670
|
+
data-sidebar="menu"
|
|
671
|
+
data-slot="sidebar-menu"
|
|
672
|
+
{...props}
|
|
673
|
+
/>
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
/* -----------------------------------------------------------------------------
|
|
678
|
+
* Component: SidebarMenuItem
|
|
679
|
+
* -------------------------------------------------------------------------- */
|
|
680
|
+
|
|
681
|
+
/**
|
|
682
|
+
* @since 0.3.16-canary.0
|
|
683
|
+
*/
|
|
684
|
+
type SidebarMenuItemProps = ComponentProps<"li">;
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* @since 0.3.16-canary.0
|
|
688
|
+
*/
|
|
689
|
+
function SidebarMenuItem({ className, ...props }: SidebarMenuItemProps): JSX.Element {
|
|
690
|
+
return (
|
|
691
|
+
<li
|
|
692
|
+
className={cn("group/menu-item relative", className)}
|
|
693
|
+
data-sidebar="menu-item"
|
|
694
|
+
data-slot="sidebar-menu-item"
|
|
695
|
+
{...props}
|
|
696
|
+
/>
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/* -----------------------------------------------------------------------------
|
|
701
|
+
* Component: SidebarMenuButton
|
|
702
|
+
* -------------------------------------------------------------------------- */
|
|
703
|
+
|
|
704
|
+
const SIDEBAR_MENU_BUTTON_NAME = "SidebarMenuButton";
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* @since 0.3.16-canary.0
|
|
708
|
+
*/
|
|
709
|
+
interface SidebarMenuButtonProps extends ComponentProps<"button">, SidebarMenuButtonVariants {
|
|
710
|
+
asChild?: boolean;
|
|
711
|
+
isActive?: boolean;
|
|
712
|
+
tooltip?: ComponentProps<typeof TooltipContent> | string;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* @since 0.3.16-canary.0
|
|
717
|
+
*/
|
|
718
|
+
function SidebarMenuButton({
|
|
719
|
+
asChild = false,
|
|
720
|
+
className,
|
|
721
|
+
isActive = false,
|
|
722
|
+
size = "md",
|
|
723
|
+
tooltip,
|
|
724
|
+
variant = "default",
|
|
725
|
+
...props
|
|
726
|
+
}: SidebarMenuButtonProps): JSX.Element {
|
|
727
|
+
const Component = asChild ? Slot : "button";
|
|
728
|
+
const { isMobile, state } = useSidebar(SIDEBAR_MENU_BUTTON_NAME);
|
|
729
|
+
|
|
730
|
+
const button = (
|
|
731
|
+
<Component
|
|
732
|
+
className={cn(sidebarMenuButtonVariants({ size, variant }), className)}
|
|
733
|
+
data-active={isActive}
|
|
734
|
+
data-sidebar="menu-button"
|
|
735
|
+
data-size={size}
|
|
736
|
+
data-slot="sidebar-menu-button"
|
|
737
|
+
{...props}
|
|
738
|
+
/>
|
|
739
|
+
);
|
|
740
|
+
|
|
741
|
+
if (!tooltip) {
|
|
742
|
+
return button;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
if (typeof tooltip === "string") {
|
|
746
|
+
tooltip = {
|
|
747
|
+
children: tooltip,
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
return (
|
|
752
|
+
<Tooltip>
|
|
753
|
+
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
|
754
|
+
<TooltipContent
|
|
755
|
+
align="center"
|
|
756
|
+
hidden={state !== "collapsed" || isMobile}
|
|
757
|
+
side="right"
|
|
758
|
+
{...tooltip}
|
|
759
|
+
/>
|
|
760
|
+
</Tooltip>
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/* -----------------------------------------------------------------------------
|
|
765
|
+
* Component: SidebarMenuAction
|
|
766
|
+
* -------------------------------------------------------------------------- */
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* @since 0.3.16-canary.0
|
|
770
|
+
*/
|
|
771
|
+
interface SidebarMenuActionProps extends ComponentProps<"button"> {
|
|
772
|
+
asChild?: boolean;
|
|
773
|
+
showOnHover?: boolean;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* @since 0.3.16-canary.0
|
|
778
|
+
*/
|
|
779
|
+
function SidebarMenuAction({
|
|
780
|
+
asChild = false,
|
|
781
|
+
className,
|
|
782
|
+
showOnHover = false,
|
|
783
|
+
...props
|
|
784
|
+
}: SidebarMenuActionProps): JSX.Element {
|
|
785
|
+
const Component = asChild ? Slot : "button";
|
|
786
|
+
|
|
787
|
+
return (
|
|
788
|
+
<Component
|
|
789
|
+
className={cn(
|
|
790
|
+
"absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center p-0",
|
|
791
|
+
"rounded-md ring-sidebar-ring outline-hidden",
|
|
792
|
+
"text-sidebar-foreground",
|
|
793
|
+
"transition-transform",
|
|
794
|
+
"motion-reduce:transition-none",
|
|
795
|
+
"group-data-[collapsible=icon]:hidden",
|
|
796
|
+
"peer-hover/menu-button:text-sidebar-accent-foreground",
|
|
797
|
+
"peer-data-[size=default]/menu-button:top-1.5",
|
|
798
|
+
"peer-data-[size=lg]/menu-button:top-2.5",
|
|
799
|
+
"peer-data-[size=sm]/menu-button:top-1",
|
|
800
|
+
"after:absolute after:-inset-2",
|
|
801
|
+
"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
|
802
|
+
"focus-visible:ring-3",
|
|
803
|
+
"md:after:hidden",
|
|
804
|
+
"[&>svg]:size-4 [&>svg]:shrink-0",
|
|
805
|
+
showOnHover &&
|
|
806
|
+
"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 peer-data-active/menu-button:text-sidebar-accent-foreground md:opacity-0 data-open:opacity-100",
|
|
807
|
+
className,
|
|
808
|
+
)}
|
|
809
|
+
data-sidebar="menu-action"
|
|
810
|
+
data-slot="sidebar-menu-action"
|
|
811
|
+
{...props}
|
|
812
|
+
/>
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/* -----------------------------------------------------------------------------
|
|
817
|
+
* Component: SidebarMenuBadge
|
|
818
|
+
* -------------------------------------------------------------------------- */
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* @since 0.3.16-canary.0
|
|
822
|
+
*/
|
|
823
|
+
type SidebarMenuBadgeProps = ComponentProps<"div">;
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* @since 0.3.16-canary.0
|
|
827
|
+
*/
|
|
828
|
+
function SidebarMenuBadge({ className, ...props }: SidebarMenuBadgeProps): JSX.Element {
|
|
829
|
+
return (
|
|
830
|
+
<div
|
|
831
|
+
className={cn(
|
|
832
|
+
"absolute right-1 flex h-5 min-w-5 items-center justify-center px-1",
|
|
833
|
+
"rounded-md",
|
|
834
|
+
"text-xs font-medium text-sidebar-foreground tabular-nums",
|
|
835
|
+
"pointer-events-none select-none",
|
|
836
|
+
"group-data-[collapsible=icon]:hidden",
|
|
837
|
+
"peer-hover/menu-button:text-sidebar-accent-foreground",
|
|
838
|
+
"peer-data-[size=default]/menu-button:top-1.5",
|
|
839
|
+
"peer-data-[size=lg]/menu-button:top-2.5",
|
|
840
|
+
"peer-data-[size=sm]/menu-button:top-1",
|
|
841
|
+
"peer-data-active/menu-button:text-sidebar-accent-foreground",
|
|
842
|
+
className,
|
|
843
|
+
)}
|
|
844
|
+
data-sidebar="menu-badge"
|
|
845
|
+
data-slot="sidebar-menu-badge"
|
|
846
|
+
{...props}
|
|
847
|
+
/>
|
|
848
|
+
);
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/* -----------------------------------------------------------------------------
|
|
852
|
+
* Component: SidebarMenuSkeleton
|
|
853
|
+
* -------------------------------------------------------------------------- */
|
|
854
|
+
|
|
855
|
+
/**
|
|
856
|
+
* @since 0.3.16-canary.0
|
|
857
|
+
*/
|
|
858
|
+
interface SidebarMenuSkeletonProps extends ComponentProps<"div"> {
|
|
859
|
+
showIcon?: boolean;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* @since 0.3.16-canary.0
|
|
864
|
+
*/
|
|
865
|
+
function SidebarMenuSkeleton({
|
|
866
|
+
className,
|
|
867
|
+
showIcon = false,
|
|
868
|
+
...props
|
|
869
|
+
}: SidebarMenuSkeletonProps): JSX.Element {
|
|
870
|
+
// Random width between 50 to 90% - use useState with lazy initializer to avoid calling Math.random during render
|
|
871
|
+
const [width] = useState(() => `${String(Math.floor(Math.random() * 40) + 50)}%`);
|
|
872
|
+
|
|
873
|
+
return (
|
|
874
|
+
<div
|
|
875
|
+
className={cn("flex h-8 items-center gap-2 px-2", "rounded-md", className)}
|
|
876
|
+
data-sidebar="menu-skeleton"
|
|
877
|
+
data-slot="sidebar-menu-skeleton"
|
|
878
|
+
{...props}
|
|
879
|
+
>
|
|
880
|
+
{showIcon ? (
|
|
881
|
+
<Skeleton className={cn("size-4", "rounded-md")} data-sidebar="menu-skeleton-icon" />
|
|
882
|
+
) : null}
|
|
883
|
+
<Skeleton
|
|
884
|
+
className="h-4 max-w-(--skeleton-width) flex-1"
|
|
885
|
+
data-sidebar="menu-skeleton-text"
|
|
886
|
+
style={
|
|
887
|
+
{
|
|
888
|
+
"--skeleton-width": width,
|
|
889
|
+
} as CSSProperties
|
|
890
|
+
}
|
|
891
|
+
/>
|
|
892
|
+
</div>
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/* -----------------------------------------------------------------------------
|
|
897
|
+
* Component: SidebarMenuSub
|
|
898
|
+
* -------------------------------------------------------------------------- */
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* @since 0.3.16-canary.0
|
|
902
|
+
*/
|
|
903
|
+
type SidebarMenuSubProps = ComponentProps<"ul">;
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* @since 0.3.16-canary.0
|
|
907
|
+
*/
|
|
908
|
+
function SidebarMenuSub({ className, ...props }: SidebarMenuSubProps): JSX.Element {
|
|
909
|
+
return (
|
|
910
|
+
<ul
|
|
911
|
+
className={cn(
|
|
912
|
+
"mx-3.5 flex min-w-0 flex-col gap-1 px-2.5 py-0.5",
|
|
913
|
+
"border-l border-sidebar-border",
|
|
914
|
+
"translate-x-px",
|
|
915
|
+
"group-data-[collapsible=icon]:hidden",
|
|
916
|
+
className,
|
|
917
|
+
)}
|
|
918
|
+
data-sidebar="menu-sub"
|
|
919
|
+
data-slot="sidebar-menu-sub"
|
|
920
|
+
{...props}
|
|
921
|
+
/>
|
|
922
|
+
);
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/* -----------------------------------------------------------------------------
|
|
926
|
+
* Component: SidebarMenuSubItem
|
|
927
|
+
* -------------------------------------------------------------------------- */
|
|
928
|
+
|
|
929
|
+
/**
|
|
930
|
+
* @since 0.3.16-canary.0
|
|
931
|
+
*/
|
|
932
|
+
type SidebarMenuSubItemProps = ComponentProps<"li">;
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* @since 0.3.16-canary.0
|
|
936
|
+
*/
|
|
937
|
+
function SidebarMenuSubItem({ className, ...props }: SidebarMenuSubItemProps): JSX.Element {
|
|
938
|
+
return (
|
|
939
|
+
<li
|
|
940
|
+
className={cn("group/menu-sub-item relative", className)}
|
|
941
|
+
data-sidebar="menu-sub-item"
|
|
942
|
+
data-slot="sidebar-menu-sub-item"
|
|
943
|
+
{...props}
|
|
944
|
+
/>
|
|
945
|
+
);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/* -----------------------------------------------------------------------------
|
|
949
|
+
* Component: SidebarMenuSubButton
|
|
950
|
+
* -------------------------------------------------------------------------- */
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* @since 0.3.16-canary.0
|
|
954
|
+
*/
|
|
955
|
+
interface SidebarMenuSubButtonProps extends ComponentProps<"a"> {
|
|
956
|
+
asChild?: boolean;
|
|
957
|
+
isActive?: boolean;
|
|
958
|
+
size?: "md" | "sm";
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* @since 0.3.16-canary.0
|
|
963
|
+
*/
|
|
964
|
+
function SidebarMenuSubButton({
|
|
965
|
+
asChild = false,
|
|
966
|
+
className,
|
|
967
|
+
isActive = false,
|
|
968
|
+
size = "md",
|
|
969
|
+
...props
|
|
970
|
+
}: SidebarMenuSubButtonProps): JSX.Element {
|
|
971
|
+
const Component = asChild ? Slot : "a";
|
|
972
|
+
|
|
973
|
+
return (
|
|
974
|
+
<Component
|
|
975
|
+
className={cn(
|
|
976
|
+
"flex h-7 min-w-0 items-center gap-2 overflow-hidden px-2",
|
|
977
|
+
"rounded-md ring-sidebar-ring outline-hidden",
|
|
978
|
+
"text-sidebar-foreground",
|
|
979
|
+
"-translate-x-px",
|
|
980
|
+
"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
|
981
|
+
"focus-visible:ring-3",
|
|
982
|
+
"active:bg-sidebar-accent active:text-sidebar-accent-foreground",
|
|
983
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
984
|
+
"aria-disabled:pointer-events-none aria-disabled:opacity-50",
|
|
985
|
+
"data-active:bg-sidebar-accent data-active:text-sidebar-accent-foreground",
|
|
986
|
+
"group-data-[collapsible=icon]:hidden",
|
|
987
|
+
"[&>span:last-child]:truncate",
|
|
988
|
+
"[&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground",
|
|
989
|
+
size === "sm" && "text-xs",
|
|
990
|
+
size === "md" && "text-sm",
|
|
991
|
+
className,
|
|
992
|
+
)}
|
|
993
|
+
data-active={isActive}
|
|
994
|
+
data-sidebar="menu-sub-button"
|
|
995
|
+
data-size={size}
|
|
996
|
+
data-slot="sidebar-menu-sub-button"
|
|
997
|
+
{...props}
|
|
998
|
+
/>
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
/* -----------------------------------------------------------------------------
|
|
1003
|
+
* Exports
|
|
1004
|
+
* -------------------------------------------------------------------------- */
|
|
1005
|
+
|
|
1006
|
+
export {
|
|
1007
|
+
Sidebar,
|
|
1008
|
+
SidebarContent,
|
|
1009
|
+
SidebarFooter,
|
|
1010
|
+
SidebarGroup,
|
|
1011
|
+
SidebarGroupAction,
|
|
1012
|
+
SidebarGroupContent,
|
|
1013
|
+
SidebarGroupLabel,
|
|
1014
|
+
SidebarHeader,
|
|
1015
|
+
SidebarInput,
|
|
1016
|
+
SidebarInset,
|
|
1017
|
+
SidebarMenu,
|
|
1018
|
+
SidebarMenuAction,
|
|
1019
|
+
SidebarMenuBadge,
|
|
1020
|
+
SidebarMenuButton,
|
|
1021
|
+
SidebarMenuItem,
|
|
1022
|
+
SidebarMenuSkeleton,
|
|
1023
|
+
SidebarMenuSub,
|
|
1024
|
+
SidebarMenuSubButton,
|
|
1025
|
+
SidebarMenuSubItem,
|
|
1026
|
+
SidebarProvider,
|
|
1027
|
+
SidebarRail,
|
|
1028
|
+
SidebarSeparator,
|
|
1029
|
+
SidebarTrigger,
|
|
1030
|
+
useSidebar,
|
|
1031
|
+
};
|
|
1032
|
+
export type {
|
|
1033
|
+
SidebarContentProps,
|
|
1034
|
+
SidebarFooterProps,
|
|
1035
|
+
SidebarGroupActionProps,
|
|
1036
|
+
SidebarGroupContentProps,
|
|
1037
|
+
SidebarGroupLabelProps,
|
|
1038
|
+
SidebarGroupProps,
|
|
1039
|
+
SidebarHeaderProps,
|
|
1040
|
+
SidebarInputProps,
|
|
1041
|
+
SidebarInsetProps,
|
|
1042
|
+
SidebarMenuActionProps,
|
|
1043
|
+
SidebarMenuBadgeProps,
|
|
1044
|
+
SidebarMenuButtonProps,
|
|
1045
|
+
SidebarMenuItemProps,
|
|
1046
|
+
SidebarMenuProps,
|
|
1047
|
+
SidebarMenuSkeletonProps,
|
|
1048
|
+
SidebarMenuSubButtonProps,
|
|
1049
|
+
SidebarMenuSubItemProps,
|
|
1050
|
+
SidebarMenuSubProps,
|
|
1051
|
+
SidebarProps,
|
|
1052
|
+
SidebarProviderProps,
|
|
1053
|
+
SidebarRailProps,
|
|
1054
|
+
SidebarSeparatorProps,
|
|
1055
|
+
SidebarTriggerProps,
|
|
1056
|
+
};
|