@pascal-app/editor 0.4.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/package.json +62 -0
- package/src/components/editor/custom-camera-controls.tsx +387 -0
- package/src/components/editor/editor-layout-v2.tsx +220 -0
- package/src/components/editor/export-manager.tsx +78 -0
- package/src/components/editor/first-person-controls.tsx +249 -0
- package/src/components/editor/floating-action-menu.tsx +231 -0
- package/src/components/editor/floorplan-panel.tsx +9609 -0
- package/src/components/editor/grid.tsx +161 -0
- package/src/components/editor/index.tsx +928 -0
- package/src/components/editor/node-action-menu.tsx +66 -0
- package/src/components/editor/preset-thumbnail-generator.tsx +125 -0
- package/src/components/editor/selection-manager.tsx +897 -0
- package/src/components/editor/site-edge-labels.tsx +90 -0
- package/src/components/editor/thumbnail-generator.tsx +166 -0
- package/src/components/editor/wall-measurement-label.tsx +258 -0
- package/src/components/feedback-dialog.tsx +265 -0
- package/src/components/pascal-radio.tsx +280 -0
- package/src/components/preview-button.tsx +16 -0
- package/src/components/systems/ceiling/ceiling-system.tsx +77 -0
- package/src/components/systems/roof/roof-edit-system.tsx +69 -0
- package/src/components/systems/stair/stair-edit-system.tsx +69 -0
- package/src/components/systems/zone/zone-label-editor-system.tsx +320 -0
- package/src/components/systems/zone/zone-system.tsx +87 -0
- package/src/components/tools/ceiling/ceiling-boundary-editor.tsx +42 -0
- package/src/components/tools/ceiling/ceiling-hole-editor.tsx +47 -0
- package/src/components/tools/ceiling/ceiling-tool.tsx +465 -0
- package/src/components/tools/door/door-math.ts +110 -0
- package/src/components/tools/door/door-tool.tsx +293 -0
- package/src/components/tools/door/move-door-tool.tsx +373 -0
- package/src/components/tools/item/item-tool.tsx +26 -0
- package/src/components/tools/item/move-tool.tsx +90 -0
- package/src/components/tools/item/placement-math.ts +85 -0
- package/src/components/tools/item/placement-strategies.ts +556 -0
- package/src/components/tools/item/placement-types.ts +117 -0
- package/src/components/tools/item/use-draft-node.ts +227 -0
- package/src/components/tools/item/use-placement-coordinator.tsx +877 -0
- package/src/components/tools/roof/move-roof-tool.tsx +288 -0
- package/src/components/tools/roof/roof-tool.tsx +318 -0
- package/src/components/tools/select/box-select-tool.tsx +626 -0
- package/src/components/tools/shared/cursor-sphere.tsx +119 -0
- package/src/components/tools/shared/polygon-editor.tsx +361 -0
- package/src/components/tools/site/site-boundary-editor.tsx +42 -0
- package/src/components/tools/slab/slab-boundary-editor.tsx +42 -0
- package/src/components/tools/slab/slab-hole-editor.tsx +47 -0
- package/src/components/tools/slab/slab-tool.tsx +322 -0
- package/src/components/tools/stair/stair-defaults.ts +7 -0
- package/src/components/tools/stair/stair-tool.tsx +194 -0
- package/src/components/tools/tool-manager.tsx +120 -0
- package/src/components/tools/wall/wall-drafting.ts +140 -0
- package/src/components/tools/wall/wall-tool.tsx +210 -0
- package/src/components/tools/window/move-window-tool.tsx +410 -0
- package/src/components/tools/window/window-math.ts +117 -0
- package/src/components/tools/window/window-tool.tsx +303 -0
- package/src/components/tools/zone/zone-boundary-editor.tsx +39 -0
- package/src/components/tools/zone/zone-tool.tsx +364 -0
- package/src/components/ui/action-menu/action-button.tsx +59 -0
- package/src/components/ui/action-menu/camera-actions.tsx +74 -0
- package/src/components/ui/action-menu/control-modes.tsx +240 -0
- package/src/components/ui/action-menu/furnish-tools.tsx +102 -0
- package/src/components/ui/action-menu/index.tsx +152 -0
- package/src/components/ui/action-menu/structure-tools.tsx +100 -0
- package/src/components/ui/action-menu/view-toggles.tsx +397 -0
- package/src/components/ui/command-palette/editor-commands.tsx +396 -0
- package/src/components/ui/command-palette/index.tsx +730 -0
- package/src/components/ui/controls/action-button.tsx +33 -0
- package/src/components/ui/controls/material-picker.tsx +194 -0
- package/src/components/ui/controls/metric-control.tsx +262 -0
- package/src/components/ui/controls/panel-section.tsx +65 -0
- package/src/components/ui/controls/segmented-control.tsx +45 -0
- package/src/components/ui/controls/slider-control.tsx +245 -0
- package/src/components/ui/controls/toggle-control.tsx +38 -0
- package/src/components/ui/floating-level-selector.tsx +355 -0
- package/src/components/ui/helpers/ceiling-helper.tsx +20 -0
- package/src/components/ui/helpers/helper-manager.tsx +33 -0
- package/src/components/ui/helpers/item-helper.tsx +40 -0
- package/src/components/ui/helpers/roof-helper.tsx +16 -0
- package/src/components/ui/helpers/slab-helper.tsx +20 -0
- package/src/components/ui/helpers/wall-helper.tsx +20 -0
- package/src/components/ui/item-catalog/catalog-items.tsx +1580 -0
- package/src/components/ui/item-catalog/item-catalog.tsx +219 -0
- package/src/components/ui/panels/ceiling-panel.tsx +230 -0
- package/src/components/ui/panels/collections/collections-popover.tsx +356 -0
- package/src/components/ui/panels/door-panel.tsx +600 -0
- package/src/components/ui/panels/item-panel.tsx +306 -0
- package/src/components/ui/panels/panel-manager.tsx +59 -0
- package/src/components/ui/panels/panel-wrapper.tsx +80 -0
- package/src/components/ui/panels/presets/presets-popover.tsx +511 -0
- package/src/components/ui/panels/reference-panel.tsx +177 -0
- package/src/components/ui/panels/roof-panel.tsx +262 -0
- package/src/components/ui/panels/roof-segment-panel.tsx +326 -0
- package/src/components/ui/panels/slab-panel.tsx +228 -0
- package/src/components/ui/panels/stair-panel.tsx +304 -0
- package/src/components/ui/panels/stair-segment-panel.tsx +339 -0
- package/src/components/ui/panels/wall-panel.tsx +123 -0
- package/src/components/ui/panels/window-panel.tsx +441 -0
- package/src/components/ui/primitives/button.tsx +69 -0
- package/src/components/ui/primitives/card.tsx +75 -0
- package/src/components/ui/primitives/color-dot.tsx +61 -0
- package/src/components/ui/primitives/context-menu.tsx +227 -0
- package/src/components/ui/primitives/dialog.tsx +129 -0
- package/src/components/ui/primitives/dropdown-menu.tsx +228 -0
- package/src/components/ui/primitives/error-boundary.tsx +52 -0
- package/src/components/ui/primitives/input.tsx +21 -0
- package/src/components/ui/primitives/number-input.tsx +187 -0
- package/src/components/ui/primitives/opacity-control.tsx +79 -0
- package/src/components/ui/primitives/popover.tsx +42 -0
- package/src/components/ui/primitives/separator.tsx +28 -0
- package/src/components/ui/primitives/sheet.tsx +130 -0
- package/src/components/ui/primitives/shortcut-token.tsx +64 -0
- package/src/components/ui/primitives/sidebar.tsx +855 -0
- package/src/components/ui/primitives/skeleton.tsx +13 -0
- package/src/components/ui/primitives/slider.tsx +58 -0
- package/src/components/ui/primitives/switch.tsx +29 -0
- package/src/components/ui/primitives/tooltip.tsx +57 -0
- package/src/components/ui/scene-loader.tsx +40 -0
- package/src/components/ui/sidebar/app-sidebar.tsx +103 -0
- package/src/components/ui/sidebar/icon-rail.tsx +147 -0
- package/src/components/ui/sidebar/panels/settings-panel/audio-settings-dialog.tsx +100 -0
- package/src/components/ui/sidebar/panels/settings-panel/index.tsx +438 -0
- package/src/components/ui/sidebar/panels/settings-panel/keyboard-shortcuts-dialog.tsx +188 -0
- package/src/components/ui/sidebar/panels/site-panel/building-tree-node.tsx +80 -0
- package/src/components/ui/sidebar/panels/site-panel/ceiling-tree-node.tsx +126 -0
- package/src/components/ui/sidebar/panels/site-panel/door-tree-node.tsx +64 -0
- package/src/components/ui/sidebar/panels/site-panel/index.tsx +1543 -0
- package/src/components/ui/sidebar/panels/site-panel/inline-rename-input.tsx +98 -0
- package/src/components/ui/sidebar/panels/site-panel/item-tree-node.tsx +117 -0
- package/src/components/ui/sidebar/panels/site-panel/level-tree-node.tsx +65 -0
- package/src/components/ui/sidebar/panels/site-panel/roof-tree-node.tsx +214 -0
- package/src/components/ui/sidebar/panels/site-panel/slab-tree-node.tsx +96 -0
- package/src/components/ui/sidebar/panels/site-panel/stair-tree-node.tsx +216 -0
- package/src/components/ui/sidebar/panels/site-panel/tree-node-actions.tsx +115 -0
- package/src/components/ui/sidebar/panels/site-panel/tree-node-drag.tsx +342 -0
- package/src/components/ui/sidebar/panels/site-panel/tree-node.tsx +271 -0
- package/src/components/ui/sidebar/panels/site-panel/wall-tree-node.tsx +106 -0
- package/src/components/ui/sidebar/panels/site-panel/window-tree-node.tsx +64 -0
- package/src/components/ui/sidebar/panels/site-panel/zone-tree-node.tsx +87 -0
- package/src/components/ui/sidebar/panels/zone-panel/index.tsx +167 -0
- package/src/components/ui/sidebar/tab-bar.tsx +39 -0
- package/src/components/ui/slider-demo.tsx +36 -0
- package/src/components/ui/slider.tsx +81 -0
- package/src/components/ui/viewer-toolbar.tsx +342 -0
- package/src/components/viewer-overlay.tsx +499 -0
- package/src/components/viewer-zone-system.tsx +48 -0
- package/src/contexts/presets-context.tsx +121 -0
- package/src/hooks/use-auto-save.ts +194 -0
- package/src/hooks/use-contextual-tools.ts +52 -0
- package/src/hooks/use-grid-events.ts +106 -0
- package/src/hooks/use-keyboard.ts +214 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/hooks/use-reduced-motion.ts +20 -0
- package/src/index.tsx +33 -0
- package/src/lib/constants.ts +3 -0
- package/src/lib/level-selection.ts +31 -0
- package/src/lib/scene.ts +394 -0
- package/src/lib/sfx/index.ts +2 -0
- package/src/lib/sfx-bus.ts +49 -0
- package/src/lib/sfx-player.ts +60 -0
- package/src/lib/utils.ts +43 -0
- package/src/store/use-audio.tsx +45 -0
- package/src/store/use-command-registry.ts +36 -0
- package/src/store/use-editor.tsx +522 -0
- package/src/store/use-palette-view-registry.ts +45 -0
- package/src/store/use-upload.ts +90 -0
- package/src/three-types.ts +3 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,855 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { Slot } from '@radix-ui/react-slot'
|
|
4
|
+
import { cva, type VariantProps } from 'class-variance-authority'
|
|
5
|
+
import { PanelLeftIcon } from 'lucide-react'
|
|
6
|
+
import * as React from 'react'
|
|
7
|
+
import { create } from 'zustand'
|
|
8
|
+
import { persist } from 'zustand/middleware'
|
|
9
|
+
import { Button } from './../../../components/ui/primitives/button'
|
|
10
|
+
import { Input } from './../../../components/ui/primitives/input'
|
|
11
|
+
import { Separator } from './../../../components/ui/primitives/separator'
|
|
12
|
+
import {
|
|
13
|
+
Sheet,
|
|
14
|
+
SheetContent,
|
|
15
|
+
SheetDescription,
|
|
16
|
+
SheetHeader,
|
|
17
|
+
SheetTitle,
|
|
18
|
+
} from './../../../components/ui/primitives/sheet'
|
|
19
|
+
import { Skeleton } from './../../../components/ui/primitives/skeleton'
|
|
20
|
+
import {
|
|
21
|
+
Tooltip,
|
|
22
|
+
TooltipContent,
|
|
23
|
+
TooltipProvider,
|
|
24
|
+
TooltipTrigger,
|
|
25
|
+
} from './../../../components/ui/primitives/tooltip'
|
|
26
|
+
import { useIsMobile } from './../../../hooks/use-mobile'
|
|
27
|
+
import { cn } from './../../../lib/utils'
|
|
28
|
+
|
|
29
|
+
const SIDEBAR_COOKIE_NAME = 'sidebar_state'
|
|
30
|
+
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
|
|
31
|
+
const SIDEBAR_WIDTH = '18rem'
|
|
32
|
+
const SIDEBAR_WIDTH_MOBILE = '18rem'
|
|
33
|
+
const SIDEBAR_WIDTH_ICON = '3rem'
|
|
34
|
+
const SIDEBAR_KEYBOARD_SHORTCUT = 'b'
|
|
35
|
+
const SIDEBAR_COLLAPSE_THRESHOLD = 220
|
|
36
|
+
const SIDEBAR_MAX_WIDTH = 800
|
|
37
|
+
|
|
38
|
+
type SidebarStore = {
|
|
39
|
+
width: number
|
|
40
|
+
setWidth: (width: number) => void
|
|
41
|
+
isCollapsed: boolean
|
|
42
|
+
setIsCollapsed: (collapsed: boolean) => void
|
|
43
|
+
isDragging: boolean
|
|
44
|
+
setIsDragging: (isDragging: boolean) => void
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const useSidebarStore = create<SidebarStore>()(
|
|
48
|
+
persist(
|
|
49
|
+
(set) => ({
|
|
50
|
+
width: 288, // 18rem = 288px
|
|
51
|
+
setWidth: (width) => {
|
|
52
|
+
if (width < SIDEBAR_COLLAPSE_THRESHOLD) {
|
|
53
|
+
set({ isCollapsed: true })
|
|
54
|
+
} else {
|
|
55
|
+
set({ width: Math.min(width, SIDEBAR_MAX_WIDTH), isCollapsed: false })
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
isCollapsed: false,
|
|
59
|
+
setIsCollapsed: (collapsed) => set({ isCollapsed: collapsed }),
|
|
60
|
+
isDragging: false,
|
|
61
|
+
setIsDragging: (isDragging) => set({ isDragging }),
|
|
62
|
+
}),
|
|
63
|
+
{
|
|
64
|
+
name: 'sidebar-preferences',
|
|
65
|
+
partialize: (state) => ({ width: state.width, isCollapsed: state.isCollapsed }),
|
|
66
|
+
},
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
type SidebarContextProps = {
|
|
71
|
+
state: 'expanded' | 'collapsed'
|
|
72
|
+
open: boolean
|
|
73
|
+
setOpen: (open: boolean) => void
|
|
74
|
+
openMobile: boolean
|
|
75
|
+
setOpenMobile: (open: boolean) => void
|
|
76
|
+
isMobile: boolean
|
|
77
|
+
toggleSidebar: () => void
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const SidebarContext = React.createContext<SidebarContextProps | null>(null)
|
|
81
|
+
|
|
82
|
+
function useSidebar() {
|
|
83
|
+
const context = React.useContext(SidebarContext)
|
|
84
|
+
if (!context) {
|
|
85
|
+
throw new Error('useSidebar must be used within a SidebarProvider.')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return context
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function SidebarProvider({
|
|
92
|
+
defaultOpen = true,
|
|
93
|
+
open: openProp,
|
|
94
|
+
onOpenChange: setOpenProp,
|
|
95
|
+
className,
|
|
96
|
+
style,
|
|
97
|
+
children,
|
|
98
|
+
...props
|
|
99
|
+
}: React.ComponentProps<'div'> & {
|
|
100
|
+
defaultOpen?: boolean
|
|
101
|
+
open?: boolean
|
|
102
|
+
onOpenChange?: (open: boolean) => void
|
|
103
|
+
}) {
|
|
104
|
+
const isMobile = useIsMobile()
|
|
105
|
+
const [openMobile, setOpenMobile] = React.useState(false)
|
|
106
|
+
const sidebarWidth = useSidebarStore((state) => state.width)
|
|
107
|
+
const isDragging = useSidebarStore((state) => state.isDragging)
|
|
108
|
+
|
|
109
|
+
// This is the internal state of the sidebar.
|
|
110
|
+
// We use openProp and setOpenProp for control from outside the component.
|
|
111
|
+
const [_open, _setOpen] = React.useState(defaultOpen)
|
|
112
|
+
const open = openProp ?? _open
|
|
113
|
+
const setOpen = React.useCallback(
|
|
114
|
+
(value: boolean | ((value: boolean) => boolean)) => {
|
|
115
|
+
const openState = typeof value === 'function' ? value(open) : value
|
|
116
|
+
if (setOpenProp) {
|
|
117
|
+
setOpenProp(openState)
|
|
118
|
+
} else {
|
|
119
|
+
_setOpen(openState)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// This sets the cookie to keep the sidebar state.
|
|
123
|
+
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
|
|
124
|
+
},
|
|
125
|
+
[setOpenProp, open],
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
// Helper to toggle the sidebar.
|
|
129
|
+
const toggleSidebar = React.useCallback(
|
|
130
|
+
() => (isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open)),
|
|
131
|
+
[isMobile, setOpen],
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
// Adds a keyboard shortcut to toggle the sidebar.
|
|
135
|
+
React.useEffect(() => {
|
|
136
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
137
|
+
if (event.key === SIDEBAR_KEYBOARD_SHORTCUT && (event.metaKey || event.ctrlKey)) {
|
|
138
|
+
event.preventDefault()
|
|
139
|
+
toggleSidebar()
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
window.addEventListener('keydown', handleKeyDown)
|
|
144
|
+
return () => window.removeEventListener('keydown', handleKeyDown)
|
|
145
|
+
}, [toggleSidebar])
|
|
146
|
+
|
|
147
|
+
// We add a state so that we can do data-state="expanded" or "collapsed".
|
|
148
|
+
// This makes it easier to style the sidebar with Tailwind classes.
|
|
149
|
+
const state = open ? 'expanded' : 'collapsed'
|
|
150
|
+
|
|
151
|
+
const contextValue = React.useMemo<SidebarContextProps>(
|
|
152
|
+
() => ({
|
|
153
|
+
state,
|
|
154
|
+
open,
|
|
155
|
+
setOpen,
|
|
156
|
+
isMobile,
|
|
157
|
+
openMobile,
|
|
158
|
+
setOpenMobile,
|
|
159
|
+
toggleSidebar,
|
|
160
|
+
}),
|
|
161
|
+
[state, open, setOpen, isMobile, openMobile, toggleSidebar],
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<SidebarContext.Provider value={contextValue}>
|
|
166
|
+
<TooltipProvider delayDuration={0}>
|
|
167
|
+
<div
|
|
168
|
+
className={cn(
|
|
169
|
+
'group/sidebar-wrapper pointer-events-none flex min-h-svh w-full has-data-[variant=inset]:bg-sidebar',
|
|
170
|
+
className,
|
|
171
|
+
)}
|
|
172
|
+
data-dragging={isDragging}
|
|
173
|
+
data-slot="sidebar-wrapper"
|
|
174
|
+
style={
|
|
175
|
+
{
|
|
176
|
+
'--sidebar-width': `${sidebarWidth}px`,
|
|
177
|
+
'--sidebar-width-icon': SIDEBAR_WIDTH_ICON,
|
|
178
|
+
...style,
|
|
179
|
+
} as React.CSSProperties
|
|
180
|
+
}
|
|
181
|
+
{...props}
|
|
182
|
+
>
|
|
183
|
+
{children}
|
|
184
|
+
</div>
|
|
185
|
+
</TooltipProvider>
|
|
186
|
+
</SidebarContext.Provider>
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function SidebarResizer({ side }: { side: 'left' | 'right' }) {
|
|
191
|
+
const setWidth = useSidebarStore((state) => state.setWidth)
|
|
192
|
+
const setIsDragging = useSidebarStore((state) => state.setIsDragging)
|
|
193
|
+
const isResizing = React.useRef(false)
|
|
194
|
+
|
|
195
|
+
const handlePointerDown = (e: React.PointerEvent) => {
|
|
196
|
+
isResizing.current = true
|
|
197
|
+
setIsDragging(true)
|
|
198
|
+
document.body.style.cursor = 'col-resize'
|
|
199
|
+
document.body.style.userSelect = 'none'
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
React.useEffect(() => {
|
|
203
|
+
const handlePointerMove = (e: PointerEvent) => {
|
|
204
|
+
if (!isResizing.current) return
|
|
205
|
+
const newWidth = side === 'left' ? e.clientX : window.innerWidth - e.clientX
|
|
206
|
+
setWidth(Math.max(288, Math.min(newWidth, 800)))
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const handlePointerUp = () => {
|
|
210
|
+
isResizing.current = false
|
|
211
|
+
setIsDragging(false)
|
|
212
|
+
document.body.style.cursor = ''
|
|
213
|
+
document.body.style.userSelect = ''
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
window.addEventListener('pointermove', handlePointerMove)
|
|
217
|
+
window.addEventListener('pointerup', handlePointerUp)
|
|
218
|
+
|
|
219
|
+
return () => {
|
|
220
|
+
window.removeEventListener('pointermove', handlePointerMove)
|
|
221
|
+
window.removeEventListener('pointerup', handlePointerUp)
|
|
222
|
+
}
|
|
223
|
+
}, [setWidth, side, setIsDragging])
|
|
224
|
+
|
|
225
|
+
return (
|
|
226
|
+
<div
|
|
227
|
+
className={cn(
|
|
228
|
+
'absolute top-0 bottom-0 z-50 w-2 cursor-col-resize transition-colors hover:bg-primary/50',
|
|
229
|
+
side === 'left' ? '-right-1' : '-left-1',
|
|
230
|
+
)}
|
|
231
|
+
onPointerDown={handlePointerDown}
|
|
232
|
+
/>
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function Sidebar({
|
|
237
|
+
side = 'left',
|
|
238
|
+
variant = 'sidebar',
|
|
239
|
+
collapsible = 'offcanvas',
|
|
240
|
+
className,
|
|
241
|
+
children,
|
|
242
|
+
...props
|
|
243
|
+
}: React.ComponentProps<'div'> & {
|
|
244
|
+
side?: 'left' | 'right'
|
|
245
|
+
variant?: 'sidebar' | 'floating' | 'inset'
|
|
246
|
+
collapsible?: 'offcanvas' | 'icon' | 'none'
|
|
247
|
+
}) {
|
|
248
|
+
const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
|
|
249
|
+
|
|
250
|
+
if (collapsible === 'none') {
|
|
251
|
+
return (
|
|
252
|
+
<div
|
|
253
|
+
className={cn(
|
|
254
|
+
'flex h-full w-(--sidebar-width) flex-col bg-sidebar text-sidebar-foreground',
|
|
255
|
+
className,
|
|
256
|
+
)}
|
|
257
|
+
data-slot="sidebar"
|
|
258
|
+
{...props}
|
|
259
|
+
>
|
|
260
|
+
{children}
|
|
261
|
+
</div>
|
|
262
|
+
)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (isMobile) {
|
|
266
|
+
return (
|
|
267
|
+
<Sheet onOpenChange={setOpenMobile} open={openMobile} {...props}>
|
|
268
|
+
<SheetContent
|
|
269
|
+
className="w-(--sidebar-width) bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
|
|
270
|
+
data-mobile="true"
|
|
271
|
+
data-sidebar="sidebar"
|
|
272
|
+
data-slot="sidebar"
|
|
273
|
+
side={side}
|
|
274
|
+
style={
|
|
275
|
+
{
|
|
276
|
+
'--sidebar-width': SIDEBAR_WIDTH_MOBILE,
|
|
277
|
+
} as React.CSSProperties
|
|
278
|
+
}
|
|
279
|
+
>
|
|
280
|
+
<SheetHeader className="sr-only">
|
|
281
|
+
<SheetTitle>Sidebar</SheetTitle>
|
|
282
|
+
<SheetDescription>Displays the mobile sidebar.</SheetDescription>
|
|
283
|
+
</SheetHeader>
|
|
284
|
+
<div className="flex h-full w-full flex-col">{children}</div>
|
|
285
|
+
</SheetContent>
|
|
286
|
+
</Sheet>
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return (
|
|
291
|
+
<div
|
|
292
|
+
className="group peer hidden text-sidebar-foreground md:block"
|
|
293
|
+
data-collapsible={state === 'collapsed' ? collapsible : ''}
|
|
294
|
+
data-side={side}
|
|
295
|
+
data-slot="sidebar"
|
|
296
|
+
data-state={state}
|
|
297
|
+
data-variant={variant}
|
|
298
|
+
>
|
|
299
|
+
{/* This is what handles the sidebar gap on desktop */}
|
|
300
|
+
<div
|
|
301
|
+
className={cn(
|
|
302
|
+
'relative w-(--sidebar-width) bg-transparent transition-[width] duration-200 ease-linear',
|
|
303
|
+
'group-data-[dragging=true]/sidebar-wrapper:transition-none',
|
|
304
|
+
'group-data-[collapsible=offcanvas]:w-0',
|
|
305
|
+
'group-data-[side=right]:rotate-180',
|
|
306
|
+
variant === 'floating' || variant === 'inset'
|
|
307
|
+
? 'group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]'
|
|
308
|
+
: 'group-data-[collapsible=icon]:w-(--sidebar-width-icon)',
|
|
309
|
+
)}
|
|
310
|
+
data-slot="sidebar-gap"
|
|
311
|
+
/>
|
|
312
|
+
<div
|
|
313
|
+
className={cn(
|
|
314
|
+
'pointer-events-auto fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-linear md:flex',
|
|
315
|
+
'group-data-[dragging=true]/sidebar-wrapper:transition-none',
|
|
316
|
+
side === 'left'
|
|
317
|
+
? 'left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]'
|
|
318
|
+
: 'right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]',
|
|
319
|
+
// Adjust the padding for floating and inset variants.
|
|
320
|
+
variant === 'floating' || variant === 'inset'
|
|
321
|
+
? 'p-2 group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]'
|
|
322
|
+
: 'group-data-[collapsible=icon]:w-(--sidebar-width-icon) group-data-[side=left]:border-r group-data-[side=right]:border-l',
|
|
323
|
+
className,
|
|
324
|
+
)}
|
|
325
|
+
data-slot="sidebar-container"
|
|
326
|
+
{...props}
|
|
327
|
+
>
|
|
328
|
+
<div
|
|
329
|
+
className="pointer-events-auto relative 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"
|
|
330
|
+
data-sidebar="sidebar"
|
|
331
|
+
data-slot="sidebar-inner"
|
|
332
|
+
>
|
|
333
|
+
{children}
|
|
334
|
+
<SidebarResizer side={side} />
|
|
335
|
+
</div>
|
|
336
|
+
</div>
|
|
337
|
+
</div>
|
|
338
|
+
)
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function SidebarTrigger({ className, onClick, ...props }: React.ComponentProps<typeof Button>) {
|
|
342
|
+
const { toggleSidebar } = useSidebar()
|
|
343
|
+
|
|
344
|
+
return (
|
|
345
|
+
<Button
|
|
346
|
+
className={cn('size-7', className)}
|
|
347
|
+
data-sidebar="trigger"
|
|
348
|
+
data-slot="sidebar-trigger"
|
|
349
|
+
onClick={(event) => {
|
|
350
|
+
onClick?.(event)
|
|
351
|
+
toggleSidebar()
|
|
352
|
+
}}
|
|
353
|
+
size="icon"
|
|
354
|
+
variant="ghost"
|
|
355
|
+
{...props}
|
|
356
|
+
>
|
|
357
|
+
<PanelLeftIcon />
|
|
358
|
+
<span className="sr-only">Toggle Sidebar</span>
|
|
359
|
+
</Button>
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function SidebarRail({ className, ...props }: React.ComponentProps<'button'>) {
|
|
364
|
+
const { toggleSidebar } = useSidebar()
|
|
365
|
+
|
|
366
|
+
return (
|
|
367
|
+
<button
|
|
368
|
+
aria-label="Toggle Sidebar"
|
|
369
|
+
className={cn(
|
|
370
|
+
'absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] hover:after:bg-sidebar-border group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex',
|
|
371
|
+
'in-data-[side=left]:cursor-w-resize in-data-[side=right]:cursor-e-resize',
|
|
372
|
+
'[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize',
|
|
373
|
+
'group-data-[collapsible=offcanvas]:translate-x-0 hover:group-data-[collapsible=offcanvas]:bg-sidebar group-data-[collapsible=offcanvas]:after:left-full',
|
|
374
|
+
'[[data-side=left][data-collapsible=offcanvas]_&]:-right-2',
|
|
375
|
+
'[[data-side=right][data-collapsible=offcanvas]_&]:-left-2',
|
|
376
|
+
className,
|
|
377
|
+
)}
|
|
378
|
+
data-sidebar="rail"
|
|
379
|
+
data-slot="sidebar-rail"
|
|
380
|
+
onClick={toggleSidebar}
|
|
381
|
+
tabIndex={-1}
|
|
382
|
+
title="Toggle Sidebar"
|
|
383
|
+
{...props}
|
|
384
|
+
/>
|
|
385
|
+
)
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function SidebarInset({ className, ...props }: React.ComponentProps<'main'>) {
|
|
389
|
+
return (
|
|
390
|
+
<main
|
|
391
|
+
className={cn(
|
|
392
|
+
'relative flex w-full flex-1 flex-col bg-background',
|
|
393
|
+
'md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2 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',
|
|
394
|
+
className,
|
|
395
|
+
)}
|
|
396
|
+
data-slot="sidebar-inset"
|
|
397
|
+
{...props}
|
|
398
|
+
/>
|
|
399
|
+
)
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function SidebarInput({ className, ...props }: React.ComponentProps<typeof Input>) {
|
|
403
|
+
return (
|
|
404
|
+
<Input
|
|
405
|
+
className={cn('h-8 w-full bg-background shadow-none', className)}
|
|
406
|
+
data-sidebar="input"
|
|
407
|
+
data-slot="sidebar-input"
|
|
408
|
+
{...props}
|
|
409
|
+
/>
|
|
410
|
+
)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function SidebarHeader({ className, ...props }: React.ComponentProps<'div'>) {
|
|
414
|
+
return (
|
|
415
|
+
<div
|
|
416
|
+
className={cn('flex flex-col gap-2 p-2', className)}
|
|
417
|
+
data-sidebar="header"
|
|
418
|
+
data-slot="sidebar-header"
|
|
419
|
+
{...props}
|
|
420
|
+
/>
|
|
421
|
+
)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function SidebarFooter({ className, ...props }: React.ComponentProps<'div'>) {
|
|
425
|
+
return (
|
|
426
|
+
<div
|
|
427
|
+
className={cn('flex flex-col gap-2 p-2', className)}
|
|
428
|
+
data-sidebar="footer"
|
|
429
|
+
data-slot="sidebar-footer"
|
|
430
|
+
{...props}
|
|
431
|
+
/>
|
|
432
|
+
)
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function SidebarSeparator({ className, ...props }: React.ComponentProps<typeof Separator>) {
|
|
436
|
+
return (
|
|
437
|
+
<Separator
|
|
438
|
+
className={cn('mx-2 w-auto bg-sidebar-border', className)}
|
|
439
|
+
data-sidebar="separator"
|
|
440
|
+
data-slot="sidebar-separator"
|
|
441
|
+
{...props}
|
|
442
|
+
/>
|
|
443
|
+
)
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function SidebarContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
447
|
+
return (
|
|
448
|
+
<div
|
|
449
|
+
className={cn(
|
|
450
|
+
'flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden',
|
|
451
|
+
className,
|
|
452
|
+
)}
|
|
453
|
+
data-sidebar="content"
|
|
454
|
+
data-slot="sidebar-content"
|
|
455
|
+
{...props}
|
|
456
|
+
/>
|
|
457
|
+
)
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function SidebarGroup({ className, ...props }: React.ComponentProps<'div'>) {
|
|
461
|
+
return (
|
|
462
|
+
<div
|
|
463
|
+
className={cn('relative flex w-full min-w-0 flex-col p-2', className)}
|
|
464
|
+
data-sidebar="group"
|
|
465
|
+
data-slot="sidebar-group"
|
|
466
|
+
{...props}
|
|
467
|
+
/>
|
|
468
|
+
)
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function SidebarGroupLabel({
|
|
472
|
+
className,
|
|
473
|
+
asChild = false,
|
|
474
|
+
ref,
|
|
475
|
+
...props
|
|
476
|
+
}: React.ComponentProps<'div'> & { asChild?: boolean }) {
|
|
477
|
+
if (asChild) {
|
|
478
|
+
return (
|
|
479
|
+
<Slot
|
|
480
|
+
className={cn(
|
|
481
|
+
'flex h-8 shrink-0 items-center rounded-md px-2 font-barlow font-medium text-sidebar-foreground/70 text-xs outline-hidden ring-sidebar-ring transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
|
482
|
+
'group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0',
|
|
483
|
+
className,
|
|
484
|
+
)}
|
|
485
|
+
data-sidebar="group-label"
|
|
486
|
+
data-slot="sidebar-group-label"
|
|
487
|
+
ref={ref as never}
|
|
488
|
+
{...props}
|
|
489
|
+
/>
|
|
490
|
+
)
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return (
|
|
494
|
+
<div
|
|
495
|
+
className={cn(
|
|
496
|
+
'flex h-8 shrink-0 items-center rounded-md px-2 font-barlow font-medium text-sidebar-foreground/70 text-xs outline-hidden ring-sidebar-ring transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
|
497
|
+
'group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0',
|
|
498
|
+
className,
|
|
499
|
+
)}
|
|
500
|
+
data-sidebar="group-label"
|
|
501
|
+
data-slot="sidebar-group-label"
|
|
502
|
+
ref={ref}
|
|
503
|
+
{...props}
|
|
504
|
+
/>
|
|
505
|
+
)
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function SidebarGroupAction({
|
|
509
|
+
className,
|
|
510
|
+
asChild = false,
|
|
511
|
+
ref,
|
|
512
|
+
...props
|
|
513
|
+
}: React.ComponentProps<'button'> & { asChild?: boolean }) {
|
|
514
|
+
const classes = cn(
|
|
515
|
+
'absolute top-3.5 right-3 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-hidden ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
|
516
|
+
'after:absolute after:-inset-2 md:after:hidden',
|
|
517
|
+
'group-data-[collapsible=icon]:hidden',
|
|
518
|
+
className,
|
|
519
|
+
)
|
|
520
|
+
|
|
521
|
+
if (asChild) {
|
|
522
|
+
return (
|
|
523
|
+
<Slot
|
|
524
|
+
className={classes}
|
|
525
|
+
data-sidebar="group-action"
|
|
526
|
+
data-slot="sidebar-group-action"
|
|
527
|
+
ref={ref as never}
|
|
528
|
+
{...props}
|
|
529
|
+
/>
|
|
530
|
+
)
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
return (
|
|
534
|
+
<button
|
|
535
|
+
className={classes}
|
|
536
|
+
data-sidebar="group-action"
|
|
537
|
+
data-slot="sidebar-group-action"
|
|
538
|
+
ref={ref}
|
|
539
|
+
{...props}
|
|
540
|
+
/>
|
|
541
|
+
)
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
function SidebarGroupContent({ className, ...props }: React.ComponentProps<'div'>) {
|
|
545
|
+
return (
|
|
546
|
+
<div
|
|
547
|
+
className={cn('w-full text-sm', className)}
|
|
548
|
+
data-sidebar="group-content"
|
|
549
|
+
data-slot="sidebar-group-content"
|
|
550
|
+
{...props}
|
|
551
|
+
/>
|
|
552
|
+
)
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
function SidebarMenu({ className, ...props }: React.ComponentProps<'ul'>) {
|
|
556
|
+
return (
|
|
557
|
+
<ul
|
|
558
|
+
className={cn('flex w-full min-w-0 flex-col gap-1', className)}
|
|
559
|
+
data-sidebar="menu"
|
|
560
|
+
data-slot="sidebar-menu"
|
|
561
|
+
{...props}
|
|
562
|
+
/>
|
|
563
|
+
)
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function SidebarMenuItem({ className, ...props }: React.ComponentProps<'li'>) {
|
|
567
|
+
return (
|
|
568
|
+
<li
|
|
569
|
+
className={cn('group/menu-item relative', className)}
|
|
570
|
+
data-sidebar="menu-item"
|
|
571
|
+
data-slot="sidebar-menu-item"
|
|
572
|
+
{...props}
|
|
573
|
+
/>
|
|
574
|
+
)
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
const sidebarMenuButtonVariants = cva(
|
|
578
|
+
'peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left font-barlow text-sm outline-hidden ring-sidebar-ring transition-[width,height,padding] 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 group-has-data-[sidebar=menu-action]/menu-item:pr-8 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 group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0',
|
|
579
|
+
{
|
|
580
|
+
variants: {
|
|
581
|
+
variant: {
|
|
582
|
+
default: 'hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
|
583
|
+
outline:
|
|
584
|
+
'bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]',
|
|
585
|
+
},
|
|
586
|
+
size: {
|
|
587
|
+
default: 'h-8 text-sm',
|
|
588
|
+
sm: 'h-7 text-xs',
|
|
589
|
+
lg: 'h-12 text-sm group-data-[collapsible=icon]:p-0!',
|
|
590
|
+
},
|
|
591
|
+
},
|
|
592
|
+
defaultVariants: {
|
|
593
|
+
variant: 'default',
|
|
594
|
+
size: 'default',
|
|
595
|
+
},
|
|
596
|
+
},
|
|
597
|
+
)
|
|
598
|
+
|
|
599
|
+
function SidebarMenuButton({
|
|
600
|
+
asChild = false,
|
|
601
|
+
isActive = false,
|
|
602
|
+
variant = 'default',
|
|
603
|
+
size = 'default',
|
|
604
|
+
tooltip,
|
|
605
|
+
className,
|
|
606
|
+
ref,
|
|
607
|
+
...props
|
|
608
|
+
}: React.ComponentProps<'button'> & {
|
|
609
|
+
asChild?: boolean
|
|
610
|
+
isActive?: boolean
|
|
611
|
+
tooltip?: string | React.ComponentProps<typeof TooltipContent>
|
|
612
|
+
} & VariantProps<typeof sidebarMenuButtonVariants>) {
|
|
613
|
+
const { isMobile, state } = useSidebar()
|
|
614
|
+
const classes = cn(sidebarMenuButtonVariants({ variant, size }), className)
|
|
615
|
+
|
|
616
|
+
const button = asChild ? (
|
|
617
|
+
<Slot
|
|
618
|
+
className={classes}
|
|
619
|
+
data-active={isActive}
|
|
620
|
+
data-sidebar="menu-button"
|
|
621
|
+
data-size={size}
|
|
622
|
+
data-slot="sidebar-menu-button"
|
|
623
|
+
ref={ref as never}
|
|
624
|
+
{...props}
|
|
625
|
+
/>
|
|
626
|
+
) : (
|
|
627
|
+
<button
|
|
628
|
+
className={classes}
|
|
629
|
+
data-active={isActive}
|
|
630
|
+
data-sidebar="menu-button"
|
|
631
|
+
data-size={size}
|
|
632
|
+
data-slot="sidebar-menu-button"
|
|
633
|
+
ref={ref}
|
|
634
|
+
{...props}
|
|
635
|
+
/>
|
|
636
|
+
)
|
|
637
|
+
|
|
638
|
+
if (!tooltip) {
|
|
639
|
+
return button
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
if (typeof tooltip === 'string') {
|
|
643
|
+
tooltip = {
|
|
644
|
+
children: tooltip,
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
return (
|
|
649
|
+
<Tooltip>
|
|
650
|
+
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
|
651
|
+
<TooltipContent
|
|
652
|
+
align="center"
|
|
653
|
+
hidden={state !== 'collapsed' || isMobile}
|
|
654
|
+
side="right"
|
|
655
|
+
{...tooltip}
|
|
656
|
+
/>
|
|
657
|
+
</Tooltip>
|
|
658
|
+
)
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
function SidebarMenuAction({
|
|
662
|
+
className,
|
|
663
|
+
asChild = false,
|
|
664
|
+
showOnHover = false,
|
|
665
|
+
ref,
|
|
666
|
+
...props
|
|
667
|
+
}: React.ComponentProps<'button'> & {
|
|
668
|
+
asChild?: boolean
|
|
669
|
+
showOnHover?: boolean
|
|
670
|
+
}) {
|
|
671
|
+
const classes = cn(
|
|
672
|
+
'absolute top-1.5 right-1 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-hidden ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 peer-hover/menu-button:text-sidebar-accent-foreground [&>svg]:size-4 [&>svg]:shrink-0',
|
|
673
|
+
'after:absolute after:-inset-2 md:after:hidden',
|
|
674
|
+
'peer-data-[size=sm]/menu-button:top-1',
|
|
675
|
+
'peer-data-[size=default]/menu-button:top-1.5',
|
|
676
|
+
'peer-data-[size=lg]/menu-button:top-2.5',
|
|
677
|
+
'group-data-[collapsible=icon]:hidden',
|
|
678
|
+
showOnHover &&
|
|
679
|
+
'group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0',
|
|
680
|
+
className,
|
|
681
|
+
)
|
|
682
|
+
|
|
683
|
+
if (asChild) {
|
|
684
|
+
return (
|
|
685
|
+
<Slot
|
|
686
|
+
className={classes}
|
|
687
|
+
data-sidebar="menu-action"
|
|
688
|
+
data-slot="sidebar-menu-action"
|
|
689
|
+
ref={ref as never}
|
|
690
|
+
{...props}
|
|
691
|
+
/>
|
|
692
|
+
)
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
return (
|
|
696
|
+
<button
|
|
697
|
+
className={classes}
|
|
698
|
+
data-sidebar="menu-action"
|
|
699
|
+
data-slot="sidebar-menu-action"
|
|
700
|
+
ref={ref}
|
|
701
|
+
{...props}
|
|
702
|
+
/>
|
|
703
|
+
)
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
function SidebarMenuBadge({ className, ...props }: React.ComponentProps<'div'>) {
|
|
707
|
+
return (
|
|
708
|
+
<div
|
|
709
|
+
className={cn(
|
|
710
|
+
'pointer-events-none absolute right-1 flex h-5 min-w-5 select-none items-center justify-center rounded-md px-1 font-medium text-sidebar-foreground text-xs tabular-nums',
|
|
711
|
+
'peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground',
|
|
712
|
+
'peer-data-[size=sm]/menu-button:top-1',
|
|
713
|
+
'peer-data-[size=default]/menu-button:top-1.5',
|
|
714
|
+
'peer-data-[size=lg]/menu-button:top-2.5',
|
|
715
|
+
'group-data-[collapsible=icon]:hidden',
|
|
716
|
+
className,
|
|
717
|
+
)}
|
|
718
|
+
data-sidebar="menu-badge"
|
|
719
|
+
data-slot="sidebar-menu-badge"
|
|
720
|
+
{...props}
|
|
721
|
+
/>
|
|
722
|
+
)
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
function SidebarMenuSkeleton({
|
|
726
|
+
className,
|
|
727
|
+
showIcon = false,
|
|
728
|
+
...props
|
|
729
|
+
}: React.ComponentProps<'div'> & {
|
|
730
|
+
showIcon?: boolean
|
|
731
|
+
}) {
|
|
732
|
+
// Random width between 50 to 90%.
|
|
733
|
+
const width = React.useMemo(() => `${Math.floor(Math.random() * 40) + 50}%`, [])
|
|
734
|
+
|
|
735
|
+
return (
|
|
736
|
+
<div
|
|
737
|
+
className={cn('flex h-8 items-center gap-2 rounded-md px-2', className)}
|
|
738
|
+
data-sidebar="menu-skeleton"
|
|
739
|
+
data-slot="sidebar-menu-skeleton"
|
|
740
|
+
{...props}
|
|
741
|
+
>
|
|
742
|
+
{showIcon && <Skeleton className="size-4 rounded-md" data-sidebar="menu-skeleton-icon" />}
|
|
743
|
+
<Skeleton
|
|
744
|
+
className="h-4 max-w-(--skeleton-width) flex-1"
|
|
745
|
+
data-sidebar="menu-skeleton-text"
|
|
746
|
+
style={
|
|
747
|
+
{
|
|
748
|
+
'--skeleton-width': width,
|
|
749
|
+
} as React.CSSProperties
|
|
750
|
+
}
|
|
751
|
+
/>
|
|
752
|
+
</div>
|
|
753
|
+
)
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
function SidebarMenuSub({ className, ...props }: React.ComponentProps<'ul'>) {
|
|
757
|
+
return (
|
|
758
|
+
<ul
|
|
759
|
+
className={cn(
|
|
760
|
+
'mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-sidebar-border border-l px-2.5 py-0.5',
|
|
761
|
+
'group-data-[collapsible=icon]:hidden',
|
|
762
|
+
className,
|
|
763
|
+
)}
|
|
764
|
+
data-sidebar="menu-sub"
|
|
765
|
+
data-slot="sidebar-menu-sub"
|
|
766
|
+
{...props}
|
|
767
|
+
/>
|
|
768
|
+
)
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
function SidebarMenuSubItem({ className, ...props }: React.ComponentProps<'li'>) {
|
|
772
|
+
return (
|
|
773
|
+
<li
|
|
774
|
+
className={cn('group/menu-sub-item relative', className)}
|
|
775
|
+
data-sidebar="menu-sub-item"
|
|
776
|
+
data-slot="sidebar-menu-sub-item"
|
|
777
|
+
{...props}
|
|
778
|
+
/>
|
|
779
|
+
)
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
function SidebarMenuSubButton({
|
|
783
|
+
asChild = false,
|
|
784
|
+
size = 'md',
|
|
785
|
+
isActive = false,
|
|
786
|
+
className,
|
|
787
|
+
ref,
|
|
788
|
+
...props
|
|
789
|
+
}: React.ComponentProps<'a'> & {
|
|
790
|
+
asChild?: boolean
|
|
791
|
+
size?: 'sm' | 'md'
|
|
792
|
+
isActive?: boolean
|
|
793
|
+
}) {
|
|
794
|
+
const classes = cn(
|
|
795
|
+
'flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 font-barlow text-sidebar-foreground outline-hidden ring-sidebar-ring 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',
|
|
796
|
+
'data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground',
|
|
797
|
+
size === 'sm' && 'text-xs',
|
|
798
|
+
size === 'md' && 'text-sm',
|
|
799
|
+
'group-data-[collapsible=icon]:hidden',
|
|
800
|
+
className,
|
|
801
|
+
)
|
|
802
|
+
|
|
803
|
+
if (asChild) {
|
|
804
|
+
return (
|
|
805
|
+
<Slot
|
|
806
|
+
className={classes}
|
|
807
|
+
data-active={isActive}
|
|
808
|
+
data-sidebar="menu-sub-button"
|
|
809
|
+
data-size={size}
|
|
810
|
+
data-slot="sidebar-menu-sub-button"
|
|
811
|
+
ref={ref as never}
|
|
812
|
+
{...props}
|
|
813
|
+
/>
|
|
814
|
+
)
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
return (
|
|
818
|
+
<a
|
|
819
|
+
className={classes}
|
|
820
|
+
data-active={isActive}
|
|
821
|
+
data-sidebar="menu-sub-button"
|
|
822
|
+
data-size={size}
|
|
823
|
+
data-slot="sidebar-menu-sub-button"
|
|
824
|
+
ref={ref}
|
|
825
|
+
{...props}
|
|
826
|
+
/>
|
|
827
|
+
)
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
export {
|
|
831
|
+
Sidebar,
|
|
832
|
+
SidebarContent,
|
|
833
|
+
SidebarFooter,
|
|
834
|
+
SidebarGroup,
|
|
835
|
+
SidebarGroupAction,
|
|
836
|
+
SidebarGroupContent,
|
|
837
|
+
SidebarGroupLabel,
|
|
838
|
+
SidebarHeader,
|
|
839
|
+
SidebarInput,
|
|
840
|
+
SidebarInset,
|
|
841
|
+
SidebarMenu,
|
|
842
|
+
SidebarMenuAction,
|
|
843
|
+
SidebarMenuBadge,
|
|
844
|
+
SidebarMenuButton,
|
|
845
|
+
SidebarMenuItem,
|
|
846
|
+
SidebarMenuSkeleton,
|
|
847
|
+
SidebarMenuSub,
|
|
848
|
+
SidebarMenuSubButton,
|
|
849
|
+
SidebarMenuSubItem,
|
|
850
|
+
SidebarProvider,
|
|
851
|
+
SidebarRail,
|
|
852
|
+
SidebarSeparator,
|
|
853
|
+
SidebarTrigger,
|
|
854
|
+
useSidebar,
|
|
855
|
+
}
|