130 lines
3.7 KiB
TypeScript
130 lines
3.7 KiB
TypeScript
"use client";
|
|
|
|
import { ContextMenu as ContextMenuPrimitive } from "@base-ui/react/context-menu";
|
|
|
|
import { resolveAsChild } from "@/lib/as-child";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
function ContextMenu({ ...props }: ContextMenuPrimitive.Root.Props) {
|
|
return <ContextMenuPrimitive.Root data-slot="context-menu" {...props} />;
|
|
}
|
|
|
|
function ContextMenuTrigger({
|
|
asChild = false,
|
|
children,
|
|
render,
|
|
className,
|
|
...props
|
|
}: ContextMenuPrimitive.Trigger.Props & { asChild?: boolean }) {
|
|
const resolved = resolveAsChild(asChild, children, render);
|
|
return (
|
|
<ContextMenuPrimitive.Trigger
|
|
data-slot="context-menu-trigger"
|
|
className={cn("select-none", className)}
|
|
render={resolved.render}
|
|
{...props}
|
|
>
|
|
{resolved.children}
|
|
</ContextMenuPrimitive.Trigger>
|
|
);
|
|
}
|
|
|
|
function ContextMenuContent({
|
|
className,
|
|
align = "start",
|
|
alignOffset = 4,
|
|
side = "bottom",
|
|
sideOffset = 0,
|
|
...props
|
|
}: ContextMenuPrimitive.Popup.Props &
|
|
Pick<
|
|
ContextMenuPrimitive.Positioner.Props,
|
|
"align" | "alignOffset" | "side" | "sideOffset"
|
|
>) {
|
|
return (
|
|
<ContextMenuPrimitive.Portal>
|
|
<ContextMenuPrimitive.Positioner
|
|
className="isolate z-50 outline-none"
|
|
align={align}
|
|
alignOffset={alignOffset}
|
|
side={side}
|
|
sideOffset={sideOffset}
|
|
>
|
|
<ContextMenuPrimitive.Popup
|
|
data-slot="context-menu-content"
|
|
className={cn(
|
|
"bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 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 z-50 max-h-(--available-height) min-w-[8rem] origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md outline-none",
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
</ContextMenuPrimitive.Positioner>
|
|
</ContextMenuPrimitive.Portal>
|
|
);
|
|
}
|
|
|
|
function ContextMenuItem({
|
|
className,
|
|
inset,
|
|
variant = "default",
|
|
...props
|
|
}: ContextMenuPrimitive.Item.Props & {
|
|
inset?: boolean;
|
|
variant?: "default" | "destructive";
|
|
}) {
|
|
return (
|
|
<ContextMenuPrimitive.Item
|
|
data-slot="context-menu-item"
|
|
data-inset={inset}
|
|
data-variant={variant}
|
|
className={cn(
|
|
"focus:bg-accent focus:text-accent-foreground data-highlighted:bg-accent data-highlighted:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function ContextMenuSeparator({
|
|
className,
|
|
...props
|
|
}: ContextMenuPrimitive.Separator.Props) {
|
|
return (
|
|
<ContextMenuPrimitive.Separator
|
|
data-slot="context-menu-separator"
|
|
className={cn("bg-border -mx-1 my-1 h-px", className)}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
function ContextMenuLabel({
|
|
className,
|
|
inset,
|
|
...props
|
|
}: ContextMenuPrimitive.GroupLabel.Props & {
|
|
inset?: boolean;
|
|
}) {
|
|
return (
|
|
<ContextMenuPrimitive.GroupLabel
|
|
data-slot="context-menu-label"
|
|
data-inset={inset}
|
|
className={cn(
|
|
"px-2 py-1.5 text-xs font-medium text-muted-foreground data-[inset]:pl-8",
|
|
className,
|
|
)}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export {
|
|
ContextMenu,
|
|
ContextMenuContent,
|
|
ContextMenuItem,
|
|
ContextMenuLabel,
|
|
ContextMenuSeparator,
|
|
ContextMenuTrigger,
|
|
};
|