-
-
Notifications
You must be signed in to change notification settings - Fork 622
Expand file tree
/
Copy pathItem.vue
More file actions
74 lines (69 loc) · 2.34 KB
/
Item.vue
File metadata and controls
74 lines (69 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<script setup>
import { ContextMenuItem } from 'reka-ui';
import { computed, useSlots } from 'vue';
import Icon from '../Icon/Icon.vue';
import { cva } from 'cva';
import { Link } from "@inertiajs/vue3";
const props = defineProps({
/** The element or component this component should render as */
as: { type: String, default: null },
/** The URL to link to */
href: { type: String, default: null },
/** When `href` is provided, this prop controls the link's `target` attribute */
target: { type: String, default: '_self' },
/** Icon name. [Browse available icons](/?path=/story/components-icon--all-icons) */
icon: { type: String, default: null },
/** Text to display in the item */
text: { type: String, default: null },
/** Controls the appearance of the context item. Options: `default`, `destructive` */
variant: { type: String, default: 'default' },
});
const slots = useSlots();
const hasDefaultSlot = !!slots.default;
const tag = computed(() => {
if (props.as) return props.as;
if (! props.href) return 'div';
return props.target === '_blank' ? 'a' : Link;
});
const classes = cva({
base: [
'col-span-2 grid grid-cols-subgrid items-center',
'rounded-lg px-1 py-1.5 text-sm antialiased',
'text-gray-700 dark:text-gray-300',
'not-data-disabled:cursor-pointer data-disabled:opacity-50',
'hover:not-data-disabled:bg-gray-50 dark:hover:not-data-disabled:bg-gray-950 outline-hidden',
],
variants: {
variant: {
default: 'text-gray-700 dark:text-gray-300',
destructive: 'text-red-600',
},
},
})({ variant: props.variant });
const iconClasses = cva({
variants: {
base: 'size-3.5!',
variant: {
default: 'text-gray-500',
destructive: 'text-red-500!',
},
},
})({ variant: props.variant });
</script>
<template>
<ContextMenuItem
:class="classes"
data-ui-context-item
:as="tag"
:href
:target
>
<div v-if="icon" class="flex size-6 items-center justify-center p-1 text-gray-500">
<Icon :name="icon" :class="iconClasses" />
</div>
<div class="col-start-2 ps-2">
<slot v-if="hasDefaultSlot" />
<template v-else>{{ text }}</template>
</div>
</ContextMenuItem>
</template>