MenuItem.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <div
  3. class="flex flex-col justify-center items-center w-50px h-50px cursor-pointer mr-10px hover:bg-bg-tertiary rounded-4px"
  4. :class="disabled ? 'cursor-not-allowed text-text-secondary' : 'pointer-cursor'"
  5. @click="handleClick(item)"
  6. >
  7. <div class="w-30px h-30px flex items-center justify-center">
  8. <img
  9. v-if="typeof item.img === 'string'"
  10. :src="item.img"
  11. class="w-24px h-24px"
  12. :alt="item.label"
  13. />
  14. <component v-else :is="item.img" size="20px"></component>
  15. </div>
  16. <div class="text-12px">{{ item.label }}</div>
  17. </div>
  18. </template>
  19. <script setup lang="ts">
  20. import type { VNode } from 'vue'
  21. import { defineEmits, defineProps } from 'vue'
  22. const props = defineProps<{
  23. item: {
  24. key: string
  25. label: string
  26. img: string | VNode
  27. }
  28. disabled?: boolean
  29. onClick?: (item: { key: string; label: string; img: string | VNode }) => void
  30. }>()
  31. const emit = defineEmits<{
  32. (e: 'click', item: { key: string; label: string; img: string | VNode }): void
  33. }>()
  34. function handleClick(item: { key: string; label: string; img: string | VNode }) {
  35. if (props.disabled) return
  36. emit('click', item)
  37. }
  38. </script>
  39. <style scoped></style>