icon.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <i class="iconfont ui-kankan-icon icon" :class="className" :style="style" @click="ev => emit('click', ev)">
  3. <slot></slot>
  4. <p class="tip" v-if="tip && os.isPc && !os.isTablet">{{ tip }}</p>
  5. </i>
  6. </template>
  7. <script lang="ts" setup>
  8. import { defineProps, computed, defineEmits } from 'vue'
  9. import { normalizeUnitToStyle, os } from '@kankan/utils'
  10. import { iconProps } from './icon'
  11. const props = defineProps(iconProps)
  12. const style = computed(() => ({
  13. 'font-size': normalizeUnitToStyle(props.size),
  14. color: props.color,
  15. }))
  16. const className = computed(() => {
  17. const base = {
  18. small: props.small,
  19. medium: props.medium,
  20. big: props.big,
  21. disabled: props.disabled,
  22. [`tip-h-` + props.tipH]: true,
  23. [`tip-v-` + props.tipV]: true,
  24. ['fun-ctrl']: props.ctrl,
  25. }
  26. if (props.type) {
  27. return {
  28. ...base,
  29. [`icon-${props.type}`]: props.type,
  30. }
  31. } else {
  32. return base
  33. }
  34. })
  35. const emit = defineEmits(['click'])
  36. // defineOptions({
  37. // name: 'UIIcon',
  38. // });
  39. </script>
  40. <style>
  41. /* @import url('./iconfont/iconfont.css'); */
  42. </style>