@contember/create 2.0.0-beta.2 → 2.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/resources/templates/template-workspace/admin/lib/datagrid/grid.tsx +5 -6
- package/resources/templates/template-workspace/admin/lib/datagrid/pagination.tsx +38 -14
- package/resources/templates/template-workspace/admin/lib/datagrid/table.tsx +13 -10
- package/resources/templates/template-workspace/admin/lib/datagrid/toolbar.tsx +22 -18
- package/resources/templates/template-workspace/admin/lib/datagrid/ui.tsx +29 -26
- package/resources/templates/template-workspace/admin/lib/form/container.tsx +5 -8
- package/resources/templates/template-workspace/admin/lib/form/inputs.tsx +5 -6
- package/resources/templates/template-workspace/admin/lib/form/labels.tsx +8 -0
- package/resources/templates/template-workspace/admin/lib/layout/index.ts +1 -0
- package/resources/templates/template-workspace/admin/lib/layout/layout-boxed.tsx +184 -0
- package/resources/templates/template-workspace/admin/lib/layout/layout.tsx +80 -160
- package/resources/templates/template-workspace/admin/lib/layout/slots.tsx +1 -0
- package/resources/templates/template-workspace/admin/lib/select/ui.tsx +1 -1
- package/resources/templates/template-workspace/admin/lib/ui/alert-dialog.tsx +6 -4
- package/resources/templates/template-workspace/admin/lib/ui/avatar.tsx +42 -0
- package/resources/templates/template-workspace/admin/lib/ui/collapsible.tsx +7 -5
- package/resources/templates/template-workspace/admin/lib/ui/dropdown.tsx +18 -16
- package/resources/templates/template-workspace/admin/lib/ui/menu.tsx +102 -74
- package/resources/templates/template-workspace/admin/lib/ui/popover.tsx +2 -2
- package/resources/templates/template-workspace/admin/lib/ui/progress.tsx +16 -18
- package/resources/templates/template-workspace/admin/lib/ui/separator.tsx +13 -0
- package/resources/templates/template-workspace/admin/lib/ui/sidebar.tsx +560 -0
- package/resources/templates/template-workspace/admin/lib/ui/skeleton.tsx +3 -0
- package/resources/templates/template-workspace/admin/lib/ui/switch.tsx +4 -5
- package/resources/templates/template-workspace/admin/lib/ui/toggle-group.tsx +2 -3
- package/resources/templates/template-workspace/admin/lib/ui/toggle.tsx +1 -2
- package/resources/templates/template-workspace/admin/lib/ui/tooltip.tsx +2 -2
- package/resources/templates/template-workspace/admin/lib/utils/uic.tsx +40 -6
- package/resources/templates/template-workspace/admin/lib/utils/use-mobile.ts +28 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as SeparatorPrimitive from '@radix-ui/react-separator'
|
|
2
|
+
import { uic } from '../utils'
|
|
3
|
+
|
|
4
|
+
export const Separator = uic(SeparatorPrimitive.Root, {
|
|
5
|
+
baseClass: 'shrink-0 bg-border',
|
|
6
|
+
variants: {
|
|
7
|
+
orientation: {
|
|
8
|
+
horizontal: 'h-[1px] w-full',
|
|
9
|
+
vertical: 'h-full w-[1px]',
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
displayName: SeparatorPrimitive.Root.displayName,
|
|
13
|
+
})
|
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import { createRequiredContext } from '@contember/react-utils'
|
|
2
|
+
import { dataAttribute } from '@contember/utilities'
|
|
3
|
+
import { Slot } from '@radix-ui/react-slot'
|
|
4
|
+
import { cva, VariantProps } from 'class-variance-authority'
|
|
5
|
+
import { PanelLeft } from 'lucide-react'
|
|
6
|
+
import {
|
|
7
|
+
ComponentProps,
|
|
8
|
+
CSSProperties,
|
|
9
|
+
ElementRef,
|
|
10
|
+
forwardRef,
|
|
11
|
+
PropsWithChildren,
|
|
12
|
+
ReactNode,
|
|
13
|
+
useCallback,
|
|
14
|
+
useEffect,
|
|
15
|
+
useMemo,
|
|
16
|
+
useState,
|
|
17
|
+
} from 'react'
|
|
18
|
+
import { cn, uic } from '../utils'
|
|
19
|
+
import { useIsMobile } from '../utils/use-mobile'
|
|
20
|
+
import { Button } from './button'
|
|
21
|
+
import { Input } from './input'
|
|
22
|
+
import { Separator } from './separator'
|
|
23
|
+
import { Sheet, SheetContent } from './sheet'
|
|
24
|
+
import { Skeleton } from './skeleton'
|
|
25
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './tooltip'
|
|
26
|
+
|
|
27
|
+
const SIDEBAR_COOKIE_NAME = 'sidebar:state'
|
|
28
|
+
const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7
|
|
29
|
+
const SIDEBAR_WIDTH = '16rem'
|
|
30
|
+
const SIDEBAR_WIDTH_LARGE = '20rem'
|
|
31
|
+
const SIDEBAR_WIDTH_MOBILE = '18rem'
|
|
32
|
+
const SIDEBAR_WIDTH_ICON = '3rem'
|
|
33
|
+
const SIDEBAR_WIDTH_ICON_LARGE = '4rem'
|
|
34
|
+
const SIDEBAR_KEYBOARD_SHORTCUT = 'b'
|
|
35
|
+
|
|
36
|
+
type SidebarContext = {
|
|
37
|
+
state: 'expanded' | 'collapsed'
|
|
38
|
+
open: boolean
|
|
39
|
+
setOpen: (open: boolean) => void
|
|
40
|
+
openMobile: boolean
|
|
41
|
+
setOpenMobile: (open: boolean) => void
|
|
42
|
+
isMobile: boolean
|
|
43
|
+
toggleSidebar: () => void
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface SidebarProviderProps extends PropsWithChildren {
|
|
47
|
+
defaultOpen?: boolean
|
|
48
|
+
open?: boolean
|
|
49
|
+
onOpenChange?: (open: boolean) => void
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const [ctx, useSidebar] = createRequiredContext<SidebarContext>('SidebarContext')
|
|
53
|
+
|
|
54
|
+
export const SidebarProvider = ({
|
|
55
|
+
defaultOpen = true, open: openProp, onOpenChange, children,
|
|
56
|
+
}: SidebarProviderProps) => {
|
|
57
|
+
const isMobile = useIsMobile()
|
|
58
|
+
const [openMobile, setOpenMobile] = useState(false)
|
|
59
|
+
const [_open, _setOpen] = useState(defaultOpen)
|
|
60
|
+
|
|
61
|
+
const open = openProp ?? _open
|
|
62
|
+
|
|
63
|
+
const setOpen = useCallback(
|
|
64
|
+
(value: boolean | ((value: boolean) => boolean)) => {
|
|
65
|
+
const openState = typeof value === 'function' ? value(open) : value
|
|
66
|
+
|
|
67
|
+
if (onOpenChange) {
|
|
68
|
+
onOpenChange(openState)
|
|
69
|
+
} else {
|
|
70
|
+
_setOpen(openState)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
document.cookie = `${SIDEBAR_COOKIE_NAME}=${openState}; path=/; max-age=${SIDEBAR_COOKIE_MAX_AGE}`
|
|
74
|
+
},
|
|
75
|
+
[onOpenChange, open],
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
const toggleSidebar = useCallback(() => isMobile ? setOpenMobile(prev => !prev) : setOpen(prev => !prev), [isMobile, setOpen])
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
82
|
+
if (
|
|
83
|
+
event.key === SIDEBAR_KEYBOARD_SHORTCUT &&
|
|
84
|
+
(event.metaKey || event.ctrlKey)
|
|
85
|
+
) {
|
|
86
|
+
event.preventDefault()
|
|
87
|
+
toggleSidebar()
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
window.addEventListener('keydown', handleKeyDown)
|
|
92
|
+
return () => window.removeEventListener('keydown', handleKeyDown)
|
|
93
|
+
}, [toggleSidebar])
|
|
94
|
+
|
|
95
|
+
const contextValue = useMemo(
|
|
96
|
+
() => ({
|
|
97
|
+
state: open ? 'expanded' : 'collapsed',
|
|
98
|
+
open,
|
|
99
|
+
setOpen,
|
|
100
|
+
isMobile,
|
|
101
|
+
openMobile,
|
|
102
|
+
setOpenMobile,
|
|
103
|
+
toggleSidebar,
|
|
104
|
+
} satisfies SidebarContext),
|
|
105
|
+
[open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar],
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<ctx.Provider value={contextValue}>
|
|
110
|
+
<TooltipProvider delayDuration={0}>
|
|
111
|
+
{children}
|
|
112
|
+
</TooltipProvider>
|
|
113
|
+
</ctx.Provider>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
SidebarProvider.displayName = 'SidebarProvider'
|
|
117
|
+
|
|
118
|
+
export const SidebarLayout = uic('div', {
|
|
119
|
+
baseClass: 'group/sidebar-wrapper grid min-h-svh w-full has-[[data-variant=inset]]:bg-sidebar max-h-screen max-w-[100vw] overflow-y-auto',
|
|
120
|
+
// Add grid template columns
|
|
121
|
+
style: {
|
|
122
|
+
'gridTemplateColumns': 'auto 1fr auto', // This creates two columns: one for sidebar, one for content
|
|
123
|
+
'--sidebar-width': SIDEBAR_WIDTH,
|
|
124
|
+
'--sidebar-width-large': SIDEBAR_WIDTH_LARGE,
|
|
125
|
+
'--sidebar-width-icon': SIDEBAR_WIDTH_ICON,
|
|
126
|
+
'--sidebar-width-icon-large': SIDEBAR_WIDTH_ICON_LARGE,
|
|
127
|
+
} as React.CSSProperties,
|
|
128
|
+
displayName: 'SidebarLayout',
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
export const SidebarInset = uic('main', {
|
|
132
|
+
baseClass: [
|
|
133
|
+
'relative min-h-svh grid',
|
|
134
|
+
'grid-cols-1 grid-rows-[auto_1fr]', // Single column layout
|
|
135
|
+
'bg-background',
|
|
136
|
+
'peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow',
|
|
137
|
+
],
|
|
138
|
+
displayName: 'SidebarInset',
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
export const SidebarInsetHeader = uic('header', {
|
|
142
|
+
baseClass: [
|
|
143
|
+
'bg-background z-50 flex justify-between h-16 shrink-0 items-center gap-2 border-b mb-4',
|
|
144
|
+
'transition-[width,height] ease-linear',
|
|
145
|
+
'group-has-[[data-collapsible=icon]]/sidebar-wrapper:h-12',
|
|
146
|
+
],
|
|
147
|
+
displayName: 'SidebarInsetHeader',
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
export const SidebarInsetContent = uic('div', {
|
|
151
|
+
baseClass: 'overflow-y-auto px-4',
|
|
152
|
+
displayName: 'SidebarInsetContent',
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
export const SidebarInsetHeaderActions = uic('div', {
|
|
156
|
+
baseClass: 'flex justify-end items-center gap-2 px-4',
|
|
157
|
+
displayName: 'SidebarInsetHeaderAction',
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
const SidebarNone = uic('div', {
|
|
161
|
+
baseClass: 'flex h-full w-[--sidebar-width] 2xl:w-[--sidebar-width-large] flex-col bg-sidebar text-sidebar-foreground',
|
|
162
|
+
displayName: 'SidebarNone',
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
const SidebarDesktopGap = uic('div', {
|
|
166
|
+
baseClass: [
|
|
167
|
+
'duration-200 relative w-[--sidebar-width] 2xl:w-[--sidebar-width-large] bg-transparent transition-[width] ease-linear',
|
|
168
|
+
'group-data-[collapsible=offcanvas]:w-0',
|
|
169
|
+
'group-data-[side=right]:rotate-180',
|
|
170
|
+
],
|
|
171
|
+
variants: {
|
|
172
|
+
variant: {
|
|
173
|
+
floating: 'group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4))] 2xl:group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon-large)_+_theme(spacing.4))]',
|
|
174
|
+
inset: 'group-data-[collapsible=icon]:w-5',
|
|
175
|
+
sidebar: 'group-data-[collapsible=icon]:w-[--sidebar-width-icon] 2xl:group-data-[collapsible=icon]:w-[--sidebar-width-icon-large]',
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
displayName: 'SidebarDesktopGap',
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
const SidebarInner = uic('div', {
|
|
182
|
+
baseClass: 'duration-200 fixed inset-y-0 z-10 hidden h-svh transition-[left,right,width] ease-linear md:block',
|
|
183
|
+
variants: {
|
|
184
|
+
side: {
|
|
185
|
+
left: 'left-0 group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)] 2xl:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width-large)*-1)]',
|
|
186
|
+
right: 'right-0 group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)] 2xl:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width-large)*-1)]',
|
|
187
|
+
},
|
|
188
|
+
variant: {
|
|
189
|
+
floating: 'p-2 w-[--sidebar-width] 2xl:w-[--sidebar-width-large] group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)_+_theme(spacing.4)_+2px)] 2xl:group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon-large)_+_theme(spacing.4)_+2px)]',
|
|
190
|
+
inset: 'p-2 w-[--sidebar-width] 2xl:w-[--sidebar-width-large] group-data-[collapsible=icon]:w-5',
|
|
191
|
+
sidebar: 'w-[--sidebar-width] 2xl:w-[--sidebar-width-large] group-data-[collapsible=icon]:w-[--sidebar-width-icon] group-data-[side=left]:border-r group-data-[side=right]:border-l 2xl:group-data-[collapsible=icon]:w-[--sidebar-width-icon-large]',
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
variantsAsDataAttrs: ['variant', 'side'],
|
|
195
|
+
wrapInner: ({ children }) =>
|
|
196
|
+
<div data-sidebar="sidebar" className="grid h-full w-full grid-rows-[auto_1fr_auto]">
|
|
197
|
+
{children}
|
|
198
|
+
</div>,
|
|
199
|
+
displayName: 'SidebarInner',
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
interface SidebarProps extends ComponentProps<'div'> {
|
|
203
|
+
side?: 'left' | 'right'
|
|
204
|
+
variant?: 'sidebar' | 'floating' | 'inset'
|
|
205
|
+
collapsible?: 'offcanvas' | 'icon' | 'none'
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export const Sidebar = forwardRef<HTMLDivElement, SidebarProps>(
|
|
209
|
+
({ side = 'left', variant = 'sidebar', collapsible = 'offcanvas', className, children, ...props }, ref) => {
|
|
210
|
+
const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
|
|
211
|
+
|
|
212
|
+
if (collapsible === 'none') {
|
|
213
|
+
return (
|
|
214
|
+
<SidebarNone ref={ref} className={className} {...props}>
|
|
215
|
+
{children}
|
|
216
|
+
</SidebarNone>
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (isMobile) {
|
|
221
|
+
return (
|
|
222
|
+
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
|
|
223
|
+
<SheetContent
|
|
224
|
+
data-sidebar="sidebar"
|
|
225
|
+
data-mobile={dataAttribute(true)}
|
|
226
|
+
className="w-[--sidebar-width] 2xl:w-[--sidebar-width-large] bg-sidebar p-0 text-sidebar-foreground [&>button]:hidden"
|
|
227
|
+
style={{ '--sidebar-width': SIDEBAR_WIDTH_MOBILE } as CSSProperties}
|
|
228
|
+
side={side}
|
|
229
|
+
>
|
|
230
|
+
<div className="flex h-full w-full flex-col">{children}</div>
|
|
231
|
+
</SheetContent>
|
|
232
|
+
</Sheet>
|
|
233
|
+
)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<div
|
|
238
|
+
ref={ref}
|
|
239
|
+
className="group peer hidden md:block text-sidebar-foreground bg-sidebar"
|
|
240
|
+
data-state={state}
|
|
241
|
+
data-collapsible={state === 'collapsed' ? collapsible : ''}
|
|
242
|
+
data-variant={variant}
|
|
243
|
+
data-side={side}
|
|
244
|
+
>
|
|
245
|
+
<SidebarDesktopGap variant={variant} />
|
|
246
|
+
<SidebarInner side={side} variant={variant} className={className} {...props}>
|
|
247
|
+
{children}
|
|
248
|
+
</SidebarInner>
|
|
249
|
+
</div>
|
|
250
|
+
)
|
|
251
|
+
},
|
|
252
|
+
)
|
|
253
|
+
Sidebar.displayName = 'Sidebar'
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
export const SidebarTrigger = forwardRef<ElementRef<typeof Button>, ComponentProps<typeof Button>>(({
|
|
257
|
+
className,
|
|
258
|
+
onClick,
|
|
259
|
+
...props
|
|
260
|
+
}, ref) => {
|
|
261
|
+
const { toggleSidebar } = useSidebar()
|
|
262
|
+
|
|
263
|
+
return (
|
|
264
|
+
<Button ref={ref} data-sidebar="trigger" variant="ghost" size="icon" className={cn('h-7 w-7', className)} onClick={event => {
|
|
265
|
+
onClick?.(event)
|
|
266
|
+
toggleSidebar()
|
|
267
|
+
}} {...props}>
|
|
268
|
+
<PanelLeft size={16} />
|
|
269
|
+
<span className="sr-only">Toggle Sidebar</span>
|
|
270
|
+
</Button>
|
|
271
|
+
)
|
|
272
|
+
})
|
|
273
|
+
SidebarTrigger.displayName = 'SidebarTrigger'
|
|
274
|
+
|
|
275
|
+
export const SidebarRail = forwardRef<HTMLButtonElement, ComponentProps<'button'>>(({ className, ...props }, ref) => {
|
|
276
|
+
const { toggleSidebar } = useSidebar()
|
|
277
|
+
|
|
278
|
+
return (
|
|
279
|
+
<button
|
|
280
|
+
ref={ref}
|
|
281
|
+
data-sidebar="rail"
|
|
282
|
+
aria-label="Toggle Sidebar"
|
|
283
|
+
tabIndex={-1}
|
|
284
|
+
onClick={toggleSidebar}
|
|
285
|
+
title="Toggle Sidebar"
|
|
286
|
+
className={cn(
|
|
287
|
+
'absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear hover:after:bg-sidebar-border sm:flex',
|
|
288
|
+
'after:absolute after:inset-y-0 after:left-1/2 after:w-[2px]',
|
|
289
|
+
'group-data-[side=left]:-right-4 group-data-[side=right]:left-0',
|
|
290
|
+
'[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize [[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize',
|
|
291
|
+
'group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar',
|
|
292
|
+
'[[data-side=left][data-collapsible=offcanvas]_&]:-right-2',
|
|
293
|
+
'[[data-side=right][data-collapsible=offcanvas]_&]:-left-2',
|
|
294
|
+
className,
|
|
295
|
+
)}
|
|
296
|
+
{...props}
|
|
297
|
+
/>
|
|
298
|
+
)
|
|
299
|
+
})
|
|
300
|
+
SidebarRail.displayName = 'SidebarRail'
|
|
301
|
+
|
|
302
|
+
export const SidebarInput = uic(Input, {
|
|
303
|
+
baseClass: 'h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring',
|
|
304
|
+
defaultProps: {
|
|
305
|
+
'data-sidebar': 'input',
|
|
306
|
+
},
|
|
307
|
+
displayName: 'SidebarInput',
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
export const SidebarHeader = uic('header', {
|
|
311
|
+
baseClass: 'flex flex-col gap-2 p-1 2xl:p-3',
|
|
312
|
+
defaultProps: {
|
|
313
|
+
'data-sidebar': 'header',
|
|
314
|
+
},
|
|
315
|
+
displayName: 'SidebarHeader',
|
|
316
|
+
})
|
|
317
|
+
|
|
318
|
+
export const SidebarFooter = uic('footer', {
|
|
319
|
+
baseClass: 'flex flex-col gap-2 p-1 2xl:p-3',
|
|
320
|
+
defaultProps: {
|
|
321
|
+
'data-sidebar': 'footer',
|
|
322
|
+
},
|
|
323
|
+
displayName: 'SidebarFooter',
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
export const SidebarSeparator = uic(Separator, {
|
|
327
|
+
baseClass: 'mx-2 w-auto bg-sidebar-border',
|
|
328
|
+
defaultProps: {
|
|
329
|
+
'data-sidebar': 'separator',
|
|
330
|
+
},
|
|
331
|
+
displayName: 'SidebarSeparator',
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
export const SidebarContent = uic('div', {
|
|
335
|
+
baseClass: 'flex min-h-0 flex-1 flex-col gap-2 overflow-auto group-data-[collapsible=icon]:overflow-hidden',
|
|
336
|
+
defaultProps: {
|
|
337
|
+
'data-sidebar': 'content',
|
|
338
|
+
},
|
|
339
|
+
displayName: 'SidebarContent',
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
export const SidebarGroup = uic('div', {
|
|
343
|
+
baseClass: 'relative flex w-full min-w-0 flex-col p-2 2xl:p-4',
|
|
344
|
+
defaultProps: {
|
|
345
|
+
'data-sidebar': 'group',
|
|
346
|
+
},
|
|
347
|
+
displayName: 'SidebarGroup',
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
export const SidebarGroupLabel = uic('div', {
|
|
351
|
+
baseClass: [
|
|
352
|
+
'duration-200 flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium text-sidebar-foreground/70 outline-none ring-sidebar-ring transition-[margin,opa] ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
|
353
|
+
'group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0',
|
|
354
|
+
],
|
|
355
|
+
defaultProps: {
|
|
356
|
+
'data-sidebar': 'group-label',
|
|
357
|
+
},
|
|
358
|
+
displayName: 'SidebarGroupLabel',
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
export const SidebarGroupAction = uic('button', {
|
|
362
|
+
baseClass: [
|
|
363
|
+
'absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0',
|
|
364
|
+
// Increases the hit area of the button on mobile.
|
|
365
|
+
'after:absolute after:-inset-2 after:md:hidden',
|
|
366
|
+
'group-data-[collapsible=icon]:hidden',
|
|
367
|
+
],
|
|
368
|
+
defaultProps: {
|
|
369
|
+
'data-sidebar': 'group-action',
|
|
370
|
+
},
|
|
371
|
+
displayName: 'SidebarGroupAction',
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
export const SidebarGroupContent = uic('div', {
|
|
375
|
+
baseClass: 'w-full text-sm',
|
|
376
|
+
defaultProps: {
|
|
377
|
+
'data-sidebar': 'group-content',
|
|
378
|
+
},
|
|
379
|
+
displayName: 'SidebarGroupContent',
|
|
380
|
+
})
|
|
381
|
+
|
|
382
|
+
export const SidebarMenu = uic('ul', {
|
|
383
|
+
baseClass: 'flex w-full min-w-0 flex-col gap-1',
|
|
384
|
+
defaultProps: {
|
|
385
|
+
'data-sidebar': 'menu',
|
|
386
|
+
},
|
|
387
|
+
displayName: 'SidebarMenu',
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
export const SidebarMenuItem = uic('li', {
|
|
391
|
+
baseClass: 'group/menu-item relative',
|
|
392
|
+
defaultProps: {
|
|
393
|
+
'data-sidebar': 'menu-item',
|
|
394
|
+
},
|
|
395
|
+
displayName: 'SidebarMenuItem',
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
export const sidebarMenuButtonVariants = cva(
|
|
399
|
+
[
|
|
400
|
+
'peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring',
|
|
401
|
+
'transition-[width,height,padding]',
|
|
402
|
+
'hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
|
403
|
+
'focus-visible:ring-2',
|
|
404
|
+
'active:bg-sidebar-accent active:text-sidebar-accent-foreground',
|
|
405
|
+
'disabled:pointer-events-none disabled:opacity-50',
|
|
406
|
+
'group-has-[[data-sidebar=menu-action]]/menu-item:pr-8',
|
|
407
|
+
'aria-disabled:pointer-events-none aria-disabled:opacity-50',
|
|
408
|
+
'data-[active]:bg-sidebar-accent data-[active]:font-medium data-[active]:text-sidebar-accent-foreground',
|
|
409
|
+
'data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground',
|
|
410
|
+
'group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2',
|
|
411
|
+
'[&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0',
|
|
412
|
+
],
|
|
413
|
+
{
|
|
414
|
+
variants: {
|
|
415
|
+
variant: {
|
|
416
|
+
default: 'hover:bg-sidebar-accent hover:text-sidebar-accent-foreground',
|
|
417
|
+
outline:
|
|
418
|
+
'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))]',
|
|
419
|
+
},
|
|
420
|
+
size: {
|
|
421
|
+
default: 'h-8 text-sm',
|
|
422
|
+
sm: 'h-7 text-xs',
|
|
423
|
+
lg: 'h-12 text-base',
|
|
424
|
+
},
|
|
425
|
+
},
|
|
426
|
+
defaultVariants: {
|
|
427
|
+
variant: 'default',
|
|
428
|
+
size: 'default',
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
type SidebarMenuButtonProps = ComponentProps<'button'> & {
|
|
434
|
+
asChild?: boolean
|
|
435
|
+
isActive?: boolean
|
|
436
|
+
tooltip?: ReactNode
|
|
437
|
+
} & VariantProps<typeof sidebarMenuButtonVariants>
|
|
438
|
+
|
|
439
|
+
export const SidebarMenuButton = forwardRef<HTMLButtonElement, SidebarMenuButtonProps>(
|
|
440
|
+
(
|
|
441
|
+
{
|
|
442
|
+
asChild = false,
|
|
443
|
+
isActive = false,
|
|
444
|
+
variant = 'default',
|
|
445
|
+
size = 'default',
|
|
446
|
+
tooltip,
|
|
447
|
+
className,
|
|
448
|
+
...props
|
|
449
|
+
},
|
|
450
|
+
ref,
|
|
451
|
+
) => {
|
|
452
|
+
const Comp = asChild ? Slot : 'button'
|
|
453
|
+
const { isMobile, state } = useSidebar()
|
|
454
|
+
|
|
455
|
+
const button = (
|
|
456
|
+
<Comp
|
|
457
|
+
ref={ref}
|
|
458
|
+
data-sidebar="menu-button"
|
|
459
|
+
data-size={size}
|
|
460
|
+
data-active={dataAttribute(isActive)}
|
|
461
|
+
className={cn(sidebarMenuButtonVariants({ variant, size }), className)}
|
|
462
|
+
{...props}
|
|
463
|
+
/>
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
if (!tooltip) {
|
|
467
|
+
return button
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
return (
|
|
471
|
+
<Tooltip>
|
|
472
|
+
<TooltipTrigger asChild>{button}</TooltipTrigger>
|
|
473
|
+
<TooltipContent
|
|
474
|
+
side="right"
|
|
475
|
+
align="center"
|
|
476
|
+
hidden={state !== 'collapsed' || isMobile}
|
|
477
|
+
>{tooltip}</TooltipContent>
|
|
478
|
+
</Tooltip>
|
|
479
|
+
)
|
|
480
|
+
},
|
|
481
|
+
)
|
|
482
|
+
SidebarMenuButton.displayName = 'SidebarMenuButton'
|
|
483
|
+
|
|
484
|
+
export const SidebarMenuAction = uic('button', {
|
|
485
|
+
baseClass: [
|
|
486
|
+
'absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2',
|
|
487
|
+
'peer-hover/menu-button:text-sidebar-accent-foreground',
|
|
488
|
+
'[&>svg]:size-4 [&>svg]:shrink-0',
|
|
489
|
+
// Increases the hit area of the button on mobile.
|
|
490
|
+
'after:absolute after:-inset-2 after:md:hidden',
|
|
491
|
+
'peer-data-[size=sm]/menu-button:top-1',
|
|
492
|
+
'peer-data-[size=default]/menu-button:top-1.5',
|
|
493
|
+
'peer-data-[size=lg]/menu-button:top-2.5',
|
|
494
|
+
'group-data-[collapsible=icon]:hidden',
|
|
495
|
+
],
|
|
496
|
+
defaultProps: {
|
|
497
|
+
'data-sidebar': 'menu-action',
|
|
498
|
+
},
|
|
499
|
+
variants: {
|
|
500
|
+
showInHover: {
|
|
501
|
+
true: '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',
|
|
502
|
+
},
|
|
503
|
+
},
|
|
504
|
+
displayName: '',
|
|
505
|
+
})
|
|
506
|
+
|
|
507
|
+
export const SidebarMenuBadge = uic('div', {
|
|
508
|
+
baseClass: [
|
|
509
|
+
'absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums text-sidebar-foreground select-none pointer-events-none',
|
|
510
|
+
'peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground',
|
|
511
|
+
'peer-data-[size=sm]/menu-button:top-1',
|
|
512
|
+
'peer-data-[size=default]/menu-button:top-1.5',
|
|
513
|
+
'peer-data-[size=lg]/menu-button:top-2.5',
|
|
514
|
+
'group-data-[collapsible=icon]:hidden',
|
|
515
|
+
],
|
|
516
|
+
defaultProps: {
|
|
517
|
+
'data-sidebar': 'menu-badge',
|
|
518
|
+
},
|
|
519
|
+
displayName: 'SidebarMenuBadge',
|
|
520
|
+
})
|
|
521
|
+
|
|
522
|
+
interface SidebarMenuSkeletonProps extends ComponentProps<'div'> {
|
|
523
|
+
showIcon?: boolean
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export const SidebarMenuSkeleton = forwardRef<HTMLDivElement, SidebarMenuSkeletonProps>(({
|
|
527
|
+
className,
|
|
528
|
+
showIcon = false,
|
|
529
|
+
...props
|
|
530
|
+
}, ref) => {
|
|
531
|
+
// Random width between 50 to 90%.
|
|
532
|
+
const width = useMemo(() => `${Math.floor(Math.random() * 40) + 50}%`, [])
|
|
533
|
+
|
|
534
|
+
return (
|
|
535
|
+
<div
|
|
536
|
+
ref={ref}
|
|
537
|
+
data-sidebar="menu-skeleton"
|
|
538
|
+
className={cn('rounded-md h-8 flex gap-2 px-2 items-center', className)}
|
|
539
|
+
{...props}
|
|
540
|
+
>
|
|
541
|
+
{showIcon && <Skeleton className="size-4 rounded-md" data-sidebar="menu-skeleton-icon" />}
|
|
542
|
+
<Skeleton
|
|
543
|
+
style={{ '--skeleton-width': width } as CSSProperties}
|
|
544
|
+
className="h-4 flex-1 max-w-[--skeleton-width]"
|
|
545
|
+
data-sidebar="menu-skeleton-text"
|
|
546
|
+
/>
|
|
547
|
+
</div>
|
|
548
|
+
)
|
|
549
|
+
})
|
|
550
|
+
SidebarMenuSkeleton.displayName = 'SidebarMenuSkeleton'
|
|
551
|
+
|
|
552
|
+
export const SidebarMenuSub = uic('ul', {
|
|
553
|
+
baseClass: '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',
|
|
554
|
+
defaultProps: {
|
|
555
|
+
'data-sidebar': 'menu-sub',
|
|
556
|
+
},
|
|
557
|
+
displayName: 'SidebarMenuSub',
|
|
558
|
+
})
|
|
559
|
+
|
|
560
|
+
export { useSidebar }
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
1
|
import * as SwitchPrimitives from '@radix-ui/react-switch'
|
|
3
|
-
import
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { uic } from '../utils'
|
|
4
4
|
|
|
5
5
|
export const Switch = uic(SwitchPrimitives.Root, {
|
|
6
6
|
baseClass: 'peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input',
|
|
7
|
-
afterChildren:
|
|
8
|
-
className=
|
|
9
|
-
/>,
|
|
7
|
+
afterChildren:
|
|
8
|
+
<SwitchPrimitives.Thumb className="pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0" />,
|
|
10
9
|
})
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
1
|
import * as ToggleGroupPrimitive from '@radix-ui/react-toggle-group'
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { cn, uic } from '../utils'
|
|
3
4
|
import { toggleConfig, ToggleProps } from './toggle'
|
|
4
|
-
import { cn } from '../utils/cn'
|
|
5
|
-
import { uic } from '../utils/uic'
|
|
6
5
|
|
|
7
6
|
const ToggleGroupContext = React.createContext<ToggleProps>({
|
|
8
7
|
size: 'default',
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as React from 'react'
|
|
2
1
|
import * as TogglePrimitive from '@radix-ui/react-toggle'
|
|
3
|
-
import { ConfigVariants, uic, uiconfig } from '../utils
|
|
2
|
+
import { ConfigVariants, uic, uiconfig } from '../utils'
|
|
4
3
|
|
|
5
4
|
export const toggleConfig = uiconfig({
|
|
6
5
|
baseClass: 'inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[active]:bg-accent data-[active]:shadow-inner data-[active]:text-accent-foreground',
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as TooltipPrimitive from '@radix-ui/react-tooltip'
|
|
2
2
|
import { uic } from '../utils'
|
|
3
|
-
|
|
3
|
+
import { createComponentOpenHooks } from '../utils/createComponentOpenHooks'
|
|
4
4
|
|
|
5
5
|
export const TooltipProvider = TooltipPrimitive.Provider
|
|
6
6
|
|
|
7
|
-
export const Tooltip = TooltipPrimitive.Root
|
|
7
|
+
export const { Component: Tooltip, useOpen: useTooltipOpenState } = createComponentOpenHooks(TooltipPrimitive.Root)
|
|
8
8
|
|
|
9
9
|
export const TooltipTrigger = TooltipPrimitive.Trigger
|
|
10
10
|
|