<!-- 
按钮组件

add by RYG
-->
<template>
  <el-button class="image-button" v-bind="$attrs" :size="btnSize" @click="handleClick">
    <div class="content-wrapper">
      <img :src="imageUrl" :alt="altText" class="image" />
      <span class="text">{{ text }}</span>
    </div>
  </el-button>
</template>

<script setup>
import { ElButton } from "element-plus";

const props = defineProps({
  imageUrl: {
    type: String,
    required: true,
  },
  btnSize: {
    type: String,
    default: "default", // 可选值：'large', 'default', 'small', 'mini'
  },
  text: {
    type: String,
    default: "按钮",
  },
  altText: {
    type: String,
    default: "按钮图片",
  },
});

const emit = defineEmits(["click"]);

const handleClick = () => {
  emit("click");
};
</script>

<style scoped>
.image-button {
  /* 重置按钮内边距，以便自定义内容布局 */
  padding: 5px;
  border: none;
  background-color: transparent;
}

.image-button:hover {
  background-color: lightblue; /* 鼠标悬停时的背景色 */
}

.image-button:focus {
  background-color: lightseagreen;
}

.content-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px; /* 图片和文字之间的间距 */
}

.image {
  width: 18px; /* 可根据需要调整 */
  height: 18px; /* 可根据需要调整 */
  object-fit: contain; /* 保持图片比例并完整显示 */
}

.text {
  font-size: 12px;
  color: inherit; /* 继承按钮的文字颜色 */
}
</style>
