icon.vue 1.1 KB

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