2022-11-24 13:04:20 +08:00
|
|
|
<script setup lang="ts">
|
2023-07-02 16:26:23 +00:00
|
|
|
defineOptions({
|
|
|
|
inheritAttrs: false,
|
|
|
|
})
|
|
|
|
|
2023-01-08 21:24:59 +08:00
|
|
|
const { as = 'button', command, disabled, content, icon } = defineProps<{
|
2022-11-24 13:04:20 +08:00
|
|
|
text?: string | number
|
2022-11-27 16:11:34 +01:00
|
|
|
content: string
|
2022-11-24 13:04:20 +08:00
|
|
|
color: string
|
|
|
|
icon: string
|
2022-11-24 16:34:05 +08:00
|
|
|
activeIcon?: string
|
2023-08-11 04:56:47 -07:00
|
|
|
inactiveIcon?: string
|
2022-11-24 13:04:20 +08:00
|
|
|
hover: string
|
2023-03-19 20:24:27 +08:00
|
|
|
elkGroupHover: string
|
2022-11-24 13:04:20 +08:00
|
|
|
active?: boolean
|
|
|
|
disabled?: boolean
|
2022-11-25 18:46:25 -05:00
|
|
|
as?: string
|
2022-11-29 16:15:05 +08:00
|
|
|
command?: boolean
|
2022-11-24 13:04:20 +08:00
|
|
|
}>()
|
|
|
|
|
2023-01-01 22:45:46 +01:00
|
|
|
defineSlots<{
|
2023-08-02 10:28:18 +00:00
|
|
|
text: (props: object) => void
|
2023-01-01 22:45:46 +01:00
|
|
|
}>()
|
|
|
|
|
2022-11-29 16:15:05 +08:00
|
|
|
const el = ref<HTMLDivElement>()
|
|
|
|
|
|
|
|
useCommand({
|
|
|
|
scope: 'Actions',
|
|
|
|
|
|
|
|
order: -2,
|
2023-01-08 21:24:59 +08:00
|
|
|
visible: () => command && !disabled,
|
2022-11-29 16:15:05 +08:00
|
|
|
|
2023-01-08 21:24:59 +08:00
|
|
|
name: () => content,
|
|
|
|
icon: () => icon,
|
2022-11-29 16:15:05 +08:00
|
|
|
|
|
|
|
onActivate() {
|
2022-12-02 10:18:57 +08:00
|
|
|
if (!checkLogin())
|
|
|
|
return
|
2022-11-29 16:15:05 +08:00
|
|
|
const clickEvent = new MouseEvent('click', {
|
|
|
|
view: window,
|
|
|
|
bubbles: true,
|
|
|
|
cancelable: true,
|
|
|
|
})
|
|
|
|
el.value?.dispatchEvent(clickEvent)
|
|
|
|
},
|
|
|
|
})
|
2022-11-24 13:04:20 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-25 18:46:25 -05:00
|
|
|
<component
|
2023-01-08 21:24:59 +08:00
|
|
|
:is="as"
|
2022-11-29 16:15:05 +08:00
|
|
|
v-bind="$attrs" ref="el"
|
2023-01-28 14:17:26 -08:00
|
|
|
w-fit flex gap-1 items-center transition-all select-none
|
2023-01-08 21:24:59 +08:00
|
|
|
rounded group
|
|
|
|
:hover=" !disabled ? hover : undefined"
|
|
|
|
focus:outline-none
|
2022-11-29 16:15:05 +08:00
|
|
|
:focus-visible="hover"
|
2023-08-11 04:56:47 -07:00
|
|
|
:class="active ? color : (disabled ? 'op25 pointer-events-none' : 'text-secondary')"
|
2022-11-30 21:00:54 +08:00
|
|
|
:aria-label="content"
|
2023-01-08 21:24:59 +08:00
|
|
|
:disabled="disabled"
|
2022-11-24 16:34:05 +08:00
|
|
|
>
|
2022-11-27 16:11:34 +01:00
|
|
|
<CommonTooltip placement="bottom" :content="content">
|
2023-01-08 21:24:59 +08:00
|
|
|
<div
|
|
|
|
rounded-full p2
|
|
|
|
v-bind="disabled ? {} : {
|
2023-03-19 20:24:27 +08:00
|
|
|
'elk-group-hover': elkGroupHover,
|
|
|
|
'group-focus-visible': elkGroupHover,
|
2023-01-08 21:24:59 +08:00
|
|
|
'group-focus-visible:ring': '2 current',
|
|
|
|
}"
|
|
|
|
>
|
2023-08-11 04:56:47 -07:00
|
|
|
<div :class="active && activeIcon ? activeIcon : (disabled ? inactiveIcon : icon)" />
|
2022-11-27 16:11:34 +01:00
|
|
|
</div>
|
|
|
|
</CommonTooltip>
|
2022-11-24 13:04:20 +08:00
|
|
|
|
2023-01-01 22:45:46 +01:00
|
|
|
<CommonAnimateNumber v-if="text !== undefined || $slots.text" :increased="active" text-sm>
|
|
|
|
<span text-secondary-light>
|
|
|
|
<slot name="text">{{ text }}</slot>
|
|
|
|
</span>
|
2022-11-30 14:21:11 +08:00
|
|
|
<template #next>
|
2023-01-01 22:45:46 +01:00
|
|
|
<span :class="[color]">
|
|
|
|
<slot name="text">{{ text }}</slot>
|
|
|
|
</span>
|
2022-11-30 14:21:11 +08:00
|
|
|
</template>
|
|
|
|
</CommonAnimateNumber>
|
2022-11-25 18:46:25 -05:00
|
|
|
</component>
|
2022-11-24 13:04:20 +08:00
|
|
|
</template>
|