2021-09-24 16:26:14 +08:00
|
|
|
<template>
|
|
|
|
<div
|
2021-10-14 18:21:17 +08:00
|
|
|
class="
|
|
|
|
relative
|
|
|
|
flex-center
|
|
|
|
h-30px
|
|
|
|
pl-14px
|
|
|
|
border-1px
|
|
|
|
rounded-2px
|
|
|
|
cursor-pointer
|
|
|
|
border-[#e5e7eb]
|
|
|
|
dark:border-[#ffffff3d]
|
|
|
|
"
|
|
|
|
:class="[closable ? 'pr-6px' : 'pr-14px']"
|
|
|
|
:style="buttonStyle"
|
2021-09-24 16:26:14 +08:00
|
|
|
@mouseenter="setTrue"
|
|
|
|
@mouseleave="setFalse"
|
|
|
|
>
|
|
|
|
<span>
|
|
|
|
<slot></slot>
|
|
|
|
</span>
|
|
|
|
<div v-if="closable" class="pl-10px">
|
2021-10-15 12:02:53 +08:00
|
|
|
<icon-close :is-primary="isActive || isHover" :primary-color="primaryColor" @click="handleClose" />
|
2021-09-24 16:26:14 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2021-10-14 18:21:17 +08:00
|
|
|
import { computed } from 'vue';
|
2021-09-24 16:26:14 +08:00
|
|
|
import { useBoolean } from '@/hooks';
|
|
|
|
import { IconClose } from '@/components';
|
2021-10-14 18:21:17 +08:00
|
|
|
import { shallowColor } from '@/utils';
|
2021-09-24 16:26:14 +08:00
|
|
|
|
2021-10-14 18:21:17 +08:00
|
|
|
const props = defineProps({
|
2021-10-15 12:02:53 +08:00
|
|
|
isActive: {
|
2021-09-24 16:26:14 +08:00
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2021-10-14 18:21:17 +08:00
|
|
|
primaryColor: {
|
|
|
|
type: String,
|
|
|
|
default: '#409EFF'
|
|
|
|
},
|
2021-09-24 16:26:14 +08:00
|
|
|
closable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
2021-10-15 12:02:53 +08:00
|
|
|
},
|
|
|
|
darkMode: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2021-09-24 16:26:14 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
const emit = defineEmits(['close']);
|
|
|
|
|
|
|
|
const { bool: isHover, setTrue, setFalse } = useBoolean();
|
|
|
|
|
|
|
|
function handleClose(e: MouseEvent) {
|
|
|
|
e.stopPropagation();
|
|
|
|
emit('close');
|
|
|
|
}
|
2021-10-14 18:21:17 +08:00
|
|
|
|
|
|
|
const buttonStyle = computed(() => {
|
|
|
|
const style: { [key: string]: string } = {};
|
2021-10-15 12:02:53 +08:00
|
|
|
if (props.isActive || isHover.value) {
|
2021-10-14 18:21:17 +08:00
|
|
|
style.color = props.primaryColor;
|
|
|
|
style.borderColor = shallowColor(props.primaryColor, 0.3);
|
2021-10-15 12:02:53 +08:00
|
|
|
if (props.isActive) {
|
|
|
|
const alpha = props.darkMode ? 0.15 : 0.1;
|
|
|
|
style.backgroundColor = shallowColor(props.primaryColor, alpha);
|
2021-10-14 18:21:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return style;
|
|
|
|
});
|
2021-09-24 16:26:14 +08:00
|
|
|
</script>
|
|
|
|
<style scoped></style>
|