<!--
 * @Author: Devin
 * @Date: 2022-11-14 16:48:05
 * @LastEditors: Devin
 * @LastEditTime: 2023-02-22 14:44:32
 * @Description: 公共icon
-->
<template>
  <el-tooltip
    v-if="content"
    class="tooltip"
    :effect="effect"
    :content="content"
    :placement="placement"
  >
    <svg
      class="common-icon"
      :class="svgClass"
      aria-hidden="true"
      :width="size"
      :height="size"
    >
      <use :xlink:href="symbolId" :fill="color" />
    </svg>
  </el-tooltip>
  <svg
    v-else
    class="common-icon"
    :class="svgClass"
    aria-hidden="true"
    :width="size"
    :height="size"
  >
    <use :xlink:href="symbolId" :fill="color" />
  </svg>
</template>

<script setup>
import { computed } from 'vue';

const props = defineProps({
  size: {
    type: Number,
    default: 18
  },
  prefix: {
    type: String,
    default: 'icon'
  },
  name: {
    type: String,
    required: true
  },
  color: {
    type: String,
    default: '#fff'
  },
  content: {
    type: String,
    default: ''
  },
  effect: {
    type: String,
    default: 'dark'
  },
  placement: {
    type: String,
    default: 'top-start'
  }
  // onClick: {
  //   type: Function,
  //   default: () => null
  // }
});
const symbolId = computed(() => `#${props.prefix}-${props.name}`);
const svgClass = computed(() => {
  if (props.className) {
    return `common-icon ${props.className}`;
  }
  return 'common-icon';
});
// const emits = defineEmits(['onClick']);

// function onClick() {
//   debugger;
//   emits('onClick');
// }
</script>

<script>
export default {
  name: 'CommonIcon'
};
</script>

<style scoped>
.common-icon {
  vertical-align: -0.1em; /* 因icon大小被设置为和字体大小一致，而span等标签的下边缘会和字体的基线对齐，故需设置一个往下的偏移比例，来纠正视觉上的未对齐效果 */
  fill: currentColor; /* 定义元素的颜色，currentColor是一个变量，这个变量的值就表示当前元素的color值，如果当前元素未设置color值，则从父元素继承 */
  overflow: hidden;
  cursor: pointer;
}
.tooltip {
  width: 100%;
  height: 100%;
  cursor: pointer;
}
</style>
