@spunto/design-system 0.70.0 → 0.72.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/package.json +1 -1
- package/src/components/sidebar-menus.tsx +211 -0
- package/src/components/sidebar.test.tsx +61 -0
- package/src/components/sidebar.tsx +755 -0
- package/src/components/tasks/index.ts +2 -2
- package/src/components/tasks/machine.tsx +108 -75
- package/src/components/tasks/task-details.tsx +53 -11
- package/src/components/tasks/tasks.test.tsx +39 -1
- package/src/index.ts +43 -0
|
@@ -0,0 +1,755 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { mergeProps } from "@base-ui/react/merge-props"
|
|
5
|
+
import { useRender } from "@base-ui/react/use-render"
|
|
6
|
+
import { cva, type VariantProps } from "class-variance-authority"
|
|
7
|
+
import { PanelLeftIcon } from "lucide-react"
|
|
8
|
+
|
|
9
|
+
import { cn } from "../utils"
|
|
10
|
+
import { Button } from "./button"
|
|
11
|
+
import { Input } from "./input"
|
|
12
|
+
import { Separator } from "./separator"
|
|
13
|
+
import {
|
|
14
|
+
Sheet,
|
|
15
|
+
SheetContent,
|
|
16
|
+
SheetDescription,
|
|
17
|
+
SheetHeader,
|
|
18
|
+
SheetTitle,
|
|
19
|
+
} from "./sheet"
|
|
20
|
+
import { Skeleton } from "./skeleton"
|
|
21
|
+
import { Tooltip } from "./tooltip"
|
|
22
|
+
|
|
23
|
+
const SIDEBAR_COOKIE_NAME = "sidebar_state"
|
|
24
|
+
const MOBILE_BREAKPOINT = 768
|
|
25
|
+
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
|
|
26
|
+
const SIDEBAR_WIDTH = "16rem"
|
|
27
|
+
const SIDEBAR_WIDTH_MOBILE = "18rem"
|
|
28
|
+
const SIDEBAR_WIDTH_ICON = "3rem"
|
|
29
|
+
const SIDEBAR_KEYBOARD_SHORTCUT = "b"
|
|
30
|
+
|
|
31
|
+
type SidebarContextProps = {
|
|
32
|
+
state: "expanded" | "collapsed"
|
|
33
|
+
open: boolean
|
|
34
|
+
setOpen: (open: boolean) => void
|
|
35
|
+
openMobile: boolean
|
|
36
|
+
setOpenMobile: (open: boolean) => void
|
|
37
|
+
isMobile: boolean
|
|
38
|
+
toggleSidebar: () => void
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function useIsMobile() {
|
|
42
|
+
const [isMobile, setIsMobile] = React.useState(false)
|
|
43
|
+
|
|
44
|
+
React.useEffect(() => {
|
|
45
|
+
if (typeof window.matchMedia !== "function") return
|
|
46
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
|
|
47
|
+
const onChange = () => setIsMobile(mql.matches)
|
|
48
|
+
mql.addEventListener("change", onChange)
|
|
49
|
+
onChange()
|
|
50
|
+
return () => mql.removeEventListener("change", onChange)
|
|
51
|
+
}, [])
|
|
52
|
+
|
|
53
|
+
return isMobile
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const SidebarContext = React.createContext<SidebarContextProps | null>(null)
|
|
57
|
+
|
|
58
|
+
function useSidebar() {
|
|
59
|
+
const context = React.useContext(SidebarContext)
|
|
60
|
+
if (!context) {
|
|
61
|
+
throw new Error("useSidebar must be used within a SidebarProvider.")
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return context
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function SidebarProvider({
|
|
68
|
+
defaultOpen = true,
|
|
69
|
+
open: openProp,
|
|
70
|
+
onOpenChange: setOpenProp,
|
|
71
|
+
cookieName = SIDEBAR_COOKIE_NAME,
|
|
72
|
+
mobileCloseKey,
|
|
73
|
+
className,
|
|
74
|
+
style,
|
|
75
|
+
children,
|
|
76
|
+
...props
|
|
77
|
+
}: React.ComponentProps<"div"> & {
|
|
78
|
+
defaultOpen?: boolean
|
|
79
|
+
open?: boolean
|
|
80
|
+
onOpenChange?: (open: boolean) => void
|
|
81
|
+
/** Cookie that remembers the desktop state (read it server-side for `defaultOpen`). `null` = don't persist. */
|
|
82
|
+
cookieName?: string | null
|
|
83
|
+
/**
|
|
84
|
+
* On mobile the sidebar is a sheet over the page: once a navigation lands, keeping it open hides
|
|
85
|
+
* the page that was just asked for. Pass anything that changes with the route (the pathname) and
|
|
86
|
+
* the sheet closes when it does — the provider has no router of its own, so it works in any app.
|
|
87
|
+
* It also closes at once on a click on a link, even one to the current page.
|
|
88
|
+
*/
|
|
89
|
+
mobileCloseKey?: unknown
|
|
90
|
+
}) {
|
|
91
|
+
const isMobile = useIsMobile()
|
|
92
|
+
const [openMobile, setOpenMobile] = React.useState(false)
|
|
93
|
+
|
|
94
|
+
// This is the internal state of the sidebar.
|
|
95
|
+
// We use openProp and setOpenProp for control from outside the component.
|
|
96
|
+
const [_open, _setOpen] = React.useState(defaultOpen)
|
|
97
|
+
const open = openProp ?? _open
|
|
98
|
+
const setOpen = React.useCallback(
|
|
99
|
+
(value: boolean | ((value: boolean) => boolean)) => {
|
|
100
|
+
const openState = typeof value === "function" ? value(open) : value
|
|
101
|
+
if (setOpenProp) {
|
|
102
|
+
setOpenProp(openState)
|
|
103
|
+
} else {
|
|
104
|
+
_setOpen(openState)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// This sets the cookie to keep the sidebar state.
|
|
108
|
+
if (cookieName) {
|
|
109
|
+
document.cookie = `${cookieName}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
[setOpenProp, open, cookieName]
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
// Helper to toggle the sidebar.
|
|
116
|
+
const toggleSidebar = React.useCallback(() => {
|
|
117
|
+
return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open)
|
|
118
|
+
}, [isMobile, setOpen, setOpenMobile])
|
|
119
|
+
|
|
120
|
+
// Covers navigations that don't go through a link too (a `router.push` from an org switcher).
|
|
121
|
+
React.useEffect(() => {
|
|
122
|
+
setOpenMobile(false)
|
|
123
|
+
}, [mobileCloseKey])
|
|
124
|
+
|
|
125
|
+
// Adds a keyboard shortcut to toggle the sidebar.
|
|
126
|
+
React.useEffect(() => {
|
|
127
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
128
|
+
if (
|
|
129
|
+
event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
|
|
130
|
+
(event.metaKey || event.ctrlKey)
|
|
131
|
+
) {
|
|
132
|
+
event.preventDefault()
|
|
133
|
+
toggleSidebar()
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
window.addEventListener("keydown", handleKeyDown)
|
|
138
|
+
return () => window.removeEventListener("keydown", handleKeyDown)
|
|
139
|
+
}, [toggleSidebar])
|
|
140
|
+
|
|
141
|
+
// We add a state so that we can do data-state="expanded" or "collapsed".
|
|
142
|
+
// This makes it easier to style the sidebar with Tailwind classes.
|
|
143
|
+
const state = open ? "expanded" : "collapsed"
|
|
144
|
+
|
|
145
|
+
const contextValue = React.useMemo<SidebarContextProps>(
|
|
146
|
+
() => ({
|
|
147
|
+
state,
|
|
148
|
+
open,
|
|
149
|
+
setOpen,
|
|
150
|
+
isMobile,
|
|
151
|
+
openMobile,
|
|
152
|
+
setOpenMobile,
|
|
153
|
+
toggleSidebar,
|
|
154
|
+
}),
|
|
155
|
+
[state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<SidebarContext.Provider value={contextValue}>
|
|
160
|
+
<div
|
|
161
|
+
data-slot="sidebar-wrapper"
|
|
162
|
+
style={
|
|
163
|
+
{
|
|
164
|
+
"--sidebar-width": SIDEBAR_WIDTH,
|
|
165
|
+
"--sidebar-width-icon": SIDEBAR_WIDTH_ICON,
|
|
166
|
+
...style,
|
|
167
|
+
} as React.CSSProperties
|
|
168
|
+
}
|
|
169
|
+
className={cn(
|
|
170
|
+
"group/sidebar-wrapper flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar",
|
|
171
|
+
className
|
|
172
|
+
)}
|
|
173
|
+
{...props}
|
|
174
|
+
>
|
|
175
|
+
{children}
|
|
176
|
+
</div>
|
|
177
|
+
</SidebarContext.Provider>
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function Sidebar({
|
|
182
|
+
side = "left",
|
|
183
|
+
variant = "sidebar",
|
|
184
|
+
collapsible = "offcanvas",
|
|
185
|
+
className,
|
|
186
|
+
children,
|
|
187
|
+
dir,
|
|
188
|
+
...props
|
|
189
|
+
}: React.ComponentProps<"div"> & {
|
|
190
|
+
side?: "left" | "right"
|
|
191
|
+
variant?: "sidebar" | "floating" | "inset"
|
|
192
|
+
collapsible?: "offcanvas" | "icon" | "none"
|
|
193
|
+
}) {
|
|
194
|
+
const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
|
|
195
|
+
|
|
196
|
+
if (collapsible === "none") {
|
|
197
|
+
return (
|
|
198
|
+
<div
|
|
199
|
+
data-slot="sidebar"
|
|
200
|
+
className={cn(
|
|
201
|
+
"flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground",
|
|
202
|
+
className
|
|
203
|
+
)}
|
|
204
|
+
{...props}
|
|
205
|
+
>
|
|
206
|
+
{children}
|
|
207
|
+
</div>
|
|
208
|
+
)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (isMobile) {
|
|
212
|
+
return (
|
|
213
|
+
<Sheet open={openMobile} onOpenChange={setOpenMobile}>
|
|
214
|
+
<SheetContent
|
|
215
|
+
dir={dir}
|
|
216
|
+
data-sidebar="sidebar"
|
|
217
|
+
data-slot="sidebar"
|
|
218
|
+
data-mobile="true"
|
|
219
|
+
showClose={false}
|
|
220
|
+
className="w-(--sidebar-width) gap-0 border-sidebar-border bg-sidebar p-0 text-sidebar-foreground"
|
|
221
|
+
style={
|
|
222
|
+
{
|
|
223
|
+
"--sidebar-width": SIDEBAR_WIDTH_MOBILE,
|
|
224
|
+
} as React.CSSProperties
|
|
225
|
+
}
|
|
226
|
+
side={side}
|
|
227
|
+
>
|
|
228
|
+
<SheetHeader className="sr-only">
|
|
229
|
+
<SheetTitle>Sidebar</SheetTitle>
|
|
230
|
+
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
|
231
|
+
</SheetHeader>
|
|
232
|
+
{/* Fermeture immédiate au clic sur un lien, sans attendre la fin de la navigation
|
|
233
|
+
(et y compris vers la page courante, où le pathname ne changera pas). */}
|
|
234
|
+
<div
|
|
235
|
+
className="flex h-full w-full flex-col"
|
|
236
|
+
onClick={(event) => {
|
|
237
|
+
const link = (event.target as HTMLElement).closest("a[href]")
|
|
238
|
+
if (link && link.getAttribute("target") !== "_blank") {
|
|
239
|
+
setOpenMobile(false)
|
|
240
|
+
}
|
|
241
|
+
}}
|
|
242
|
+
>
|
|
243
|
+
{children}
|
|
244
|
+
</div>
|
|
245
|
+
</SheetContent>
|
|
246
|
+
</Sheet>
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<div
|
|
252
|
+
className="group peer hidden text-sidebar-foreground md:block"
|
|
253
|
+
data-state={state}
|
|
254
|
+
data-collapsible={state === "collapsed" ? collapsible : ""}
|
|
255
|
+
data-variant={variant}
|
|
256
|
+
data-side={side}
|
|
257
|
+
data-slot="sidebar"
|
|
258
|
+
>
|
|
259
|
+
{/* This is what handles the sidebar gap on desktop */}
|
|
260
|
+
<div
|
|
261
|
+
data-slot="sidebar-gap"
|
|
262
|
+
className={cn(
|
|
263
|
+
"relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear",
|
|
264
|
+
"group-data-[collapsible=offcanvas]:w-0",
|
|
265
|
+
"group-data-[side=right]:rotate-180",
|
|
266
|
+
variant === "floating" || variant === "inset"
|
|
267
|
+
? "group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]"
|
|
268
|
+
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon)"
|
|
269
|
+
)}
|
|
270
|
+
/>
|
|
271
|
+
<div
|
|
272
|
+
data-slot="sidebar-container"
|
|
273
|
+
data-side={side}
|
|
274
|
+
className={cn(
|
|
275
|
+
"fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear data-[side=left]:left-0 data-[side=left]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)] data-[side=right]:right-0 data-[side=right]:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)] md:flex",
|
|
276
|
+
// Adjust the padding for floating and inset variants.
|
|
277
|
+
variant === "floating" || variant === "inset"
|
|
278
|
+
? "p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]"
|
|
279
|
+
: "group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l",
|
|
280
|
+
className
|
|
281
|
+
)}
|
|
282
|
+
{...props}
|
|
283
|
+
>
|
|
284
|
+
<div
|
|
285
|
+
data-sidebar="sidebar"
|
|
286
|
+
data-slot="sidebar-inner"
|
|
287
|
+
className="flex size-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:shadow-sm group-data-[variant=floating]:ring-1 group-data-[variant=floating]:ring-sidebar-border"
|
|
288
|
+
>
|
|
289
|
+
{children}
|
|
290
|
+
</div>
|
|
291
|
+
</div>
|
|
292
|
+
</div>
|
|
293
|
+
)
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function SidebarTrigger({
|
|
297
|
+
className,
|
|
298
|
+
onClick,
|
|
299
|
+
...props
|
|
300
|
+
}: React.ComponentProps<typeof Button>) {
|
|
301
|
+
const { toggleSidebar } = useSidebar()
|
|
302
|
+
|
|
303
|
+
return (
|
|
304
|
+
<Button
|
|
305
|
+
data-sidebar="trigger"
|
|
306
|
+
data-slot="sidebar-trigger"
|
|
307
|
+
variant="ghost"
|
|
308
|
+
size="icon-sm"
|
|
309
|
+
className={cn(className)}
|
|
310
|
+
onClick={(event) => {
|
|
311
|
+
onClick?.(event)
|
|
312
|
+
toggleSidebar()
|
|
313
|
+
}}
|
|
314
|
+
{...props}
|
|
315
|
+
>
|
|
316
|
+
<PanelLeftIcon />
|
|
317
|
+
<span className="sr-only">Toggle Sidebar</span>
|
|
318
|
+
</Button>
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function SidebarRail({ className, ...props }: React.ComponentProps<"button">) {
|
|
323
|
+
const { toggleSidebar } = useSidebar()
|
|
324
|
+
|
|
325
|
+
return (
|
|
326
|
+
<button
|
|
327
|
+
data-sidebar="rail"
|
|
328
|
+
data-slot="sidebar-rail"
|
|
329
|
+
aria-label="Toggle Sidebar"
|
|
330
|
+
tabIndex={-1}
|
|
331
|
+
onClick={toggleSidebar}
|
|
332
|
+
title="Toggle Sidebar"
|
|
333
|
+
className={cn(
|
|
334
|
+
"absolute inset-y-0 z-20 hidden w-4 transition-all ease-linear group-data-[side=left]:-right-4 group-data-[side=right]:left-0 after:absolute after:inset-y-0 after:start-1/2 after:w-[2px] hover:after:bg-sidebar-border sm:flex ltr:-translate-x-1/2 rtl:-translate-x-1/2",
|
|
335
|
+
"in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize",
|
|
336
|
+
"[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize",
|
|
337
|
+
"group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full hover:group-data-[collapsible=offcanvas]:bg-sidebar",
|
|
338
|
+
"[[data-side=left][data-collapsible=offcanvas]_&]:-right-2",
|
|
339
|
+
"[[data-side=right][data-collapsible=offcanvas]_&]:-left-2",
|
|
340
|
+
className
|
|
341
|
+
)}
|
|
342
|
+
{...props}
|
|
343
|
+
/>
|
|
344
|
+
)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
|
|
348
|
+
return (
|
|
349
|
+
<main
|
|
350
|
+
data-slot="sidebar-inset"
|
|
351
|
+
className={cn(
|
|
352
|
+
"relative flex w-full flex-1 flex-col bg-background 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",
|
|
353
|
+
className
|
|
354
|
+
)}
|
|
355
|
+
{...props}
|
|
356
|
+
/>
|
|
357
|
+
)
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function SidebarInput({
|
|
361
|
+
className,
|
|
362
|
+
...props
|
|
363
|
+
}: React.ComponentProps<typeof Input>) {
|
|
364
|
+
return (
|
|
365
|
+
<Input
|
|
366
|
+
data-slot="sidebar-input"
|
|
367
|
+
data-sidebar="input"
|
|
368
|
+
className={cn("h-8 w-full bg-background shadow-none", className)}
|
|
369
|
+
{...props}
|
|
370
|
+
/>
|
|
371
|
+
)
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function SidebarHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
375
|
+
return (
|
|
376
|
+
<div
|
|
377
|
+
data-slot="sidebar-header"
|
|
378
|
+
data-sidebar="header"
|
|
379
|
+
className={cn("flex flex-col gap-2 p-2", className)}
|
|
380
|
+
{...props}
|
|
381
|
+
/>
|
|
382
|
+
)
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function SidebarFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
386
|
+
return (
|
|
387
|
+
<div
|
|
388
|
+
data-slot="sidebar-footer"
|
|
389
|
+
data-sidebar="footer"
|
|
390
|
+
className={cn("flex flex-col gap-2 p-2", className)}
|
|
391
|
+
{...props}
|
|
392
|
+
/>
|
|
393
|
+
)
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function SidebarSeparator({
|
|
397
|
+
className,
|
|
398
|
+
...props
|
|
399
|
+
}: React.ComponentProps<typeof Separator>) {
|
|
400
|
+
return (
|
|
401
|
+
<Separator
|
|
402
|
+
data-slot="sidebar-separator"
|
|
403
|
+
data-sidebar="separator"
|
|
404
|
+
className={cn("mx-2 w-auto bg-sidebar-border", className)}
|
|
405
|
+
{...props}
|
|
406
|
+
/>
|
|
407
|
+
)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function SidebarContent({ className, ...props }: React.ComponentProps<"div">) {
|
|
411
|
+
return (
|
|
412
|
+
<div
|
|
413
|
+
data-slot="sidebar-content"
|
|
414
|
+
data-sidebar="content"
|
|
415
|
+
className={cn(
|
|
416
|
+
"flex min-h-0 flex-1 flex-col gap-0 overflow-auto group-data-[collapsible=icon]:overflow-hidden",
|
|
417
|
+
className
|
|
418
|
+
)}
|
|
419
|
+
{...props}
|
|
420
|
+
/>
|
|
421
|
+
)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function SidebarGroup({ className, ...props }: React.ComponentProps<"div">) {
|
|
425
|
+
return (
|
|
426
|
+
<div
|
|
427
|
+
data-slot="sidebar-group"
|
|
428
|
+
data-sidebar="group"
|
|
429
|
+
className={cn("relative flex w-full min-w-0 flex-col p-2", className)}
|
|
430
|
+
{...props}
|
|
431
|
+
/>
|
|
432
|
+
)
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function SidebarGroupLabel({
|
|
436
|
+
className,
|
|
437
|
+
render,
|
|
438
|
+
...props
|
|
439
|
+
}: useRender.ComponentProps<"div"> & React.ComponentProps<"div">) {
|
|
440
|
+
return useRender({
|
|
441
|
+
defaultTagName: "div",
|
|
442
|
+
props: mergeProps<"div">(
|
|
443
|
+
{
|
|
444
|
+
className: cn(
|
|
445
|
+
"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 group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0 focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
|
446
|
+
className
|
|
447
|
+
),
|
|
448
|
+
},
|
|
449
|
+
props
|
|
450
|
+
),
|
|
451
|
+
render,
|
|
452
|
+
state: {
|
|
453
|
+
slot: "sidebar-group-label",
|
|
454
|
+
sidebar: "group-label",
|
|
455
|
+
},
|
|
456
|
+
})
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
function SidebarGroupAction({
|
|
460
|
+
className,
|
|
461
|
+
render,
|
|
462
|
+
...props
|
|
463
|
+
}: useRender.ComponentProps<"button"> & React.ComponentProps<"button">) {
|
|
464
|
+
return useRender({
|
|
465
|
+
defaultTagName: "button",
|
|
466
|
+
props: mergeProps<"button">(
|
|
467
|
+
{
|
|
468
|
+
className: cn(
|
|
469
|
+
"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 group-data-[collapsible=icon]:hidden after:absolute after:-inset-2 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 md:after:hidden [&>svg]:size-4 [&>svg]:shrink-0",
|
|
470
|
+
className
|
|
471
|
+
),
|
|
472
|
+
},
|
|
473
|
+
props
|
|
474
|
+
),
|
|
475
|
+
render,
|
|
476
|
+
state: {
|
|
477
|
+
slot: "sidebar-group-action",
|
|
478
|
+
sidebar: "group-action",
|
|
479
|
+
},
|
|
480
|
+
})
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function SidebarGroupContent({
|
|
484
|
+
className,
|
|
485
|
+
...props
|
|
486
|
+
}: React.ComponentProps<"div">) {
|
|
487
|
+
return (
|
|
488
|
+
<div
|
|
489
|
+
data-slot="sidebar-group-content"
|
|
490
|
+
data-sidebar="group-content"
|
|
491
|
+
className={cn("w-full text-sm", className)}
|
|
492
|
+
{...props}
|
|
493
|
+
/>
|
|
494
|
+
)
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function SidebarMenu({ className, ...props }: React.ComponentProps<"ul">) {
|
|
498
|
+
return (
|
|
499
|
+
<ul
|
|
500
|
+
data-slot="sidebar-menu"
|
|
501
|
+
data-sidebar="menu"
|
|
502
|
+
className={cn("flex w-full min-w-0 flex-col gap-0", className)}
|
|
503
|
+
{...props}
|
|
504
|
+
/>
|
|
505
|
+
)
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function SidebarMenuItem({ className, ...props }: React.ComponentProps<"li">) {
|
|
509
|
+
return (
|
|
510
|
+
<li
|
|
511
|
+
data-slot="sidebar-menu-item"
|
|
512
|
+
data-sidebar="menu-item"
|
|
513
|
+
className={cn("group/menu-item relative", className)}
|
|
514
|
+
{...props}
|
|
515
|
+
/>
|
|
516
|
+
)
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
const sidebarMenuButtonVariants = cva(
|
|
520
|
+
"peer/menu-button group/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-open:hover:bg-sidebar-accent data-open:hover:text-sidebar-accent-foreground data-active:bg-sidebar-accent data-active:font-medium data-active:text-sidebar-accent-foreground [&_svg]:size-4 [&_svg]:shrink-0 [&>span:last-child]:truncate",
|
|
521
|
+
{
|
|
522
|
+
variants: {
|
|
523
|
+
variant: {
|
|
524
|
+
default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
|
|
525
|
+
outline:
|
|
526
|
+
"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)]",
|
|
527
|
+
},
|
|
528
|
+
size: {
|
|
529
|
+
default: "h-8 text-sm",
|
|
530
|
+
sm: "h-7 text-xs",
|
|
531
|
+
lg: "h-12 text-sm group-data-[collapsible=icon]:p-0!",
|
|
532
|
+
},
|
|
533
|
+
},
|
|
534
|
+
defaultVariants: {
|
|
535
|
+
variant: "default",
|
|
536
|
+
size: "default",
|
|
537
|
+
},
|
|
538
|
+
}
|
|
539
|
+
)
|
|
540
|
+
|
|
541
|
+
function SidebarMenuButton({
|
|
542
|
+
render,
|
|
543
|
+
isActive = false,
|
|
544
|
+
variant = "default",
|
|
545
|
+
size = "default",
|
|
546
|
+
tooltip,
|
|
547
|
+
className,
|
|
548
|
+
...props
|
|
549
|
+
}: useRender.ComponentProps<"button"> &
|
|
550
|
+
React.ComponentProps<"button"> & {
|
|
551
|
+
isActive?: boolean
|
|
552
|
+
/** Label shown beside the button while the sidebar is collapsed to icons. */
|
|
553
|
+
tooltip?: React.ReactNode
|
|
554
|
+
} & VariantProps<typeof sidebarMenuButtonVariants>) {
|
|
555
|
+
const { isMobile, state } = useSidebar()
|
|
556
|
+
const comp = useRender({
|
|
557
|
+
defaultTagName: "button",
|
|
558
|
+
props: mergeProps<"button">(
|
|
559
|
+
{
|
|
560
|
+
className: cn(sidebarMenuButtonVariants({ variant, size }), className),
|
|
561
|
+
},
|
|
562
|
+
props
|
|
563
|
+
),
|
|
564
|
+
render,
|
|
565
|
+
state: {
|
|
566
|
+
slot: "sidebar-menu-button",
|
|
567
|
+
sidebar: "menu-button",
|
|
568
|
+
size,
|
|
569
|
+
active: isActive,
|
|
570
|
+
},
|
|
571
|
+
})
|
|
572
|
+
|
|
573
|
+
if (!tooltip) {
|
|
574
|
+
return comp
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// Only worth a bubble when the label is hidden: collapsed to icons, on desktop.
|
|
578
|
+
return (
|
|
579
|
+
<Tooltip content={state === "collapsed" && !isMobile ? tooltip : undefined} side="right" align="center">
|
|
580
|
+
{comp as React.ReactElement<Record<string, unknown>>}
|
|
581
|
+
</Tooltip>
|
|
582
|
+
)
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function SidebarMenuAction({
|
|
586
|
+
className,
|
|
587
|
+
render,
|
|
588
|
+
showOnHover = false,
|
|
589
|
+
...props
|
|
590
|
+
}: useRender.ComponentProps<"button"> &
|
|
591
|
+
React.ComponentProps<"button"> & {
|
|
592
|
+
showOnHover?: boolean
|
|
593
|
+
}) {
|
|
594
|
+
return useRender({
|
|
595
|
+
defaultTagName: "button",
|
|
596
|
+
props: mergeProps<"button">(
|
|
597
|
+
{
|
|
598
|
+
className: cn(
|
|
599
|
+
"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 group-data-[collapsible=icon]:hidden peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 after:absolute after:-inset-2 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 md:after:hidden [&>svg]:size-4 [&>svg]:shrink-0",
|
|
600
|
+
showOnHover &&
|
|
601
|
+
"group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 peer-data-active/menu-button:text-sidebar-accent-foreground aria-expanded:opacity-100 md:opacity-0",
|
|
602
|
+
className
|
|
603
|
+
),
|
|
604
|
+
},
|
|
605
|
+
props
|
|
606
|
+
),
|
|
607
|
+
render,
|
|
608
|
+
state: {
|
|
609
|
+
slot: "sidebar-menu-action",
|
|
610
|
+
sidebar: "menu-action",
|
|
611
|
+
},
|
|
612
|
+
})
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function SidebarMenuBadge({
|
|
616
|
+
className,
|
|
617
|
+
...props
|
|
618
|
+
}: React.ComponentProps<"div">) {
|
|
619
|
+
return (
|
|
620
|
+
<div
|
|
621
|
+
data-slot="sidebar-menu-badge"
|
|
622
|
+
data-sidebar="menu-badge"
|
|
623
|
+
className={cn(
|
|
624
|
+
"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 group-data-[collapsible=icon]:hidden peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[size=default]/menu-button:top-1.5 peer-data-[size=lg]/menu-button:top-2.5 peer-data-[size=sm]/menu-button:top-1 peer-data-active/menu-button:text-sidebar-accent-foreground",
|
|
625
|
+
className
|
|
626
|
+
)}
|
|
627
|
+
{...props}
|
|
628
|
+
/>
|
|
629
|
+
)
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function SidebarMenuSkeleton({
|
|
633
|
+
className,
|
|
634
|
+
showIcon = false,
|
|
635
|
+
...props
|
|
636
|
+
}: React.ComponentProps<"div"> & {
|
|
637
|
+
showIcon?: boolean
|
|
638
|
+
}) {
|
|
639
|
+
// Random width between 50 to 90%.
|
|
640
|
+
const [width] = React.useState(() => {
|
|
641
|
+
return `${Math.floor(Math.random() * 40) + 50}%`
|
|
642
|
+
})
|
|
643
|
+
|
|
644
|
+
return (
|
|
645
|
+
<div
|
|
646
|
+
data-slot="sidebar-menu-skeleton"
|
|
647
|
+
data-sidebar="menu-skeleton"
|
|
648
|
+
className={cn("flex h-8 items-center gap-2 rounded-md px-2", className)}
|
|
649
|
+
{...props}
|
|
650
|
+
>
|
|
651
|
+
{showIcon && (
|
|
652
|
+
<Skeleton
|
|
653
|
+
className="size-4 rounded-md"
|
|
654
|
+
data-sidebar="menu-skeleton-icon"
|
|
655
|
+
/>
|
|
656
|
+
)}
|
|
657
|
+
<Skeleton
|
|
658
|
+
className="h-4 max-w-(--skeleton-width) flex-1"
|
|
659
|
+
data-sidebar="menu-skeleton-text"
|
|
660
|
+
style={
|
|
661
|
+
{
|
|
662
|
+
"--skeleton-width": width,
|
|
663
|
+
} as React.CSSProperties
|
|
664
|
+
}
|
|
665
|
+
/>
|
|
666
|
+
</div>
|
|
667
|
+
)
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function SidebarMenuSub({ className, ...props }: React.ComponentProps<"ul">) {
|
|
671
|
+
return (
|
|
672
|
+
<ul
|
|
673
|
+
data-slot="sidebar-menu-sub"
|
|
674
|
+
data-sidebar="menu-sub"
|
|
675
|
+
className={cn(
|
|
676
|
+
"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 group-data-[collapsible=icon]:hidden",
|
|
677
|
+
className
|
|
678
|
+
)}
|
|
679
|
+
{...props}
|
|
680
|
+
/>
|
|
681
|
+
)
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
function SidebarMenuSubItem({
|
|
685
|
+
className,
|
|
686
|
+
...props
|
|
687
|
+
}: React.ComponentProps<"li">) {
|
|
688
|
+
return (
|
|
689
|
+
<li
|
|
690
|
+
data-slot="sidebar-menu-sub-item"
|
|
691
|
+
data-sidebar="menu-sub-item"
|
|
692
|
+
className={cn("group/menu-sub-item relative", className)}
|
|
693
|
+
{...props}
|
|
694
|
+
/>
|
|
695
|
+
)
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function SidebarMenuSubButton({
|
|
699
|
+
render,
|
|
700
|
+
size = "md",
|
|
701
|
+
isActive = false,
|
|
702
|
+
className,
|
|
703
|
+
...props
|
|
704
|
+
}: useRender.ComponentProps<"a"> &
|
|
705
|
+
React.ComponentProps<"a"> & {
|
|
706
|
+
size?: "sm" | "md"
|
|
707
|
+
isActive?: boolean
|
|
708
|
+
}) {
|
|
709
|
+
return useRender({
|
|
710
|
+
defaultTagName: "a",
|
|
711
|
+
props: mergeProps<"a">(
|
|
712
|
+
{
|
|
713
|
+
className: cn(
|
|
714
|
+
"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 group-data-[collapsible=icon]: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 data-[size=md]:text-sm data-[size=sm]:text-xs data-active:bg-sidebar-accent data-active:text-sidebar-accent-foreground [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground",
|
|
715
|
+
className
|
|
716
|
+
),
|
|
717
|
+
},
|
|
718
|
+
props
|
|
719
|
+
),
|
|
720
|
+
render,
|
|
721
|
+
state: {
|
|
722
|
+
slot: "sidebar-menu-sub-button",
|
|
723
|
+
sidebar: "menu-sub-button",
|
|
724
|
+
size,
|
|
725
|
+
active: isActive,
|
|
726
|
+
},
|
|
727
|
+
})
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
export {
|
|
731
|
+
Sidebar,
|
|
732
|
+
SidebarContent,
|
|
733
|
+
SidebarFooter,
|
|
734
|
+
SidebarGroup,
|
|
735
|
+
SidebarGroupAction,
|
|
736
|
+
SidebarGroupContent,
|
|
737
|
+
SidebarGroupLabel,
|
|
738
|
+
SidebarHeader,
|
|
739
|
+
SidebarInput,
|
|
740
|
+
SidebarInset,
|
|
741
|
+
SidebarMenu,
|
|
742
|
+
SidebarMenuAction,
|
|
743
|
+
SidebarMenuBadge,
|
|
744
|
+
SidebarMenuButton,
|
|
745
|
+
SidebarMenuItem,
|
|
746
|
+
SidebarMenuSkeleton,
|
|
747
|
+
SidebarMenuSub,
|
|
748
|
+
SidebarMenuSubButton,
|
|
749
|
+
SidebarMenuSubItem,
|
|
750
|
+
SidebarProvider,
|
|
751
|
+
SidebarRail,
|
|
752
|
+
SidebarSeparator,
|
|
753
|
+
SidebarTrigger,
|
|
754
|
+
useSidebar,
|
|
755
|
+
}
|