You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MenuItem.vue 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div class="item" :class="cssClass" @click="click">
  3. <!-- Icon -->
  4. <slot name="icon">
  5. <div v-if="icon" class="item__icon">
  6. <img v-if="isImageIcon" :src="icon">
  7. <font-awesome-icon v-else :icon="icon" />
  8. </div>
  9. </slot>
  10. <!-- Title & Description -->
  11. <div v-if="label" class="item__label">
  12. <div class="item__title">
  13. <span v-html="label" />
  14. <AppTip v-if="tooltip" :tooltip="prettyTooltip" />
  15. </div>
  16. <slot name="description">
  17. <span v-if="description" class="item__description" v-html="description" />
  18. </slot>
  19. </div>
  20. <!-- Action -->
  21. <div v-if="$slots.default" class="item__action" :class="actionClass">
  22. <slot />
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. import { isNil, startsWith } from 'lodash'
  28. import MarkdownIt from 'markdown-it'
  29. import { dreamtrack } from '~/modules/services'
  30. const md = new MarkdownIt()
  31. const { shell } = $provider.api
  32. export default {
  33. props: {
  34. icon: {
  35. type: [String, Array],
  36. default: undefined,
  37. },
  38. label: {
  39. type: String,
  40. default: undefined,
  41. },
  42. description: {
  43. type: String,
  44. default: undefined,
  45. },
  46. tooltip: {
  47. type: String,
  48. default: undefined,
  49. },
  50. href: {
  51. type: String,
  52. default: undefined,
  53. },
  54. isLink: {
  55. type: Boolean,
  56. default: false,
  57. },
  58. actionClass: {
  59. type: [String, Object, Array],
  60. default: '',
  61. },
  62. },
  63. computed: {
  64. hasIcon() {
  65. return !isNil(this.icon) || !isNil(this.$slots.icon)
  66. },
  67. isImageIcon() {
  68. return startsWith(this.icon, 'http') || startsWith(this.icon, '/')
  69. },
  70. cssClass() {
  71. return {
  72. 'item--link': !isNil(this.href) || this.isLink,
  73. }
  74. },
  75. prettyTooltip() {
  76. return md.render(this.tooltip)
  77. },
  78. },
  79. methods: {
  80. click() {
  81. this.$emit('click')
  82. if (!isNil(this.href)) {
  83. if (startsWith(this.href, '/')) {
  84. this.$router.push(this.href)
  85. } else {
  86. dreamtrack.track('CLICK_LINK', { href: this.href })
  87. shell.openExternal(this.href)
  88. }
  89. }
  90. },
  91. },
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. .item {
  96. @apply flex items-center;
  97. @include transition('background-color');
  98. min-height: 50px;
  99. &:not(:last-child) {
  100. @apply mb-6;
  101. }
  102. &.item--active,
  103. &.item--link:hover {
  104. @apply bg-menus-light text-white;
  105. .item__icon, .item__title {
  106. @apply text-generic-500;
  107. }
  108. }
  109. &.item--link {
  110. @apply rounded cursor-pointer;
  111. @include transition('background-color, color');
  112. }
  113. }
  114. .item__icon {
  115. @apply mr-2 flex items-center justify-center;
  116. @apply text-2xl text-generic-500;
  117. width: 42px;
  118. min-width: 42px;
  119. img {
  120. width: 24px;
  121. height: 24px;
  122. }
  123. }
  124. .item__label {
  125. @apply flex-1 flex flex-col justify-center;
  126. @apply text-common;
  127. &:not(:last-child) {
  128. @apply mr-6;
  129. }
  130. .item__title {
  131. @apply block font-semibold;
  132. }
  133. &::v-deep {
  134. .tip {
  135. @apply ml-1;
  136. }
  137. }
  138. .item__description {
  139. @apply block text-xs text-common-dark;
  140. }
  141. }
  142. .item__action {
  143. @apply flex-1;
  144. &.item__action--center {
  145. @apply flex justify-center items-center;
  146. }
  147. }
  148. </style>