ActionMenu.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <!--
  2. Menu d'actions rapides (appel, contact, ...), qui reste accroché au bord droit
  3. de l'écran (ou au bas de l'écran sur les petits écrans)
  4. -->
  5. <template>
  6. <div v-show="showMenu">
  7. <!-- Écrans larges : menu lateral, accroché au bord droit de l'écran -->
  8. <div v-if="lgAndUp && isVisible" class="sticky-menu lateral">
  9. <v-row
  10. v-for="(action, index) in actionsOrDefault"
  11. :key="index"
  12. :class="['square', action.color]"
  13. @click="() => onActionClick(action)"
  14. >
  15. <NuxtLink class="link">
  16. <div>
  17. <v-icon :class="action.icon" />
  18. <p class="text-square mt-2">
  19. {{ action.text }}
  20. </p>
  21. </div>
  22. </NuxtLink>
  23. </v-row>
  24. </div>
  25. <!-- Petits écrans : menu sous forme de bandeau en pied de page (sauf si le footer du site est visible) -->
  26. <div v-else-if="isVisible" class="sticky-menu band">
  27. <v-btn
  28. v-for="(action, index) in actionsOrDefault"
  29. :key="index"
  30. :class="[action.color]"
  31. @click="() => onActionClick(action)"
  32. >
  33. <span v-if="mdAndUp">{{ action.text }}</span>
  34. <v-icon v-else :aria-label="action.text">{{ action.icon }}</v-icon>
  35. </v-btn>
  36. </div>
  37. <v-btn
  38. v-if="isVisible"
  39. :to="{ path: '', hash: '#top' }"
  40. aria-label="Revenir en début de page"
  41. class="back-to-the-top secondary"
  42. >
  43. <v-icon>fas fa-arrow-up</v-icon>
  44. </v-btn>
  45. </div>
  46. </template>
  47. <script setup lang="ts">
  48. import { useRouter } from 'vue-router'
  49. import { useDisplay } from 'vuetify'
  50. import type { ComputedRef } from 'vue'
  51. import { useLayoutStore } from '~/stores/layoutStore'
  52. import { ActionMenuItemType } from '~/types/enum/layout'
  53. import type { ActionMenuItem } from '~/types/interface'
  54. const { lgAndUp, mdAndUp } = useDisplay()
  55. const router = useRouter()
  56. const layoutStore = useLayoutStore()
  57. const { isMobileDevice } = useClientDevice()
  58. const telephoneNumber = '04 85 30 04 03'
  59. const isVisible: ComputedRef<boolean> = computed(
  60. () =>
  61. !layoutStore.isHeaderVisible &&
  62. !layoutStore.isBannerVisible &&
  63. !layoutStore.isFooterVisible
  64. )
  65. // Attend l'hydratation avant d'afficher
  66. const showMenu = ref(false)
  67. onNuxtReady(() => {
  68. showMenu.value = true
  69. })
  70. // Actions par défaut du menu, peut-être surchargé via la propriété `actions`
  71. const defaultActions: Array<ActionMenuItem> = [
  72. {
  73. type: ActionMenuItemType.FOLLOW_LINK,
  74. color: 'secondary',
  75. icon: 'far fa-comments',
  76. text: 'Nous contacter',
  77. url: { path: 'nous-contacter', hash: '#form' },
  78. },
  79. {
  80. type: ActionMenuItemType.CALL_US,
  81. color: 'primary',
  82. icon: 'fas fa-phone',
  83. text: 'Nous Appeler',
  84. },
  85. ]
  86. const props = defineProps({
  87. /**
  88. * Actions accessibles via le menu (par défaut : "Nous contacter", "Nous appeler")
  89. */
  90. actions: {
  91. type: Array<ActionMenuItem>,
  92. required: false,
  93. default: [],
  94. },
  95. })
  96. const actionsOrDefault: ComputedRef<Array<ActionMenuItem>> = computed(() => {
  97. return props.actions.length > 0 ? props.actions : defaultActions
  98. })
  99. const callUs = () => {
  100. if (isMobileDevice()) {
  101. window.location.href = `tel:${telephoneNumber}`
  102. } else {
  103. navigateTo({ path: 'nous-contacter', hash: '#details' })
  104. }
  105. }
  106. /**
  107. * On a cliqué sur une des actions du menu
  108. * @param action
  109. */
  110. const onActionClick = (action: ActionMenuItem) => {
  111. switch (action.type) {
  112. case ActionMenuItemType.ASK_FOR_A_DEMO:
  113. router.push({ path: action.url as string, query: { request: 'demo' } })
  114. break
  115. case ActionMenuItemType.CALL_US:
  116. callUs()
  117. break
  118. case ActionMenuItemType.FOLLOW_LINK:
  119. if (!action.url) {
  120. throw new Error('Missing prop : url')
  121. }
  122. navigateTo(action.url, {
  123. open: { target: action.target ? action.target : '_self' },
  124. })
  125. break
  126. default:
  127. throw new Error('Unrecognized action')
  128. }
  129. }
  130. </script>
  131. <style scoped lang="scss">
  132. .sticky-menu {
  133. z-index: 100;
  134. }
  135. // Menu format lateral (pour affichage écrans larges)
  136. .sticky-menu.lateral {
  137. position: fixed;
  138. right: 0;
  139. top: 60%;
  140. transform: translateY(-50%);
  141. float: right;
  142. display: flex;
  143. flex-direction: column;
  144. color: var(--on-primary-color);
  145. font-weight: 500;
  146. font-size: 0.7rem;
  147. line-height: 15px;
  148. text-align: center !important;
  149. letter-spacing: 0.2em;
  150. text-transform: uppercase;
  151. }
  152. // Menu format ruban (pour affichage petits écrans)
  153. .sticky-menu.band {
  154. position: fixed;
  155. height: 46px;
  156. bottom: 0;
  157. width: 100%;
  158. display: flex;
  159. justify-content: center;
  160. background-color: var(--neutral-color);
  161. max-width: 100vw;
  162. padding: 0 6px;
  163. .v-btn {
  164. margin: 6px 2%;
  165. }
  166. }
  167. .square {
  168. position: relative;
  169. width: 7rem;
  170. padding: 1rem;
  171. cursor: pointer;
  172. transition: transform 0.3s ease-in-out;
  173. box-shadow: -1px 2px 6px 1px var(--on-neutral-color-light);
  174. }
  175. .square:hover {
  176. transform: translateX(-10px);
  177. }
  178. .link {
  179. text-decoration: none;
  180. color: var(--on-primary-color);
  181. * {
  182. text-align: center;
  183. }
  184. }
  185. .back-to-the-top {
  186. position: fixed;
  187. right: 12px;
  188. bottom: 58px;
  189. z-index: 100;
  190. height: 48px;
  191. width: 48px;
  192. border-radius: 32px;
  193. }
  194. .primary {
  195. background: var(--action-menu-primary-color);
  196. color: var(--action-menu-on-primary-color);
  197. a {
  198. color: var(--action-menu-on-primary-color);
  199. }
  200. }
  201. .secondary {
  202. background: var(--action-menu-secondary-color);
  203. color: var(--action-menu-on-secondary-color);
  204. a {
  205. color: var(--action-menu-on-secondary-color);
  206. }
  207. }
  208. </style>