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