Card.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <!--
  2. VCard proposant une option dans la boite de dialogue "Assistant de création"
  3. La carte peut prendre en paramètres des options `to` et `href` :
  4. Si `to` est défini et pas `href`, la carte mène simplement à un nouveau menu dans le wizard.
  5. Si `href` est défini, et pas `to`, la carte se comporte comme un lien, et doit rediriger la page vers `href` au clic.
  6. Enfin, si les deux sont définis, l'url est envoyée au composant parent pour être mémorisée, et la carte mène ensuite à
  7. un nouveau menu dans le wizard, qui permettra d'affiner l'url, par exemple en lui ajoutant une query.
  8. -->
  9. <template>
  10. <v-card
  11. class="col-md-6"
  12. color=""
  13. :flat="true"
  14. border="solid 1px"
  15. @click="onClick"
  16. >
  17. <v-row :no-gutters="true" :style="mdAndUp ? 'height: 100px' : ''">
  18. <v-col cols="3" class="flex-grow-0 flex-shrink-0 d-flex justify-center">
  19. <v-icon
  20. :icon="icon"
  21. size="50"
  22. class="ma-2 pa-2 align-self-center text-neutral-strong"
  23. />
  24. </v-col>
  25. <v-col
  26. cols="9"
  27. align-self="center"
  28. class="pl-2 infos-container flex-grow-1 flex-shrink-1"
  29. >
  30. <h4 class="text-primary">
  31. {{ $t(title) }}
  32. </h4>
  33. <p class="text-neutral-strong">
  34. {{ $t(textContent) }}
  35. </p>
  36. </v-col>
  37. </v-row>
  38. </v-card>
  39. </template>
  40. <script setup lang="ts">
  41. import type { PropType } from 'vue'
  42. import { useDisplay } from 'vuetify'
  43. import { MENU_LINK_TYPE } from '~/types/enum/layout'
  44. import { useAdminUrl } from '~/composables/utils/useAdminUrl'
  45. import UrlUtils from '~/services/utils/urlUtils'
  46. const props = defineProps({
  47. /**
  48. * Target location in the wizard
  49. */
  50. to: {
  51. type: String,
  52. required: false,
  53. default: null,
  54. },
  55. /**
  56. * Target url
  57. */
  58. href: {
  59. type: String,
  60. required: false,
  61. default: null,
  62. },
  63. /**
  64. * Target url
  65. */
  66. linkType: {
  67. type: Number as PropType<MENU_LINK_TYPE>,
  68. required: false,
  69. default: MENU_LINK_TYPE.V1,
  70. },
  71. /**
  72. * Title displayed on the card
  73. */
  74. title: {
  75. type: String,
  76. required: true,
  77. },
  78. /**
  79. * Description displayed on the card
  80. */
  81. textContent: {
  82. type: String,
  83. required: true,
  84. },
  85. /**
  86. * Icon displayed on the card
  87. */
  88. icon: {
  89. type: String,
  90. required: true,
  91. },
  92. })
  93. const emit = defineEmits(['click'])
  94. const { makeAdminUrl } = useAdminUrl()
  95. const { mdAndUp } = useDisplay()
  96. let url: string | null = null
  97. if (props.href !== null) {
  98. switch (props.linkType) {
  99. case MENU_LINK_TYPE.V1:
  100. url = makeAdminUrl(props.href)
  101. break
  102. case MENU_LINK_TYPE.EXTERNAL:
  103. url = UrlUtils.prependHttps(props.href)
  104. break
  105. default:
  106. url = props.href
  107. }
  108. }
  109. const onClick = () => {
  110. emit('click', props.to, url)
  111. }
  112. </script>
  113. <style lang="scss" scoped>
  114. h4 {
  115. font-size: 15px;
  116. font-weight: bold;
  117. margin-bottom: 6px;
  118. }
  119. p {
  120. font-size: 13px;
  121. }
  122. .infos-container {
  123. padding: 15px 0;
  124. }
  125. .v-card:hover {
  126. cursor: pointer;
  127. background: rgb(var(--v-theme-primary-alt));
  128. }
  129. </style>