2022-11-24 08:34:05 +00:00
|
|
|
<script setup lang="ts">
|
2024-10-21 10:00:51 +01:00
|
|
|
const {
|
|
|
|
is = 'div',
|
|
|
|
text,
|
|
|
|
description,
|
|
|
|
icon,
|
|
|
|
checked,
|
|
|
|
command,
|
|
|
|
} = defineProps<{
|
2023-01-22 09:57:30 +00:00
|
|
|
is?: string
|
2022-11-29 08:15:05 +00:00
|
|
|
text?: string
|
2022-11-24 09:15:58 +00:00
|
|
|
description?: string
|
2022-11-24 08:34:05 +00:00
|
|
|
icon?: string
|
2022-11-24 09:15:58 +00:00
|
|
|
checked?: boolean
|
2022-11-29 08:15:05 +00:00
|
|
|
command?: boolean
|
2024-10-21 10:00:51 +01:00
|
|
|
}>()
|
|
|
|
|
2022-11-24 08:34:05 +00:00
|
|
|
const emit = defineEmits(['click'])
|
|
|
|
|
2024-10-21 10:00:51 +01:00
|
|
|
const type = computed(() => is === 'button' ? 'button' : null)
|
|
|
|
|
2023-01-03 11:58:08 +00:00
|
|
|
const { hide } = useDropdownContext() || {}
|
2022-11-24 08:34:05 +00:00
|
|
|
|
2022-11-29 08:15:05 +00:00
|
|
|
const el = ref<HTMLDivElement>()
|
|
|
|
|
2023-03-30 20:01:24 +01:00
|
|
|
function handleClick(evt: MouseEvent) {
|
2022-11-26 05:05:44 +00:00
|
|
|
hide?.()
|
2022-11-24 08:34:05 +00:00
|
|
|
emit('click', evt)
|
|
|
|
}
|
2022-11-29 08:15:05 +00:00
|
|
|
|
|
|
|
useCommand({
|
|
|
|
scope: 'Actions',
|
|
|
|
|
|
|
|
order: -1,
|
2024-10-21 10:00:51 +01:00
|
|
|
visible: () => command && text,
|
2022-11-29 08:15:05 +00:00
|
|
|
|
2024-10-21 10:00:51 +01:00
|
|
|
name: () => text!,
|
|
|
|
icon: () => icon ?? 'i-ri:question-line',
|
|
|
|
description: () => description,
|
2022-11-29 08:15:05 +00:00
|
|
|
|
|
|
|
onActivate() {
|
|
|
|
const clickEvent = new MouseEvent('click', {
|
|
|
|
view: window,
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true,
|
|
|
|
})
|
|
|
|
el.value?.dispatchEvent(clickEvent)
|
|
|
|
},
|
|
|
|
})
|
2022-11-24 08:34:05 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2023-01-22 09:57:30 +00:00
|
|
|
<component
|
|
|
|
v-bind="$attrs"
|
|
|
|
:is="is"
|
|
|
|
ref="el"
|
2024-10-21 10:00:51 +01:00
|
|
|
:type="type"
|
2023-01-31 03:43:12 +00:00
|
|
|
w-full
|
2022-11-29 08:15:05 +00:00
|
|
|
flex gap-3 items-center cursor-pointer px4 py3
|
2023-01-16 20:17:47 +00:00
|
|
|
select-none
|
2022-11-29 08:15:05 +00:00
|
|
|
hover-bg-active
|
2022-11-30 13:00:54 +00:00
|
|
|
:aria-label="text"
|
2022-11-24 09:15:58 +00:00
|
|
|
@click="handleClick"
|
|
|
|
>
|
2022-11-24 08:34:05 +00:00
|
|
|
<div v-if="icon" :class="icon" />
|
2022-11-24 09:15:58 +00:00
|
|
|
<div flex="~ col">
|
2022-11-26 05:05:44 +00:00
|
|
|
<div text-15px>
|
2022-11-29 08:15:05 +00:00
|
|
|
<slot>
|
|
|
|
{{ text }}
|
|
|
|
</slot>
|
2022-11-24 09:15:58 +00:00
|
|
|
</div>
|
2022-11-26 20:41:18 +00:00
|
|
|
<div text-3 text-secondary>
|
2022-11-24 09:15:58 +00: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 12:58:10 +00:00
|
|
|
<slot name="actions" />
|
2023-01-22 09:57:30 +00:00
|
|
|
</component>
|
2022-11-24 08:34:05 +00:00
|
|
|
</template>
|