53 lines
1.9 KiB
Vue
53 lines
1.9 KiB
Vue
<script setup lang="ts">
|
|
import type { ContextMenuItemEmits, ContextMenuItemProps } from "reka-ui";
|
|
import type { HTMLAttributes } from "vue";
|
|
import { reactiveOmit } from "@vueuse/core";
|
|
import { ContextMenuItem, useForwardPropsEmits } from "reka-ui";
|
|
import { shouldSuppressRepeatedActivation, suppressEvent, type ActionActivationGuard } from "@/lib/actionActivation";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
const props = withDefaults(
|
|
defineProps<
|
|
ContextMenuItemProps & {
|
|
class?: HTMLAttributes["class"];
|
|
inset?: boolean;
|
|
variant?: "default" | "destructive";
|
|
}
|
|
>(),
|
|
{
|
|
variant: "default",
|
|
},
|
|
);
|
|
const emits = defineEmits<ContextMenuItemEmits>();
|
|
|
|
const delegatedProps = reactiveOmit(props, "class");
|
|
|
|
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|
const activationGuard: ActionActivationGuard = {};
|
|
|
|
function guardRepeatedClick(event: MouseEvent) {
|
|
if (props.disabled) return;
|
|
if (shouldSuppressRepeatedActivation(activationGuard)) {
|
|
suppressEvent(event);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<ContextMenuItem
|
|
data-slot="context-menu-item"
|
|
:data-inset="inset ? '' : undefined"
|
|
:data-variant="variant"
|
|
v-bind="forwarded"
|
|
@click.capture="guardRepeatedClick"
|
|
:class="
|
|
cn(
|
|
'focus:bg-accent focus: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 focus:*:[svg]:text-accent-foreground gap-2 rounded-md px-2 py-1 text-[13px] data-inset:pl-7 [&_svg:not([class*=size-])]:size-4 group/context-menu-item relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0',
|
|
props.class,
|
|
)
|
|
"
|
|
>
|
|
<slot />
|
|
</ContextMenuItem>
|
|
</template>
|