1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-13 20:39:58 +00:00
elk/components/status/StatusActionButton.vue
Chris f15bddff67
fix: hidden unnecessary dom render (#310)
Co-authored-by: 三咲智子 Kevin Deng <sxzz@sxzz.moe>
2022-12-03 13:28:32 +08:00

69 lines
1.6 KiB
Vue

<script setup lang="ts">
const props = defineProps<{
text?: string | number
content: string
color: string
icon: string
activeIcon?: string
hover: string
groupHover: string
active?: boolean
disabled?: boolean
as?: string
command?: boolean
}>()
defineOptions({
inheritAttrs: false,
})
const el = ref<HTMLDivElement>()
useCommand({
scope: 'Actions',
order: -2,
visible: () => props.command && !props.disabled,
name: () => props.content,
icon: () => props.icon,
onActivate() {
if (!checkLogin())
return
const clickEvent = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true,
})
el.value?.dispatchEvent(clickEvent)
},
})
</script>
<template>
<component
:is="as || 'button'"
v-bind="$attrs" ref="el"
w-fit flex gap-1 items-center
rounded group :hover="hover"
focus:outline-none cursor-pointer
:focus-visible="hover"
:class="active ? [color] : 'text-secondary'"
:aria-label="content"
>
<CommonTooltip placement="bottom" :content="content">
<div rounded-full p2 :group-hover="groupHover" :group-focus-visible="groupHover" group-focus-visible:ring="2 current">
<div :class="[active && activeIcon ? activeIcon : icon, { 'pointer-events-none': disabled }]" />
</div>
</CommonTooltip>
<CommonAnimateNumber v-if="text !== undefined" :increased="active" text-sm>
<span text-secondary-light>{{ text }}</span>
<template #next>
<span :class="[color]">{{ text }}</span>
</template>
</CommonAnimateNumber>
</component>
</template>