tiny-rdm/frontend/src/components/common/IconButton.vue

61 lines
1.6 KiB
Vue
Raw Normal View History

2023-06-27 15:53:29 +08:00
<script setup>
import { computed } from 'vue'
import { NIcon } from 'naive-ui'
const emit = defineEmits(['click'])
const props = defineProps({
tooltip: String,
tTooltip: String,
icon: [String, Object],
2023-06-27 15:53:29 +08:00
size: {
type: [Number, String],
default: 20,
},
color: {
type: String,
default: 'currentColor',
},
strokeWidth: {
type: [Number, String],
default: 3,
},
disabled: Boolean,
})
const disableColor = computed(() => {
const baseColor = props.color
const grayScale = Math.round(
0.299 * parseInt(baseColor.substring(1, 2), 16) +
0.587 * parseInt(baseColor.substring(3, 2), 16) +
0.114 * parseInt(baseColor.substring(5, 2), 16)
)
const color = `#${grayScale.toString(16).repeat(3)}`
return color
2023-06-27 15:53:29 +08:00
})
const hasTooltip = computed(() => {
return props.tooltip || props.tTooltip
})
</script>
<template>
<n-tooltip v-if="hasTooltip">
<template #trigger>
<n-button text :disabled="disabled" @click="emit('click')">
<n-icon :size="props.size" :color="props.color">
<component :is="props.icon" :stroke-width="props.strokeWidth" />
</n-icon>
</n-button>
2023-06-27 15:53:29 +08:00
</template>
{{ props.tTooltip ? $t(props.tTooltip) : props.tooltip }}
</n-tooltip>
<n-button v-else text :disabled="disabled" @click="emit('click')">
<n-icon :size="props.size" :color="props.color">
<component :is="props.icon" :stroke-width="props.strokeWidth" />
</n-icon>
</n-button>
2023-06-27 15:53:29 +08:00
</template>
<style lang="scss"></style>