2022-11-24 17:34:05 +09:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { dropdownContextKey } from './ctx'
|
|
|
|
|
2022-11-29 17:15:05 +09:00
|
|
|
const props = defineProps<{
|
|
|
|
text?: string
|
2022-11-24 18:15:58 +09:00
|
|
|
description?: string
|
2022-11-24 17:34:05 +09:00
|
|
|
icon?: string
|
2022-11-24 18:15:58 +09:00
|
|
|
checked?: boolean
|
2022-11-29 17:15:05 +09:00
|
|
|
command?: boolean
|
2022-11-24 17:34:05 +09:00
|
|
|
}>()
|
|
|
|
const emit = defineEmits(['click'])
|
|
|
|
|
2022-11-26 14:05:44 +09:00
|
|
|
const { hide } = inject(dropdownContextKey, undefined) || {}
|
2022-11-24 17:34:05 +09:00
|
|
|
|
2022-11-29 17:15:05 +09:00
|
|
|
const el = ref<HTMLDivElement>()
|
|
|
|
|
2022-11-24 17:34:05 +09:00
|
|
|
const handleClick = (evt: MouseEvent) => {
|
2022-11-26 14:05:44 +09:00
|
|
|
hide?.()
|
2022-11-24 17:34:05 +09:00
|
|
|
emit('click', evt)
|
|
|
|
}
|
2022-11-29 17:15:05 +09:00
|
|
|
|
|
|
|
useCommand({
|
|
|
|
scope: 'Actions',
|
|
|
|
|
|
|
|
order: -1,
|
|
|
|
visible: () => props.command && props.text,
|
|
|
|
|
|
|
|
name: () => props.text!,
|
|
|
|
icon: () => props.icon ?? 'i-ri:question-line',
|
|
|
|
description: () => props.description,
|
|
|
|
|
|
|
|
onActivate() {
|
|
|
|
const clickEvent = new MouseEvent('click', {
|
|
|
|
view: window,
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true,
|
|
|
|
})
|
|
|
|
el.value?.dispatchEvent(clickEvent)
|
|
|
|
},
|
|
|
|
})
|
2022-11-24 17:34:05 +09:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-24 18:15:58 +09:00
|
|
|
<div
|
2022-11-29 17:15:05 +09:00
|
|
|
v-bind="$attrs" ref="el"
|
|
|
|
flex gap-3 items-center cursor-pointer px4 py3
|
|
|
|
hover-bg-active
|
2022-11-30 22:00:54 +09:00
|
|
|
:aria-label="text"
|
2022-11-24 18:15:58 +09:00
|
|
|
@click="handleClick"
|
|
|
|
>
|
2022-11-24 17:34:05 +09:00
|
|
|
<div v-if="icon" :class="icon" />
|
2022-11-24 18:15:58 +09:00
|
|
|
<div flex="~ col">
|
2022-11-26 14:05:44 +09:00
|
|
|
<div text-15px>
|
2022-11-29 17:15:05 +09:00
|
|
|
<slot>
|
|
|
|
{{ text }}
|
|
|
|
</slot>
|
2022-11-24 18:15:58 +09:00
|
|
|
</div>
|
2022-11-27 05:41:18 +09:00
|
|
|
<div text-3 text-secondary>
|
2022-11-24 18:15:58 +09:00
|
|
|
<slot name="description">
|
|
|
|
<p v-if="description">
|
|
|
|
{{ description }}
|
|
|
|
</p>
|
|
|
|
</slot>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div flex-auto />
|
|
|
|
|
|
|
|
<div v-if="checked" i-ri:check-line />
|
2022-11-26 21:58:10 +09:00
|
|
|
<slot name="actions" />
|
2022-11-24 17:34:05 +09:00
|
|
|
</div>
|
|
|
|
</template>
|