mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-09-29 22:56:41 +08:00
optimize(components): use tailwind-merge for smarter class merging
This commit is contained in:
parent
ce3ccd473a
commit
d965142579
@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue';
|
|
||||||
import { createReusableTemplate } from '@vueuse/core';
|
import { createReusableTemplate } from '@vueuse/core';
|
||||||
import type { PopoverPlacement } from 'naive-ui';
|
import type { PopoverPlacement } from 'naive-ui';
|
||||||
|
import { twMerge } from 'tailwind-merge';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'ButtonIcon',
|
name: 'ButtonIcon',
|
||||||
@ -21,38 +21,22 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
class: 'h-36px text-icon',
|
class: '',
|
||||||
icon: '',
|
icon: '',
|
||||||
tooltipContent: '',
|
tooltipContent: '',
|
||||||
tooltipPlacement: 'bottom',
|
tooltipPlacement: 'bottom',
|
||||||
zIndex: 98
|
zIndex: 98
|
||||||
});
|
});
|
||||||
|
|
||||||
interface ButtonProps {
|
const [DefineButton, Button] = createReusableTemplate();
|
||||||
className: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [DefineButton, Button] = createReusableTemplate<ButtonProps>();
|
const DEFAULT_CLASS = 'h-[36px] text-icon';
|
||||||
|
|
||||||
const cls = computed(() => {
|
|
||||||
let clsStr = props.class;
|
|
||||||
|
|
||||||
if (!clsStr.includes('h-')) {
|
|
||||||
clsStr += ' h-36px';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!clsStr.includes('text-')) {
|
|
||||||
clsStr += ' text-icon';
|
|
||||||
}
|
|
||||||
|
|
||||||
return clsStr;
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<!-- define component start: Button -->
|
<!-- define component start: Button -->
|
||||||
<DefineButton v-slot="{ $slots, className }">
|
<DefineButton v-slot="{ $slots }">
|
||||||
<NButton quaternary :class="className">
|
<NButton quaternary :class="twMerge(DEFAULT_CLASS, props.class)" v-bind="$attrs">
|
||||||
<div class="flex-center gap-8px">
|
<div class="flex-center gap-8px">
|
||||||
<component :is="$slots.default" />
|
<component :is="$slots.default" />
|
||||||
</div>
|
</div>
|
||||||
@ -62,7 +46,7 @@ const cls = computed(() => {
|
|||||||
|
|
||||||
<NTooltip v-if="tooltipContent" :placement="tooltipPlacement" :z-index="zIndex">
|
<NTooltip v-if="tooltipContent" :placement="tooltipPlacement" :z-index="zIndex">
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<Button :class-name="cls" v-bind="$attrs">
|
<Button>
|
||||||
<slot>
|
<slot>
|
||||||
<SvgIcon :icon="icon" />
|
<SvgIcon :icon="icon" />
|
||||||
</slot>
|
</slot>
|
||||||
@ -70,7 +54,7 @@ const cls = computed(() => {
|
|||||||
</template>
|
</template>
|
||||||
{{ tooltipContent }}
|
{{ tooltipContent }}
|
||||||
</NTooltip>
|
</NTooltip>
|
||||||
<Button v-else :class-name="cls" v-bind="$attrs">
|
<Button v-else>
|
||||||
<slot>
|
<slot>
|
||||||
<SvgIcon :icon="icon" />
|
<SvgIcon :icon="icon" />
|
||||||
</slot>
|
</slot>
|
||||||
|
Loading…
Reference in New Issue
Block a user