-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(contextmenu): support item disabled
- Loading branch information
Showing
5 changed files
with
108 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,29 @@ | ||
<template> | ||
<div @click="onClick" | ||
class="relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-gray-100 focus:bg-gray-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50"> | ||
:class="[ | ||
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors hover:bg-gray-100 focus:bg-gray-100 data-[disabled]:pointer-events-none data-[disabled]:opacity-50', | ||
{ 'opacity-50 cursor-not-allowed': disabled } | ||
]"> | ||
<slot/> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ContextMenuItemEmits } from './types' | ||
import { ContextMenuItemEmits, ContextMenuItemProps } from './types' | ||
import { inject } from 'vue' | ||
const props = withDefaults(defineProps<ContextMenuItemProps>(), { | ||
disabled: false | ||
}) | ||
const closeMenu = inject('closeMenu') as () => void | ||
const emit = defineEmits<ContextMenuItemEmits>() | ||
const onClick = () => { | ||
emit('on-click') | ||
closeMenu() | ||
if (!props.disabled) { | ||
emit('on-click') | ||
closeMenu() | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ export interface ContextMenuProps | |
export interface ContextMenuItemProps | ||
{ | ||
label?: string | ||
disabled?: boolean | ||
} |