ruoyi-plus-soybean/src/components/custom/button-icon.vue

59 lines
1.4 KiB
Vue
Raw Normal View History

2023-11-17 08:45:00 +08:00
<script setup lang="ts">
2025-04-23 16:02:41 +08:00
import { computed, useAttrs } from 'vue';
2024-09-03 12:19:57 +08:00
import type { ButtonProps, PopoverPlacement } from 'naive-ui';
import { twMerge } from 'tailwind-merge';
2023-11-17 08:45:00 +08:00
defineOptions({
name: 'ButtonIcon',
inheritAttrs: false
});
2023-12-14 21:45:29 +08:00
interface Props {
/** Button class */
class?: string;
/** Iconify icon name */
icon?: string;
/** Tooltip content */
tooltipContent?: string;
/** Tooltip placement */
tooltipPlacement?: PopoverPlacement;
zIndex?: number;
2024-09-03 12:19:57 +08:00
quaternary?: boolean;
[key: string]: any;
2023-12-14 21:45:29 +08:00
}
const props = withDefaults(defineProps<Props>(), {
class: '',
icon: '',
tooltipContent: '',
tooltipPlacement: 'bottom',
2024-09-03 12:19:57 +08:00
zIndex: 98,
quaternary: true
});
const DEFAULT_CLASS = 'h-[36px] text-icon';
2024-09-03 12:19:57 +08:00
const attrs: ButtonProps = useAttrs();
const quaternary = computed(() => {
return !(attrs.text || attrs.dashed || attrs.ghost) && props.quaternary;
});
2023-11-17 08:45:00 +08:00
</script>
<template>
<NTooltip :placement="tooltipPlacement" :z-index="zIndex" :disabled="!tooltipContent">
2023-11-17 08:45:00 +08:00
<template #trigger>
2024-09-03 12:19:57 +08:00
<NButton :quaternary="quaternary" :class="twMerge(DEFAULT_CLASS, props.class)" :focusable="false" v-bind="attrs">
<div class="flex-center gap-8px">
<slot>
<SvgIcon :icon="icon" />
</slot>
</div>
</NButton>
2023-11-17 08:45:00 +08:00
</template>
{{ tooltipContent }}
</NTooltip>
</template>
<style scoped></style>