Uecko_ERP/packages/shadcn-ui/src/components/menubar.tsx

281 lines
8.0 KiB
TypeScript
Raw Normal View History

2026-04-12 10:07:54 +00:00
"use client"
2026-05-04 18:33:24 +00:00
import type * as React from "react"
2026-04-12 10:07:54 +00:00
import { Menu as MenuPrimitive } from "@base-ui/react/menu"
import { Menubar as MenubarPrimitive } from "@base-ui/react/menubar"
2025-05-05 17:11:44 +00:00
import { cn } from "@repo/shadcn-ui/lib/utils"
2026-04-12 10:07:54 +00:00
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuPortal,
DropdownMenuRadioGroup,
DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
DropdownMenuTrigger,
} from "@repo/shadcn-ui/components/dropdown-menu"
import { CheckIcon } from "lucide-react"
2025-05-05 17:11:44 +00:00
2026-04-12 10:07:54 +00:00
function Menubar({ className, ...props }: MenubarPrimitive.Props) {
2025-05-05 17:11:44 +00:00
return (
2026-04-12 10:07:54 +00:00
<MenubarPrimitive
2025-05-05 17:11:44 +00:00
data-slot="menubar"
className={cn(
2026-04-12 10:07:54 +00:00
"flex h-9 items-center gap-1 rounded-md border p-1 shadow-xs",
2025-05-05 17:11:44 +00:00
className
)}
{...props}
/>
)
}
2026-04-12 10:07:54 +00:00
function MenubarMenu({ ...props }: React.ComponentProps<typeof DropdownMenu>) {
return <DropdownMenu data-slot="menubar-menu" {...props} />
2025-05-05 17:11:44 +00:00
}
function MenubarGroup({
...props
2026-04-12 10:07:54 +00:00
}: React.ComponentProps<typeof DropdownMenuGroup>) {
return <DropdownMenuGroup data-slot="menubar-group" {...props} />
2025-05-05 17:11:44 +00:00
}
function MenubarPortal({
...props
2026-04-12 10:07:54 +00:00
}: React.ComponentProps<typeof DropdownMenuPortal>) {
return <DropdownMenuPortal data-slot="menubar-portal" {...props} />
2025-05-05 17:11:44 +00:00
}
function MenubarTrigger({
className,
...props
2026-04-12 10:07:54 +00:00
}: React.ComponentProps<typeof DropdownMenuTrigger>) {
2025-05-05 17:11:44 +00:00
return (
2026-04-12 10:07:54 +00:00
<DropdownMenuTrigger
2025-05-05 17:11:44 +00:00
data-slot="menubar-trigger"
className={cn(
2026-04-12 10:07:54 +00:00
"flex items-center rounded-sm px-2 py-1 text-sm font-medium outline-hidden select-none hover:bg-muted aria-expanded:bg-muted",
2025-05-05 17:11:44 +00:00
className
)}
{...props}
/>
)
}
function MenubarContent({
className,
align = "start",
alignOffset = -4,
sideOffset = 8,
...props
2026-04-12 10:07:54 +00:00
}: React.ComponentProps<typeof DropdownMenuContent>) {
2025-05-05 17:11:44 +00:00
return (
2026-04-12 10:07:54 +00:00
<DropdownMenuContent
data-slot="menubar-content"
align={align}
alignOffset={alignOffset}
sideOffset={sideOffset}
className={cn("min-w-36 rounded-md bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95", className )}
{...props}
/>
2025-05-05 17:11:44 +00:00
)
}
function MenubarItem({
className,
inset,
variant = "default",
...props
2026-04-12 10:07:54 +00:00
}: React.ComponentProps<typeof DropdownMenuItem>) {
2025-05-05 17:11:44 +00:00
return (
2026-04-12 10:07:54 +00:00
<DropdownMenuItem
2025-05-05 17:11:44 +00:00
data-slot="menubar-item"
data-inset={inset}
data-variant={variant}
className={cn(
2026-04-12 10:07:54 +00:00
"group/menubar-item gap-2 rounded-sm px-2 py-1.5 text-sm focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:opacity-50 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive!",
2025-05-05 17:11:44 +00:00
className
)}
{...props}
/>
)
}
function MenubarCheckboxItem({
className,
children,
checked,
2026-03-17 17:49:54 +00:00
inset,
2025-05-05 17:11:44 +00:00
...props
2026-04-12 10:07:54 +00:00
}: MenuPrimitive.CheckboxItem.Props & {
2026-03-17 17:49:54 +00:00
inset?: boolean
}) {
2025-05-05 17:11:44 +00:00
return (
2026-04-12 10:07:54 +00:00
<MenuPrimitive.CheckboxItem
2025-05-05 17:11:44 +00:00
data-slot="menubar-checkbox-item"
2026-03-17 17:49:54 +00:00
data-inset={inset}
2025-05-05 17:11:44 +00:00
className={cn(
2026-04-12 10:07:54 +00:00
"relative flex cursor-default items-center gap-2 rounded-md py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-8 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0",
2025-05-05 17:11:44 +00:00
className
)}
checked={checked}
{...props}
>
2026-04-12 10:07:54 +00:00
<span className="pointer-events-none absolute left-2 flex size-4 items-center justify-center [&_svg:not([class*='size-'])]:size-4">
<MenuPrimitive.CheckboxItemIndicator>
2026-03-17 17:49:54 +00:00
<CheckIcon
/>
2026-04-12 10:07:54 +00:00
</MenuPrimitive.CheckboxItemIndicator>
2025-05-05 17:11:44 +00:00
</span>
{children}
2026-04-12 10:07:54 +00:00
</MenuPrimitive.CheckboxItem>
2025-05-05 17:11:44 +00:00
)
}
2026-04-12 10:07:54 +00:00
function MenubarRadioGroup({
...props
}: React.ComponentProps<typeof DropdownMenuRadioGroup>) {
return <DropdownMenuRadioGroup data-slot="menubar-radio-group" {...props} />
}
2025-05-05 17:11:44 +00:00
function MenubarRadioItem({
className,
children,
2026-03-17 17:49:54 +00:00
inset,
2025-05-05 17:11:44 +00:00
...props
2026-04-12 10:07:54 +00:00
}: MenuPrimitive.RadioItem.Props & {
2026-03-17 17:49:54 +00:00
inset?: boolean
}) {
2025-05-05 17:11:44 +00:00
return (
2026-04-12 10:07:54 +00:00
<MenuPrimitive.RadioItem
2025-05-05 17:11:44 +00:00
data-slot="menubar-radio-item"
2026-03-17 17:49:54 +00:00
data-inset={inset}
2025-05-05 17:11:44 +00:00
className={cn(
2026-04-12 10:07:54 +00:00
"relative flex cursor-default items-center gap-2 rounded-md py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground data-inset:pl-8 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
2025-05-05 17:11:44 +00:00
className
)}
{...props}
>
2026-04-12 10:07:54 +00:00
<span className="pointer-events-none absolute left-2 flex size-4 items-center justify-center [&_svg:not([class*='size-'])]:size-4">
<MenuPrimitive.RadioItemIndicator>
2026-03-17 17:49:54 +00:00
<CheckIcon
/>
2026-04-12 10:07:54 +00:00
</MenuPrimitive.RadioItemIndicator>
2025-05-05 17:11:44 +00:00
</span>
{children}
2026-04-12 10:07:54 +00:00
</MenuPrimitive.RadioItem>
2025-05-05 17:11:44 +00:00
)
}
function MenubarLabel({
className,
inset,
...props
2026-04-12 10:07:54 +00:00
}: React.ComponentProps<typeof DropdownMenuLabel> & {
2025-05-05 17:11:44 +00:00
inset?: boolean
}) {
return (
2026-04-12 10:07:54 +00:00
<DropdownMenuLabel
2025-05-05 17:11:44 +00:00
data-slot="menubar-label"
data-inset={inset}
className={cn(
2026-04-12 10:07:54 +00:00
"px-2 py-1.5 text-sm font-medium data-inset:pl-8",
2025-05-05 17:11:44 +00:00
className
)}
{...props}
/>
)
}
function MenubarSeparator({
className,
...props
2026-04-12 10:07:54 +00:00
}: React.ComponentProps<typeof DropdownMenuSeparator>) {
2025-05-05 17:11:44 +00:00
return (
2026-04-12 10:07:54 +00:00
<DropdownMenuSeparator
2025-05-05 17:11:44 +00:00
data-slot="menubar-separator"
2026-03-17 17:49:54 +00:00
className={cn("-mx-1 my-1 h-px bg-border", className)}
2025-05-05 17:11:44 +00:00
{...props}
/>
)
}
function MenubarShortcut({
className,
...props
2026-04-12 10:07:54 +00:00
}: React.ComponentProps<typeof DropdownMenuShortcut>) {
2025-05-05 17:11:44 +00:00
return (
2026-04-12 10:07:54 +00:00
<DropdownMenuShortcut
2025-05-05 17:11:44 +00:00
data-slot="menubar-shortcut"
className={cn(
2026-03-17 17:49:54 +00:00
"ml-auto text-xs tracking-widest text-muted-foreground group-focus/menubar-item:text-accent-foreground",
2025-05-05 17:11:44 +00:00
className
)}
{...props}
/>
)
}
function MenubarSub({
...props
2026-04-12 10:07:54 +00:00
}: React.ComponentProps<typeof DropdownMenuSub>) {
return <DropdownMenuSub data-slot="menubar-sub" {...props} />
2025-05-05 17:11:44 +00:00
}
function MenubarSubTrigger({
className,
inset,
...props
2026-04-12 10:07:54 +00:00
}: React.ComponentProps<typeof DropdownMenuSubTrigger> & {
2025-05-05 17:11:44 +00:00
inset?: boolean
}) {
return (
2026-04-12 10:07:54 +00:00
<DropdownMenuSubTrigger
2025-05-05 17:11:44 +00:00
data-slot="menubar-sub-trigger"
data-inset={inset}
className={cn(
2026-04-12 10:07:54 +00:00
"gap-2 rounded-sm px-2 py-1.5 text-sm focus:bg-accent focus:text-accent-foreground data-inset:pl-8 data-open:bg-accent data-open:text-accent-foreground [&_svg:not([class*='size-'])]:size-4",
2025-05-05 17:11:44 +00:00
className
)}
{...props}
2026-04-12 10:07:54 +00:00
/>
2025-05-05 17:11:44 +00:00
)
}
function MenubarSubContent({
className,
...props
2026-04-12 10:07:54 +00:00
}: React.ComponentProps<typeof DropdownMenuSubContent>) {
2025-05-05 17:11:44 +00:00
return (
2026-04-12 10:07:54 +00:00
<DropdownMenuSubContent
2025-05-05 17:11:44 +00:00
data-slot="menubar-sub-content"
2026-04-12 10:07:54 +00:00
className={cn("min-w-32 rounded-md bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className )}
2025-05-05 17:11:44 +00:00
{...props}
/>
)
}
export {
Menubar,
MenubarPortal,
MenubarMenu,
MenubarTrigger,
MenubarContent,
MenubarGroup,
MenubarSeparator,
MenubarLabel,
MenubarItem,
MenubarShortcut,
MenubarCheckboxItem,
MenubarRadioGroup,
MenubarRadioItem,
MenubarSub,
MenubarSubTrigger,
MenubarSubContent,
}