@shellui/core 0.4.1 → 0.5.0-alpha.2
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/README.md +2 -2
- package/package.json +15 -3
- package/schemas/curated-themes.json +4035 -0
- package/schemas/shellui.config.schema.json +961 -0
- package/schemas/shellui.theme.schema.json +187 -0
- package/src/app.tsx +4 -1
- package/src/components/ContentView.tsx +144 -9
- package/src/components/LoadingOverlay.tsx +1 -1
- package/src/components/ui/alert-dialog.tsx +1 -1
- package/src/components/ui/dialog.tsx +23 -5
- package/src/components/ui/drawer.tsx +282 -42
- package/src/components/ui/dropdown-menu.tsx +7 -2
- package/src/components/ui/input.tsx +21 -0
- package/src/components/ui/separator.tsx +23 -0
- package/src/components/ui/sheet.tsx +220 -0
- package/src/components/ui/sidebar.tsx +785 -221
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/constants/urls.ts +1 -0
- package/src/features/admin/utils.ts +2 -45
- package/src/features/alertDialog/DialogContext.tsx +1 -1
- package/src/features/auth/components/LoginButton.tsx +25 -18
- package/src/features/auth/components/LoginPreferencesControls.tsx +124 -0
- package/src/features/auth/components/LoginView.tsx +131 -49
- package/src/features/config/types.ts +64 -82
- package/src/features/drawer/DrawerContext.tsx +55 -19
- package/src/features/layouts/AppLayout.tsx +3 -3
- package/src/features/layouts/OverlayShell.tsx +376 -77
- package/src/features/layouts/appbar/AppBarLayout.tsx +501 -88
- package/src/features/layouts/branding/AppBrandIcon.tsx +95 -0
- package/src/features/layouts/branding/resolveThemeAsset.spec.ts +33 -0
- package/src/features/layouts/branding/resolveThemeAsset.ts +33 -0
- package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +49 -0
- package/src/features/layouts/chrome/ContentDragOverlay.tsx +19 -0
- package/src/features/layouts/chrome/DesktopBackButton.tsx +71 -0
- package/src/features/layouts/chrome/DesktopChrome.tsx +28 -0
- package/src/features/layouts/chrome/DesktopForwardButton.tsx +59 -0
- package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +16 -0
- package/src/features/layouts/chrome/constants.ts +11 -0
- package/src/features/layouts/chrome/goDesktopBack.spec.ts +218 -0
- package/src/features/layouts/chrome/goDesktopBack.ts +106 -0
- package/src/features/layouts/chrome/index.ts +26 -0
- package/src/features/layouts/chrome/runtime.ts +45 -0
- package/src/features/layouts/findMatchingNavigationItem.spec.ts +55 -0
- package/src/features/layouts/fullscreen/FullscreenLayout.tsx +17 -1
- package/src/features/layouts/isFrameForAppUrl.spec.ts +33 -0
- package/src/features/layouts/sidebar/NavigationContent.tsx +70 -34
- package/src/features/layouts/sidebar/SidebarIcons.tsx +41 -42
- package/src/features/layouts/sidebar/SidebarInner.tsx +142 -24
- package/src/features/layouts/sidebar/SidebarLayout.tsx +100 -37
- package/src/features/layouts/sidebar/sidebarUtils.ts +0 -7
- package/src/features/layouts/sidebar/types.ts +3 -3
- package/src/features/layouts/utils.ts +73 -5
- package/src/features/layouts/windows/WindowsLayout.tsx +173 -61
- package/src/features/modal/ModalContext.tsx +21 -8
- package/src/features/overlays/OverlayDrawerPendingBar.tsx +26 -0
- package/src/features/overlays/OverlayDynamicDemoView.tsx +108 -0
- package/src/features/overlays/OverlayPendingSpinner.tsx +18 -0
- package/src/features/overlays/ResponsiveModal.tsx +483 -0
- package/src/features/overlays/overlaySize.spec.ts +71 -0
- package/src/features/overlays/overlaySize.ts +228 -0
- package/src/features/overlays/useOverlayReportedSize.ts +130 -0
- package/src/features/settings/SettingsProvider.tsx +66 -46
- package/src/features/settings/SettingsView.tsx +42 -47
- package/src/features/settings/components/Appearance.tsx +305 -55
- package/src/features/settings/components/develop/DrawerTestButtons.tsx +18 -0
- package/src/features/settings/components/develop/ModalTestButtons.tsx +23 -0
- package/src/features/settings/utils/getResolvedAppearanceForSettings.ts +11 -5
- package/src/features/theme/applyTheme.ts +143 -0
- package/src/features/theme/color.ts +83 -0
- package/src/features/theme/curated/amber-minimal.json +86 -0
- package/src/features/theme/curated/amethyst-haze.json +86 -0
- package/src/features/theme/curated/astro-vista.json +86 -0
- package/src/features/theme/curated/bold-tech.json +86 -0
- package/src/features/theme/curated/bubblegum.json +86 -0
- package/src/features/theme/curated/caffeine.json +83 -0
- package/src/features/theme/curated/candyland.json +86 -0
- package/src/features/theme/curated/catppuccin.json +86 -0
- package/src/features/theme/curated/claude.json +86 -0
- package/src/features/theme/curated/claymorphism.json +86 -0
- package/src/features/theme/curated/clean-slate.json +86 -0
- package/src/features/theme/curated/cosmic-night.json +86 -0
- package/src/features/theme/curated/cyberpunk.json +86 -0
- package/src/features/theme/curated/darkmatter.json +86 -0
- package/src/features/theme/curated/doom-64.json +86 -0
- package/src/features/theme/curated/elegant-luxury.json +86 -0
- package/src/features/theme/curated/graphite.json +86 -0
- package/src/features/theme/curated/index.ts +260 -0
- package/src/features/theme/curated/kodama-grove.json +86 -0
- package/src/features/theme/curated/light-green.json +87 -0
- package/src/features/theme/curated/midnight-bloom.json +86 -0
- package/src/features/theme/curated/mocha-mousse.json +86 -0
- package/src/features/theme/curated/modern-minimal.json +86 -0
- package/src/features/theme/curated/mono.json +84 -0
- package/src/features/theme/curated/nature.json +86 -0
- package/src/features/theme/curated/neo-brutalism.json +86 -0
- package/src/features/theme/curated/northern-lights.json +86 -0
- package/src/features/theme/curated/notebook.json +87 -0
- package/src/features/theme/curated/ocean-breeze.json +86 -0
- package/src/features/theme/curated/pastel-dreams.json +86 -0
- package/src/features/theme/curated/perpetuity.json +86 -0
- package/src/features/theme/curated/quantum-rose.json +86 -0
- package/src/features/theme/curated/retro-arcade.json +86 -0
- package/src/features/theme/curated/sage-garden.json +86 -0
- package/src/features/theme/curated/shadcn.json +83 -0
- package/src/features/theme/curated/shellui.json +82 -0
- package/src/features/theme/curated/soft-pop.json +86 -0
- package/src/features/theme/curated/solar-dusk.json +86 -0
- package/src/features/theme/curated/starry-night.json +86 -0
- package/src/features/theme/curated/sunset-horizon.json +86 -0
- package/src/features/theme/curated/supabase.json +85 -0
- package/src/features/theme/curated/t3-chat.json +83 -0
- package/src/features/theme/curated/tangerine.json +86 -0
- package/src/features/theme/curated/twitter.json +86 -0
- package/src/features/theme/curated/vercel.json +86 -0
- package/src/features/theme/curated/vintage-paper.json +86 -0
- package/src/features/theme/curated/violet-bloom.json +87 -0
- package/src/features/theme/curated/zen-inspired.json +87 -0
- package/src/features/theme/index.ts +76 -0
- package/src/features/theme/normalize.ts +159 -0
- package/src/features/theme/registry.ts +50 -0
- package/src/features/theme/resolveConfig.ts +182 -0
- package/src/features/theme/safeApplyTheme.ts +147 -0
- package/src/features/theme/themes.spec.ts +276 -0
- package/src/features/theme/themes.ts +82 -558
- package/src/features/theme/tokenKeys.ts +60 -0
- package/src/features/theme/types.ts +170 -0
- package/src/features/theme/useTheme.tsx +48 -50
- package/src/hooks/use-mobile.tsx +19 -0
- package/src/i18n/translations/en/common.json +41 -0
- package/src/i18n/translations/en/settings.json +10 -2
- package/src/i18n/translations/fr/common.json +41 -0
- package/src/i18n/translations/fr/settings.json +10 -2
- package/src/index.css +372 -128
- package/src/index.ts +71 -0
- package/src/lib/z-index.ts +4 -1
- package/src/routes/components/IndexRoute.tsx +12 -2
- package/src/routes/components/NavigationItemRoute.tsx +1 -10
- package/src/routes/hooks/useNavigationItems.ts +29 -44
- package/src/routes/routes.tsx +63 -27
- package/tailwind.config.js +27 -27
- package/src/features/layouts/sidebar/BottomNavItem.tsx +0 -88
- package/src/features/layouts/sidebar/MobileBottomNav.tsx +0 -168
|
@@ -1,146 +1,667 @@
|
|
|
1
|
-
import
|
|
2
|
-
forwardRef,
|
|
3
|
-
type HTMLAttributes,
|
|
4
|
-
type ButtonHTMLAttributes,
|
|
5
|
-
type AnchorHTMLAttributes,
|
|
6
|
-
} from 'react';
|
|
7
|
-
import { Slot } from '@radix-ui/react-slot';
|
|
1
|
+
import * as React from 'react';
|
|
8
2
|
import { cva, type VariantProps } from 'class-variance-authority';
|
|
3
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
4
|
+
|
|
5
|
+
import { useIsMobile } from '../../hooks/use-mobile';
|
|
9
6
|
import { cn } from '../../lib/utils';
|
|
7
|
+
import { Z_INDEX } from '../../lib/z-index';
|
|
8
|
+
import { Button } from './button';
|
|
9
|
+
import { Input } from './input';
|
|
10
|
+
import { Separator } from './separator';
|
|
11
|
+
import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle } from './sheet';
|
|
12
|
+
import { Skeleton } from './skeleton';
|
|
13
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './tooltip';
|
|
14
|
+
|
|
15
|
+
function PanelLeftIcon({ className }: { className?: string }) {
|
|
16
|
+
return (
|
|
17
|
+
<svg
|
|
18
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
19
|
+
width="24"
|
|
20
|
+
height="24"
|
|
21
|
+
viewBox="0 0 24 24"
|
|
22
|
+
fill="none"
|
|
23
|
+
stroke="currentColor"
|
|
24
|
+
strokeWidth="2"
|
|
25
|
+
strokeLinecap="round"
|
|
26
|
+
strokeLinejoin="round"
|
|
27
|
+
className={className}
|
|
28
|
+
aria-hidden
|
|
29
|
+
>
|
|
30
|
+
<rect
|
|
31
|
+
width="18"
|
|
32
|
+
height="18"
|
|
33
|
+
x="3"
|
|
34
|
+
y="3"
|
|
35
|
+
rx="2"
|
|
36
|
+
/>
|
|
37
|
+
<path d="M9 3v18" />
|
|
38
|
+
</svg>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const SIDEBAR_STORAGE_KEY = 'shellui:sidebar:open';
|
|
43
|
+
const SIDEBAR_WIDTH_STORAGE_KEY = 'shellui:sidebar:width';
|
|
44
|
+
/** Default expanded width (matches previous 16rem). */
|
|
45
|
+
const SIDEBAR_WIDTH_DEFAULT_PX = 256;
|
|
46
|
+
const SIDEBAR_WIDTH_MIN_PX = 200;
|
|
47
|
+
const SIDEBAR_WIDTH_MAX_PX = 480;
|
|
48
|
+
/** Cap at the viewport so a phone narrower than 18rem still gets a full-width sheet. */
|
|
49
|
+
const SIDEBAR_WIDTH_MOBILE = 'min(18rem, 100%)';
|
|
50
|
+
const SIDEBAR_WIDTH_ICON = '3rem';
|
|
51
|
+
const SIDEBAR_KEYBOARD_SHORTCUT = 'b';
|
|
52
|
+
/** Ignore tiny pointer moves so a rail click still toggles. */
|
|
53
|
+
const SIDEBAR_RESIZE_DRAG_THRESHOLD_PX = 3;
|
|
54
|
+
|
|
55
|
+
function readSidebarOpen(fallback: boolean): boolean {
|
|
56
|
+
if (typeof window === 'undefined') return fallback;
|
|
57
|
+
try {
|
|
58
|
+
const stored = sessionStorage.getItem(SIDEBAR_STORAGE_KEY);
|
|
59
|
+
if (stored === 'true') return true;
|
|
60
|
+
if (stored === 'false') return false;
|
|
61
|
+
} catch {
|
|
62
|
+
// Ignore quota / privacy mode errors.
|
|
63
|
+
}
|
|
64
|
+
return fallback;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function writeSidebarOpen(open: boolean): void {
|
|
68
|
+
if (typeof window === 'undefined') return;
|
|
69
|
+
try {
|
|
70
|
+
sessionStorage.setItem(SIDEBAR_STORAGE_KEY, String(open));
|
|
71
|
+
} catch {
|
|
72
|
+
// Ignore quota / privacy mode errors.
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function clampSidebarWidth(widthPx: number): number {
|
|
77
|
+
return Math.min(SIDEBAR_WIDTH_MAX_PX, Math.max(SIDEBAR_WIDTH_MIN_PX, Math.round(widthPx)));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function readSidebarWidth(fallbackPx: number): number {
|
|
81
|
+
if (typeof window === 'undefined') return fallbackPx;
|
|
82
|
+
try {
|
|
83
|
+
const stored = sessionStorage.getItem(SIDEBAR_WIDTH_STORAGE_KEY);
|
|
84
|
+
if (stored === null) return fallbackPx;
|
|
85
|
+
const parsed = Number.parseInt(stored, 10);
|
|
86
|
+
if (!Number.isFinite(parsed)) return fallbackPx;
|
|
87
|
+
return clampSidebarWidth(parsed);
|
|
88
|
+
} catch {
|
|
89
|
+
return fallbackPx;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function writeSidebarWidth(widthPx: number): void {
|
|
94
|
+
if (typeof window === 'undefined') return;
|
|
95
|
+
try {
|
|
96
|
+
sessionStorage.setItem(SIDEBAR_WIDTH_STORAGE_KEY, String(clampSidebarWidth(widthPx)));
|
|
97
|
+
} catch {
|
|
98
|
+
// Ignore quota / privacy mode errors.
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
type SidebarContextProps = {
|
|
103
|
+
state: 'expanded' | 'collapsed';
|
|
104
|
+
open: boolean;
|
|
105
|
+
setOpen: (open: boolean) => void;
|
|
106
|
+
openMobile: boolean;
|
|
107
|
+
setOpenMobile: (open: boolean) => void;
|
|
108
|
+
isMobile: boolean;
|
|
109
|
+
toggleSidebar: () => void;
|
|
110
|
+
/** Expanded desktop sidebar width in CSS pixels. */
|
|
111
|
+
width: number;
|
|
112
|
+
setWidth: (width: number, options?: { persist?: boolean }) => void;
|
|
113
|
+
isResizing: boolean;
|
|
114
|
+
setIsResizing: (resizing: boolean) => void;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const SidebarContext = React.createContext<SidebarContextProps | null>(null);
|
|
118
|
+
|
|
119
|
+
function useSidebar() {
|
|
120
|
+
const context = React.useContext(SidebarContext);
|
|
121
|
+
if (!context) {
|
|
122
|
+
throw new Error('useSidebar must be used within a SidebarProvider.');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return context;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function SidebarProvider({
|
|
129
|
+
defaultOpen = true,
|
|
130
|
+
open: openProp,
|
|
131
|
+
onOpenChange: setOpenProp,
|
|
132
|
+
className,
|
|
133
|
+
style,
|
|
134
|
+
children,
|
|
135
|
+
...props
|
|
136
|
+
}: React.ComponentProps<'div'> & {
|
|
137
|
+
defaultOpen?: boolean;
|
|
138
|
+
open?: boolean;
|
|
139
|
+
onOpenChange?: (open: boolean) => void;
|
|
140
|
+
}) {
|
|
141
|
+
const isMobile = useIsMobile();
|
|
142
|
+
const [openMobile, setOpenMobile] = React.useState(false);
|
|
143
|
+
const [width, _setWidth] = React.useState(() => readSidebarWidth(SIDEBAR_WIDTH_DEFAULT_PX));
|
|
144
|
+
const [isResizing, setIsResizing] = React.useState(false);
|
|
145
|
+
|
|
146
|
+
// This is the internal state of the sidebar.
|
|
147
|
+
// We use openProp and setOpenProp for control from outside the component.
|
|
148
|
+
const [_open, _setOpen] = React.useState(() => readSidebarOpen(defaultOpen));
|
|
149
|
+
const open = openProp ?? _open;
|
|
150
|
+
const setOpen = React.useCallback(
|
|
151
|
+
(value: boolean | ((value: boolean) => boolean)) => {
|
|
152
|
+
const openState = typeof value === 'function' ? value(open) : value;
|
|
153
|
+
if (setOpenProp) {
|
|
154
|
+
setOpenProp(openState);
|
|
155
|
+
} else {
|
|
156
|
+
_setOpen(openState);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Persist desktop expanded/collapsed across refresh for this tab session.
|
|
160
|
+
writeSidebarOpen(openState);
|
|
161
|
+
},
|
|
162
|
+
[setOpenProp, open],
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
const setWidth = React.useCallback((next: number, options?: { persist?: boolean }) => {
|
|
166
|
+
const clamped = clampSidebarWidth(next);
|
|
167
|
+
_setWidth(clamped);
|
|
168
|
+
if (options?.persist !== false) {
|
|
169
|
+
writeSidebarWidth(clamped);
|
|
170
|
+
}
|
|
171
|
+
}, []);
|
|
172
|
+
|
|
173
|
+
// Helper to toggle the sidebar.
|
|
174
|
+
const toggleSidebar = React.useCallback(() => {
|
|
175
|
+
return isMobile ? setOpenMobile((value) => !value) : setOpen((value) => !value);
|
|
176
|
+
}, [isMobile, setOpen, setOpenMobile]);
|
|
177
|
+
|
|
178
|
+
// Adds a keyboard shortcut to toggle the sidebar.
|
|
179
|
+
React.useEffect(() => {
|
|
180
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
181
|
+
if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
toggleSidebar();
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
188
|
+
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
189
|
+
}, [toggleSidebar]);
|
|
190
|
+
|
|
191
|
+
// We add a state so that we can do data-state="expanded" or "collapsed".
|
|
192
|
+
// This makes it easier to style the sidebar with Tailwind classes.
|
|
193
|
+
const state = open ? 'expanded' : 'collapsed';
|
|
10
194
|
|
|
11
|
-
const
|
|
12
|
-
|
|
195
|
+
const contextValue = React.useMemo<SidebarContextProps>(
|
|
196
|
+
() => ({
|
|
197
|
+
state,
|
|
198
|
+
open,
|
|
199
|
+
setOpen,
|
|
200
|
+
isMobile,
|
|
201
|
+
openMobile,
|
|
202
|
+
setOpenMobile,
|
|
203
|
+
toggleSidebar,
|
|
204
|
+
width,
|
|
205
|
+
setWidth,
|
|
206
|
+
isResizing,
|
|
207
|
+
setIsResizing,
|
|
208
|
+
}),
|
|
209
|
+
[
|
|
210
|
+
state,
|
|
211
|
+
open,
|
|
212
|
+
setOpen,
|
|
213
|
+
isMobile,
|
|
214
|
+
openMobile,
|
|
215
|
+
setOpenMobile,
|
|
216
|
+
toggleSidebar,
|
|
217
|
+
width,
|
|
218
|
+
setWidth,
|
|
219
|
+
isResizing,
|
|
220
|
+
],
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
return (
|
|
224
|
+
<SidebarContext.Provider value={contextValue}>
|
|
225
|
+
<TooltipProvider delayDuration={0}>
|
|
226
|
+
<div
|
|
227
|
+
data-slot="sidebar-wrapper"
|
|
228
|
+
data-resizing={isResizing ? '' : undefined}
|
|
229
|
+
style={
|
|
230
|
+
{
|
|
231
|
+
'--sidebar-width': `${width}px`,
|
|
232
|
+
'--sidebar-width-icon': SIDEBAR_WIDTH_ICON,
|
|
233
|
+
...style,
|
|
234
|
+
} as React.CSSProperties
|
|
235
|
+
}
|
|
236
|
+
className={cn(
|
|
237
|
+
'group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar',
|
|
238
|
+
className,
|
|
239
|
+
)}
|
|
240
|
+
{...props}
|
|
241
|
+
>
|
|
242
|
+
{children}
|
|
243
|
+
</div>
|
|
244
|
+
</TooltipProvider>
|
|
245
|
+
</SidebarContext.Provider>
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function Sidebar({
|
|
250
|
+
side = 'left',
|
|
251
|
+
variant = 'sidebar',
|
|
252
|
+
collapsible = 'offcanvas',
|
|
253
|
+
className,
|
|
254
|
+
children,
|
|
255
|
+
...props
|
|
256
|
+
}: React.ComponentProps<'div'> & {
|
|
257
|
+
side?: 'left' | 'right';
|
|
258
|
+
variant?: 'sidebar' | 'floating' | 'inset';
|
|
259
|
+
collapsible?: 'offcanvas' | 'icon' | 'none';
|
|
260
|
+
}) {
|
|
261
|
+
const context = React.useContext(SidebarContext);
|
|
262
|
+
|
|
263
|
+
if (collapsible === 'none') {
|
|
13
264
|
return (
|
|
14
265
|
<div
|
|
15
|
-
|
|
16
|
-
data-sidebar="sidebar"
|
|
266
|
+
data-slot="sidebar"
|
|
17
267
|
className={cn(
|
|
18
|
-
'flex h-full
|
|
19
|
-
'w-64',
|
|
268
|
+
'flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground',
|
|
20
269
|
className,
|
|
21
270
|
)}
|
|
22
271
|
{...props}
|
|
23
|
-
|
|
272
|
+
>
|
|
273
|
+
{children}
|
|
274
|
+
</div>
|
|
24
275
|
);
|
|
25
|
-
}
|
|
26
|
-
);
|
|
27
|
-
Sidebar.displayName = 'Sidebar';
|
|
276
|
+
}
|
|
28
277
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<div
|
|
33
|
-
ref={ref}
|
|
34
|
-
className={cn('flex flex-col gap-2 p-2', className)}
|
|
35
|
-
{...props}
|
|
36
|
-
/>
|
|
37
|
-
);
|
|
38
|
-
},
|
|
39
|
-
);
|
|
40
|
-
SidebarHeader.displayName = 'SidebarHeader';
|
|
278
|
+
if (!context) {
|
|
279
|
+
throw new Error('useSidebar must be used within a SidebarProvider.');
|
|
280
|
+
}
|
|
41
281
|
|
|
42
|
-
const
|
|
43
|
-
({ className, ...props }, ref) => {
|
|
44
|
-
return (
|
|
45
|
-
<div
|
|
46
|
-
ref={ref}
|
|
47
|
-
className={cn('flex flex-1 flex-col gap-2 overflow-auto', className)}
|
|
48
|
-
{...props}
|
|
49
|
-
/>
|
|
50
|
-
);
|
|
51
|
-
},
|
|
52
|
-
);
|
|
53
|
-
SidebarContent.displayName = 'SidebarContent';
|
|
282
|
+
const { isMobile, state, openMobile, setOpenMobile } = context;
|
|
54
283
|
|
|
55
|
-
|
|
56
|
-
({ className, ...props }, ref) => {
|
|
284
|
+
if (isMobile) {
|
|
57
285
|
return (
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
286
|
+
<Sheet
|
|
287
|
+
open={openMobile}
|
|
288
|
+
onOpenChange={setOpenMobile}
|
|
61
289
|
{...props}
|
|
62
|
-
|
|
290
|
+
>
|
|
291
|
+
<SheetContent
|
|
292
|
+
data-sidebar="sidebar"
|
|
293
|
+
data-slot="sidebar"
|
|
294
|
+
data-mobile="true"
|
|
295
|
+
className="w-(--sidebar-width) max-w-full overflow-x-hidden bg-sidebar p-0 text-sidebar-foreground sm:max-w-full [&>button]:hidden"
|
|
296
|
+
style={
|
|
297
|
+
{
|
|
298
|
+
'--sidebar-width': SIDEBAR_WIDTH_MOBILE,
|
|
299
|
+
zIndex: Z_INDEX.SIDEBAR_SHEET_CONTENT,
|
|
300
|
+
} as React.CSSProperties
|
|
301
|
+
}
|
|
302
|
+
overlayZIndex={Z_INDEX.SIDEBAR_SHEET_OVERLAY}
|
|
303
|
+
side={side}
|
|
304
|
+
>
|
|
305
|
+
<SheetHeader className="sr-only">
|
|
306
|
+
<SheetTitle>Sidebar</SheetTitle>
|
|
307
|
+
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
|
308
|
+
</SheetHeader>
|
|
309
|
+
<div className="flex h-full w-full flex-col">{children}</div>
|
|
310
|
+
</SheetContent>
|
|
311
|
+
</Sheet>
|
|
63
312
|
);
|
|
64
|
-
}
|
|
65
|
-
);
|
|
66
|
-
SidebarFooter.displayName = 'SidebarFooter';
|
|
313
|
+
}
|
|
67
314
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
315
|
+
return (
|
|
316
|
+
<div
|
|
317
|
+
className="group peer hidden text-sidebar-foreground md:block"
|
|
318
|
+
data-state={state}
|
|
319
|
+
data-collapsible={state === 'collapsed' ? collapsible : ''}
|
|
320
|
+
data-variant={variant}
|
|
321
|
+
data-side={side}
|
|
322
|
+
data-slot="sidebar"
|
|
323
|
+
>
|
|
324
|
+
{/* This is what handles the sidebar gap on desktop */}
|
|
71
325
|
<div
|
|
72
|
-
|
|
73
|
-
className={cn(
|
|
74
|
-
|
|
326
|
+
data-slot="sidebar-gap"
|
|
327
|
+
className={cn(
|
|
328
|
+
'relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear group-data-[resizing]/sidebar-wrapper:transition-none',
|
|
329
|
+
'group-data-[collapsible=offcanvas]:w-0',
|
|
330
|
+
'group-data-[side=right]:rotate-180',
|
|
331
|
+
variant === 'floating' || variant === 'inset'
|
|
332
|
+
? 'group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]'
|
|
333
|
+
: 'group-data-[collapsible=icon]:w-(--sidebar-width-icon)',
|
|
334
|
+
)}
|
|
75
335
|
/>
|
|
76
|
-
);
|
|
77
|
-
},
|
|
78
|
-
);
|
|
79
|
-
SidebarGroup.displayName = 'SidebarGroup';
|
|
80
|
-
|
|
81
|
-
const SidebarGroupLabel = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
|
|
82
|
-
({ className, ...props }, ref) => {
|
|
83
|
-
return (
|
|
84
336
|
<div
|
|
85
|
-
|
|
337
|
+
data-slot="sidebar-container"
|
|
86
338
|
className={cn(
|
|
87
|
-
'
|
|
339
|
+
'fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear group-data-[resizing]/sidebar-wrapper:transition-none md:flex',
|
|
340
|
+
side === 'left'
|
|
341
|
+
? 'left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]'
|
|
342
|
+
: 'right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]',
|
|
343
|
+
// Adjust the padding for floating and inset variants.
|
|
344
|
+
variant === 'floating' || variant === 'inset'
|
|
345
|
+
? 'p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]'
|
|
346
|
+
: 'group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l',
|
|
88
347
|
className,
|
|
89
348
|
)}
|
|
90
|
-
style={{ fontFamily: 'var(--heading-font-family, inherit)' }}
|
|
91
349
|
{...props}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
350
|
+
>
|
|
351
|
+
<div
|
|
352
|
+
data-sidebar="sidebar"
|
|
353
|
+
data-slot="sidebar-inner"
|
|
354
|
+
className="flex h-full w-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:shadow-sm"
|
|
355
|
+
>
|
|
356
|
+
{children}
|
|
357
|
+
</div>
|
|
358
|
+
</div>
|
|
359
|
+
</div>
|
|
360
|
+
);
|
|
361
|
+
}
|
|
97
362
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
363
|
+
function SidebarTrigger({ className, onClick, ...props }: React.ComponentProps<typeof Button>) {
|
|
364
|
+
const { toggleSidebar } = useSidebar();
|
|
365
|
+
|
|
366
|
+
return (
|
|
367
|
+
<Button
|
|
368
|
+
type="button"
|
|
369
|
+
data-sidebar="trigger"
|
|
370
|
+
data-slot="sidebar-trigger"
|
|
371
|
+
variant="ghost"
|
|
372
|
+
size="icon"
|
|
373
|
+
aria-label="Toggle Sidebar"
|
|
374
|
+
className={cn(
|
|
375
|
+
'size-7 touch-manipulation select-none [-webkit-touch-callout:none]',
|
|
376
|
+
className,
|
|
377
|
+
)}
|
|
378
|
+
{...props}
|
|
379
|
+
onClick={(event) => {
|
|
380
|
+
onClick?.(event);
|
|
381
|
+
if (event.defaultPrevented) return;
|
|
382
|
+
toggleSidebar();
|
|
383
|
+
}}
|
|
384
|
+
>
|
|
385
|
+
<PanelLeftIcon />
|
|
386
|
+
</Button>
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function SidebarRail({ className, ...props }: React.ComponentProps<'button'>) {
|
|
391
|
+
const { toggleSidebar, state, width, setWidth, setIsResizing } = useSidebar();
|
|
392
|
+
const dragRef = React.useRef<{
|
|
393
|
+
startX: number;
|
|
394
|
+
startWidth: number;
|
|
395
|
+
side: 'left' | 'right';
|
|
396
|
+
pointerId: number;
|
|
397
|
+
} | null>(null);
|
|
398
|
+
const didDragRef = React.useRef(false);
|
|
399
|
+
const widthRef = React.useRef(width);
|
|
400
|
+
widthRef.current = width;
|
|
401
|
+
|
|
402
|
+
const onPointerDown = (event: React.PointerEvent<HTMLButtonElement>) => {
|
|
403
|
+
if (event.button !== 0) return;
|
|
404
|
+
// Collapsed rail keeps click-to-expand; only resize when expanded.
|
|
405
|
+
if (state !== 'expanded') return;
|
|
406
|
+
|
|
407
|
+
const side =
|
|
408
|
+
(event.currentTarget.closest('[data-side]') as HTMLElement | null)?.dataset.side === 'right'
|
|
409
|
+
? 'right'
|
|
410
|
+
: 'left';
|
|
411
|
+
|
|
412
|
+
didDragRef.current = false;
|
|
413
|
+
dragRef.current = {
|
|
414
|
+
startX: event.clientX,
|
|
415
|
+
startWidth: width,
|
|
416
|
+
side,
|
|
417
|
+
pointerId: event.pointerId,
|
|
418
|
+
};
|
|
419
|
+
setIsResizing(true);
|
|
420
|
+
document.body.style.cursor = 'col-resize';
|
|
421
|
+
document.body.style.userSelect = 'none';
|
|
422
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const onPointerMove = (event: React.PointerEvent<HTMLButtonElement>) => {
|
|
426
|
+
const drag = dragRef.current;
|
|
427
|
+
if (!drag || event.pointerId !== drag.pointerId) return;
|
|
428
|
+
|
|
429
|
+
const delta = event.clientX - drag.startX;
|
|
430
|
+
if (!didDragRef.current && Math.abs(delta) < SIDEBAR_RESIZE_DRAG_THRESHOLD_PX) return;
|
|
431
|
+
didDragRef.current = true;
|
|
432
|
+
|
|
433
|
+
const nextWidth = drag.side === 'left' ? drag.startWidth + delta : drag.startWidth - delta;
|
|
434
|
+
widthRef.current = clampSidebarWidth(nextWidth);
|
|
435
|
+
setWidth(nextWidth, { persist: false });
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
const endDrag = (event: React.PointerEvent<HTMLButtonElement>) => {
|
|
439
|
+
const drag = dragRef.current;
|
|
440
|
+
if (!drag || event.pointerId !== drag.pointerId) return;
|
|
441
|
+
dragRef.current = null;
|
|
442
|
+
setIsResizing(false);
|
|
443
|
+
document.body.style.cursor = '';
|
|
444
|
+
document.body.style.userSelect = '';
|
|
445
|
+
if (didDragRef.current) {
|
|
446
|
+
setWidth(widthRef.current, { persist: true });
|
|
447
|
+
}
|
|
448
|
+
try {
|
|
449
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
450
|
+
} catch {
|
|
451
|
+
// Already released.
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
return (
|
|
456
|
+
<button
|
|
457
|
+
type="button"
|
|
458
|
+
data-sidebar="rail"
|
|
459
|
+
data-slot="sidebar-rail"
|
|
460
|
+
data-shellui-no-drag=""
|
|
461
|
+
aria-label={state === 'expanded' ? 'Resize Sidebar' : 'Toggle Sidebar'}
|
|
462
|
+
tabIndex={-1}
|
|
463
|
+
title={state === 'expanded' ? 'Drag to resize' : 'Toggle Sidebar'}
|
|
464
|
+
onClick={(event) => {
|
|
465
|
+
if (didDragRef.current) {
|
|
466
|
+
didDragRef.current = false;
|
|
467
|
+
event.preventDefault();
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
toggleSidebar();
|
|
471
|
+
}}
|
|
472
|
+
onPointerDown={onPointerDown}
|
|
473
|
+
onPointerMove={onPointerMove}
|
|
474
|
+
onPointerUp={endDrag}
|
|
475
|
+
onPointerCancel={endDrag}
|
|
476
|
+
className={cn(
|
|
477
|
+
'absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex',
|
|
478
|
+
'in-data-[side=left]:cursor-col-resize in-data-[side=right]:cursor-col-resize',
|
|
479
|
+
'[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize',
|
|
480
|
+
'group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar',
|
|
481
|
+
'[[data-side=left][data-collapsible=offcanvas]_&]:-right-2',
|
|
482
|
+
'[[data-side=right][data-collapsible=offcanvas]_&]:-left-2',
|
|
483
|
+
className,
|
|
484
|
+
)}
|
|
485
|
+
{...props}
|
|
486
|
+
/>
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function SidebarInset({ className, ...props }: React.ComponentProps<'main'>) {
|
|
491
|
+
return (
|
|
492
|
+
<main
|
|
493
|
+
data-slot="sidebar-inset"
|
|
494
|
+
className={cn(
|
|
495
|
+
'relative flex w-full flex-1 flex-col bg-background',
|
|
496
|
+
'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 md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2',
|
|
497
|
+
className,
|
|
498
|
+
)}
|
|
499
|
+
{...props}
|
|
500
|
+
/>
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function SidebarInput({ className, ...props }: React.ComponentProps<typeof Input>) {
|
|
505
|
+
return (
|
|
506
|
+
<Input
|
|
507
|
+
data-slot="sidebar-input"
|
|
508
|
+
data-sidebar="input"
|
|
509
|
+
className={cn('h-8 w-full bg-background shadow-none', className)}
|
|
510
|
+
{...props}
|
|
511
|
+
/>
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function SidebarHeader({ className, ...props }: React.ComponentProps<'div'>) {
|
|
516
|
+
return (
|
|
517
|
+
<div
|
|
518
|
+
data-slot="sidebar-header"
|
|
519
|
+
data-sidebar="header"
|
|
520
|
+
className={cn('flex flex-col gap-2 p-2', className)}
|
|
521
|
+
{...props}
|
|
522
|
+
/>
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function SidebarFooter({ className, ...props }: React.ComponentProps<'div'>) {
|
|
527
|
+
return (
|
|
528
|
+
<div
|
|
529
|
+
data-slot="sidebar-footer"
|
|
530
|
+
data-sidebar="footer"
|
|
531
|
+
className={cn('flex flex-col gap-2 p-2', className)}
|
|
532
|
+
{...props}
|
|
533
|
+
/>
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
function SidebarSeparator({ className, ...props }: React.ComponentProps<typeof Separator>) {
|
|
538
|
+
return (
|
|
539
|
+
<Separator
|
|
540
|
+
data-slot="sidebar-separator"
|
|
541
|
+
data-sidebar="separator"
|
|
542
|
+
className={cn('mx-2 w-auto bg-sidebar-border', className)}
|
|
543
|
+
{...props}
|
|
544
|
+
/>
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function SidebarContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
549
|
+
return (
|
|
550
|
+
<div
|
|
551
|
+
data-slot="sidebar-content"
|
|
552
|
+
data-sidebar="content"
|
|
553
|
+
className={cn(
|
|
554
|
+
'flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden',
|
|
555
|
+
className,
|
|
556
|
+
)}
|
|
557
|
+
{...props}
|
|
558
|
+
/>
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function SidebarGroup({ className, ...props }: React.ComponentProps<'div'>) {
|
|
563
|
+
return (
|
|
564
|
+
<div
|
|
565
|
+
data-slot="sidebar-group"
|
|
566
|
+
data-sidebar="group"
|
|
567
|
+
className={cn('relative flex w-full min-w-0 flex-col p-2', className)}
|
|
568
|
+
{...props}
|
|
569
|
+
/>
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function SidebarGroupLabel({
|
|
574
|
+
className,
|
|
575
|
+
asChild = false,
|
|
576
|
+
style,
|
|
577
|
+
...props
|
|
578
|
+
}: React.ComponentProps<'div'> & { asChild?: boolean }) {
|
|
579
|
+
const Comp = asChild ? Slot : 'div';
|
|
580
|
+
|
|
581
|
+
return (
|
|
582
|
+
<Comp
|
|
583
|
+
data-slot="sidebar-group-label"
|
|
584
|
+
data-sidebar="group-label"
|
|
585
|
+
className={cn(
|
|
586
|
+
'flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 ring-sidebar-ring outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
|
587
|
+
'group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0',
|
|
588
|
+
className,
|
|
589
|
+
)}
|
|
590
|
+
style={{ fontFamily: 'var(--heading-font-family, inherit)', ...style }}
|
|
591
|
+
{...props}
|
|
592
|
+
/>
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
function SidebarGroupAction({
|
|
597
|
+
className,
|
|
598
|
+
asChild = false,
|
|
599
|
+
...props
|
|
600
|
+
}: React.ComponentProps<'button'> & { asChild?: boolean }) {
|
|
104
601
|
const Comp = asChild ? Slot : 'button';
|
|
602
|
+
|
|
105
603
|
return (
|
|
106
604
|
<Comp
|
|
107
|
-
|
|
605
|
+
data-slot="sidebar-group-action"
|
|
606
|
+
data-sidebar="group-action"
|
|
108
607
|
className={cn(
|
|
109
|
-
'absolute right-
|
|
608
|
+
'absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground ring-sidebar-ring outline-hidden transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
|
609
|
+
// Increases the hit area of the button on mobile.
|
|
610
|
+
'after:absolute after:-inset-2 md:after:hidden',
|
|
611
|
+
'group-data-[collapsible=icon]:hidden',
|
|
110
612
|
className,
|
|
111
613
|
)}
|
|
112
614
|
{...props}
|
|
113
615
|
/>
|
|
114
616
|
);
|
|
115
|
-
}
|
|
116
|
-
SidebarGroupAction.displayName = 'SidebarGroupAction';
|
|
617
|
+
}
|
|
117
618
|
|
|
118
|
-
|
|
119
|
-
(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
619
|
+
function SidebarGroupContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
620
|
+
return (
|
|
621
|
+
<div
|
|
622
|
+
data-slot="sidebar-group-content"
|
|
623
|
+
data-sidebar="group-content"
|
|
624
|
+
className={cn('w-full text-sm', className)}
|
|
625
|
+
{...props}
|
|
626
|
+
/>
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function SidebarMenu({ className, ...props }: React.ComponentProps<'ul'>) {
|
|
631
|
+
return (
|
|
632
|
+
<ul
|
|
633
|
+
data-slot="sidebar-menu"
|
|
634
|
+
data-sidebar="menu"
|
|
635
|
+
className={cn('flex w-full min-w-0 flex-col gap-1', className)}
|
|
636
|
+
{...props}
|
|
637
|
+
/>
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function SidebarMenuItem({ className, ...props }: React.ComponentProps<'li'>) {
|
|
642
|
+
return (
|
|
643
|
+
<li
|
|
644
|
+
data-slot="sidebar-menu-item"
|
|
645
|
+
data-sidebar="menu-item"
|
|
646
|
+
className={cn('group/menu-item relative', className)}
|
|
647
|
+
{...props}
|
|
648
|
+
/>
|
|
649
|
+
);
|
|
650
|
+
}
|
|
130
651
|
|
|
131
652
|
const sidebarMenuButtonVariants = cva(
|
|
132
|
-
'flex w-full
|
|
653
|
+
'peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm ring-sidebar-ring outline-hidden transition-[width,height,padding] group-has-data-[sidebar=menu-action]/menu-item:pr-8 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0',
|
|
133
654
|
{
|
|
134
655
|
variants: {
|
|
135
656
|
variant: {
|
|
136
657
|
default: 'hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
|
137
658
|
outline:
|
|
138
|
-
'bg-background shadow-[
|
|
659
|
+
'bg-background shadow-[0_0_0_1px_var(--sidebar-border)] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_var(--sidebar-accent)]',
|
|
139
660
|
},
|
|
140
661
|
size: {
|
|
141
662
|
default: 'h-8 text-sm',
|
|
142
663
|
sm: 'h-7 text-xs',
|
|
143
|
-
lg: 'h-12 text-
|
|
664
|
+
lg: 'h-12 text-sm group-data-[collapsible=icon]:p-0!',
|
|
144
665
|
},
|
|
145
666
|
},
|
|
146
667
|
defaultVariants: {
|
|
@@ -150,185 +671,228 @@ const sidebarMenuButtonVariants = cva(
|
|
|
150
671
|
},
|
|
151
672
|
);
|
|
152
673
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
674
|
+
function SidebarMenuButton({
|
|
675
|
+
asChild = false,
|
|
676
|
+
isActive = false,
|
|
677
|
+
variant = 'default',
|
|
678
|
+
size = 'default',
|
|
679
|
+
tooltip,
|
|
680
|
+
className,
|
|
681
|
+
...props
|
|
682
|
+
}: React.ComponentProps<'button'> & {
|
|
683
|
+
asChild?: boolean;
|
|
684
|
+
isActive?: boolean;
|
|
685
|
+
tooltip?: string | React.ComponentProps<typeof TooltipContent>;
|
|
686
|
+
} & VariantProps<typeof sidebarMenuButtonVariants>) {
|
|
161
687
|
const Comp = asChild ? Slot : 'button';
|
|
688
|
+
const context = React.useContext(SidebarContext);
|
|
689
|
+
const isMobile = context?.isMobile ?? false;
|
|
690
|
+
const state = context?.state ?? 'expanded';
|
|
162
691
|
|
|
163
|
-
|
|
692
|
+
const button = (
|
|
164
693
|
<Comp
|
|
165
|
-
|
|
694
|
+
data-slot="sidebar-menu-button"
|
|
695
|
+
data-sidebar="menu-button"
|
|
696
|
+
data-size={size}
|
|
166
697
|
data-active={isActive}
|
|
167
698
|
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
|
|
168
699
|
{...props}
|
|
169
|
-
|
|
170
|
-
{children}
|
|
171
|
-
</Comp>
|
|
700
|
+
/>
|
|
172
701
|
);
|
|
173
|
-
});
|
|
174
|
-
SidebarMenuButton.displayName = 'SidebarMenuButton';
|
|
175
702
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
<ul
|
|
180
|
-
ref={ref}
|
|
181
|
-
className={cn('flex w-full min-w-0 flex-col gap-1', className)}
|
|
182
|
-
{...props}
|
|
183
|
-
/>
|
|
184
|
-
);
|
|
185
|
-
},
|
|
186
|
-
);
|
|
187
|
-
SidebarMenu.displayName = 'SidebarMenu';
|
|
703
|
+
if (!tooltip || !context) {
|
|
704
|
+
return button;
|
|
705
|
+
}
|
|
188
706
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
707
|
+
if (typeof tooltip === 'string') {
|
|
708
|
+
tooltip = {
|
|
709
|
+
children: tooltip,
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
return (
|
|
714
|
+
<Tooltip>
|
|
715
|
+
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
|
716
|
+
<TooltipContent
|
|
717
|
+
side="right"
|
|
718
|
+
align="center"
|
|
719
|
+
hidden={state !== 'collapsed' || isMobile}
|
|
720
|
+
{...tooltip}
|
|
196
721
|
/>
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
SidebarMenuItem.displayName = 'SidebarMenuItem';
|
|
722
|
+
</Tooltip>
|
|
723
|
+
);
|
|
724
|
+
}
|
|
201
725
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
726
|
+
function SidebarMenuAction({
|
|
727
|
+
className,
|
|
728
|
+
asChild = false,
|
|
729
|
+
showOnHover = false,
|
|
730
|
+
...props
|
|
731
|
+
}: React.ComponentProps<'button'> & {
|
|
732
|
+
asChild?: boolean;
|
|
733
|
+
showOnHover?: boolean;
|
|
734
|
+
}) {
|
|
208
735
|
const Comp = asChild ? Slot : 'button';
|
|
736
|
+
|
|
209
737
|
return (
|
|
210
738
|
<Comp
|
|
211
|
-
|
|
739
|
+
data-slot="sidebar-menu-action"
|
|
740
|
+
data-sidebar="menu-action"
|
|
212
741
|
className={cn(
|
|
213
|
-
'absolute
|
|
742
|
+
'absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground ring-sidebar-ring outline-hidden transition-transform peer-hover/menu-button:text-sidebar-accent-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
|
743
|
+
// Increases the hit area of the button on mobile.
|
|
744
|
+
'after:absolute after:-inset-2 md:after:hidden',
|
|
745
|
+
'peer-data-[size=sm]/menu-button:top-1',
|
|
746
|
+
'peer-data-[size=default]/menu-button:top-1.5',
|
|
747
|
+
'peer-data-[size=lg]/menu-button:top-2.5',
|
|
748
|
+
'group-data-[collapsible=icon]:hidden',
|
|
749
|
+
showOnHover &&
|
|
750
|
+
'group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground data-[state=open]:opacity-100 md:opacity-0',
|
|
214
751
|
className,
|
|
215
752
|
)}
|
|
216
753
|
{...props}
|
|
217
754
|
/>
|
|
218
755
|
);
|
|
219
|
-
}
|
|
220
|
-
SidebarMenuAction.displayName = 'SidebarMenuAction';
|
|
756
|
+
}
|
|
221
757
|
|
|
222
|
-
|
|
223
|
-
(
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
)
|
|
236
|
-
|
|
758
|
+
function SidebarMenuBadge({ className, ...props }: React.ComponentProps<'div'>) {
|
|
759
|
+
return (
|
|
760
|
+
<div
|
|
761
|
+
data-slot="sidebar-menu-badge"
|
|
762
|
+
data-sidebar="menu-badge"
|
|
763
|
+
className={cn(
|
|
764
|
+
'pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium text-sidebar-foreground tabular-nums select-none',
|
|
765
|
+
'peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground',
|
|
766
|
+
'peer-data-[size=sm]/menu-button:top-1',
|
|
767
|
+
'peer-data-[size=default]/menu-button:top-1.5',
|
|
768
|
+
'peer-data-[size=lg]/menu-button:top-2.5',
|
|
769
|
+
'group-data-[collapsible=icon]:hidden',
|
|
770
|
+
className,
|
|
771
|
+
)}
|
|
772
|
+
{...props}
|
|
773
|
+
/>
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
function SidebarMenuSkeleton({
|
|
778
|
+
className,
|
|
779
|
+
showIcon = false,
|
|
780
|
+
...props
|
|
781
|
+
}: React.ComponentProps<'div'> & {
|
|
782
|
+
showIcon?: boolean;
|
|
783
|
+
}) {
|
|
784
|
+
// Random width between 50 to 90%.
|
|
785
|
+
const width = React.useMemo(() => {
|
|
786
|
+
return `${Math.floor(Math.random() * 40) + 50}%`;
|
|
787
|
+
}, []);
|
|
237
788
|
|
|
238
|
-
const SidebarMenuSkeleton = forwardRef<
|
|
239
|
-
HTMLDivElement,
|
|
240
|
-
HTMLAttributes<HTMLDivElement> & {
|
|
241
|
-
showIcon?: boolean;
|
|
242
|
-
}
|
|
243
|
-
>(({ className, showIcon = false, ...props }, ref) => {
|
|
244
789
|
return (
|
|
245
790
|
<div
|
|
246
|
-
|
|
247
|
-
|
|
791
|
+
data-slot="sidebar-menu-skeleton"
|
|
792
|
+
data-sidebar="menu-skeleton"
|
|
793
|
+
className={cn('flex h-8 items-center gap-2 rounded-md px-2', className)}
|
|
248
794
|
{...props}
|
|
249
795
|
>
|
|
250
|
-
{showIcon &&
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
796
|
+
{showIcon && (
|
|
797
|
+
<Skeleton
|
|
798
|
+
className="size-4 rounded-md"
|
|
799
|
+
data-sidebar="menu-skeleton-icon"
|
|
800
|
+
/>
|
|
801
|
+
)}
|
|
802
|
+
<Skeleton
|
|
803
|
+
className="h-4 max-w-(--skeleton-width) flex-1"
|
|
804
|
+
data-sidebar="menu-skeleton-text"
|
|
805
|
+
style={
|
|
806
|
+
{
|
|
807
|
+
'--skeleton-width': width,
|
|
808
|
+
} as React.CSSProperties
|
|
809
|
+
}
|
|
810
|
+
/>
|
|
255
811
|
</div>
|
|
256
812
|
);
|
|
257
|
-
}
|
|
258
|
-
SidebarMenuSkeleton.displayName = 'SidebarMenuSkeleton';
|
|
813
|
+
}
|
|
259
814
|
|
|
260
|
-
|
|
261
|
-
(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
815
|
+
function SidebarMenuSub({ className, ...props }: React.ComponentProps<'ul'>) {
|
|
816
|
+
return (
|
|
817
|
+
<ul
|
|
818
|
+
data-slot="sidebar-menu-sub"
|
|
819
|
+
data-sidebar="menu-sub"
|
|
820
|
+
className={cn(
|
|
821
|
+
'mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5',
|
|
822
|
+
'group-data-[collapsible=icon]:hidden',
|
|
823
|
+
className,
|
|
824
|
+
)}
|
|
825
|
+
{...props}
|
|
826
|
+
/>
|
|
827
|
+
);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
function SidebarMenuSubItem({ className, ...props }: React.ComponentProps<'li'>) {
|
|
831
|
+
return (
|
|
832
|
+
<li
|
|
833
|
+
data-slot="sidebar-menu-sub-item"
|
|
834
|
+
data-sidebar="menu-sub-item"
|
|
835
|
+
className={cn('group/menu-sub-item relative', className)}
|
|
836
|
+
{...props}
|
|
837
|
+
/>
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
function SidebarMenuSubButton({
|
|
842
|
+
asChild = false,
|
|
843
|
+
size = 'md',
|
|
844
|
+
isActive = false,
|
|
845
|
+
className,
|
|
846
|
+
...props
|
|
847
|
+
}: React.ComponentProps<'a'> & {
|
|
848
|
+
asChild?: boolean;
|
|
849
|
+
size?: 'sm' | 'md';
|
|
850
|
+
isActive?: boolean;
|
|
851
|
+
}) {
|
|
284
852
|
const Comp = asChild ? Slot : 'a';
|
|
853
|
+
|
|
285
854
|
return (
|
|
286
855
|
<Comp
|
|
287
|
-
|
|
856
|
+
data-slot="sidebar-menu-sub-button"
|
|
857
|
+
data-sidebar="menu-sub-button"
|
|
288
858
|
data-size={size}
|
|
289
859
|
data-active={isActive}
|
|
290
860
|
className={cn(
|
|
291
|
-
'flex min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md
|
|
861
|
+
'flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground ring-sidebar-ring outline-hidden hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground',
|
|
862
|
+
'data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground',
|
|
292
863
|
size === 'sm' && 'text-xs',
|
|
293
864
|
size === 'md' && 'text-sm',
|
|
294
|
-
|
|
865
|
+
'group-data-[collapsible=icon]:hidden',
|
|
295
866
|
className,
|
|
296
867
|
)}
|
|
297
868
|
{...props}
|
|
298
869
|
/>
|
|
299
870
|
);
|
|
300
|
-
}
|
|
301
|
-
SidebarMenuSubButton.displayName = 'SidebarMenuSubButton';
|
|
302
|
-
|
|
303
|
-
const SidebarMenuSubItem = forwardRef<HTMLLIElement, HTMLAttributes<HTMLLIElement>>(
|
|
304
|
-
({ className, ...props }, ref) => {
|
|
305
|
-
return (
|
|
306
|
-
<li
|
|
307
|
-
ref={ref}
|
|
308
|
-
className={cn('group/menu-sub-item relative', className)}
|
|
309
|
-
{...props}
|
|
310
|
-
/>
|
|
311
|
-
);
|
|
312
|
-
},
|
|
313
|
-
);
|
|
314
|
-
SidebarMenuSubItem.displayName = 'SidebarMenuSubItem';
|
|
871
|
+
}
|
|
315
872
|
|
|
316
873
|
export {
|
|
317
874
|
Sidebar,
|
|
318
|
-
SidebarHeader,
|
|
319
875
|
SidebarContent,
|
|
320
876
|
SidebarFooter,
|
|
321
877
|
SidebarGroup,
|
|
322
|
-
SidebarGroupLabel,
|
|
323
878
|
SidebarGroupAction,
|
|
324
879
|
SidebarGroupContent,
|
|
880
|
+
SidebarGroupLabel,
|
|
881
|
+
SidebarHeader,
|
|
882
|
+
SidebarInput,
|
|
883
|
+
SidebarInset,
|
|
325
884
|
SidebarMenu,
|
|
326
|
-
SidebarMenuButton,
|
|
327
|
-
SidebarMenuItem,
|
|
328
885
|
SidebarMenuAction,
|
|
329
886
|
SidebarMenuBadge,
|
|
887
|
+
SidebarMenuButton,
|
|
888
|
+
SidebarMenuItem,
|
|
330
889
|
SidebarMenuSkeleton,
|
|
331
890
|
SidebarMenuSub,
|
|
332
891
|
SidebarMenuSubButton,
|
|
333
892
|
SidebarMenuSubItem,
|
|
893
|
+
SidebarProvider,
|
|
894
|
+
SidebarRail,
|
|
895
|
+
SidebarSeparator,
|
|
896
|
+
SidebarTrigger,
|
|
897
|
+
useSidebar,
|
|
334
898
|
};
|