Submit.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <v-btn
  3. class="mr-4 theme-primary"
  4. :class="hasOtherActions ? 'pr-0' : ''"
  5. @click="submitAction(mainAction)"
  6. ref="mainBtn"
  7. :disabled="validationPending"
  8. >
  9. {{ $t(mainAction) }}
  10. <v-divider class="ml-3" :vertical="true" v-if="hasOtherActions"></v-divider>
  11. <v-menu
  12. :top="dropDirection === 'top'"
  13. offset-y
  14. left
  15. v-if="hasOtherActions"
  16. :nudge-top="dropDirection === 'top' ? 6 : 0"
  17. :nudge-bottom="dropDirection === 'bottom' ? 6 : 0"
  18. >
  19. <template #activator="{ on, attrs }">
  20. <v-toolbar-title v-on="on">
  21. <v-icon class="pl-3 pr-3">
  22. {{
  23. dropDirection === 'top' ? 'fa fa-caret-up' : 'fa fa-caret-down'
  24. }}
  25. </v-icon>
  26. </v-toolbar-title>
  27. </template>
  28. <v-list :min-width="menuSize">
  29. <v-list-item
  30. dense
  31. v-for="(action, index) in actions"
  32. :key="index"
  33. class="subAction"
  34. v-if="index > 0"
  35. >
  36. <v-list-item-title
  37. v-text="$t(action)"
  38. @click="submitAction(action)"
  39. />
  40. </v-list-item>
  41. </v-list>
  42. </v-menu>
  43. </v-btn>
  44. </template>
  45. <script setup lang="ts">
  46. import { computed, ref } from '@vue/reactivity'
  47. import type { ComputedRef, Ref } from '@vue/reactivity'
  48. const props = defineProps({
  49. actions: {
  50. type: Array,
  51. required: true,
  52. },
  53. dropDirection: {
  54. type: String,
  55. required: false,
  56. default: 'bottom',
  57. },
  58. validationPending: {
  59. type: Boolean,
  60. required: false,
  61. default: false,
  62. },
  63. })
  64. const emit = defineEmits(['submit'])
  65. const mainBtn: Ref = ref(null)
  66. const menuSize = computed(() => {
  67. // Btn size + 40px de padding
  68. return mainBtn.value?.$el.clientWidth + 40
  69. })
  70. const submitAction = (action: string) => {
  71. emit('submit', action)
  72. }
  73. const mainAction: ComputedRef<string> = computed(() => {
  74. return props.actions[0] as string
  75. })
  76. const hasOtherActions: ComputedRef<boolean> = computed(() => {
  77. return props.actions.length > 1
  78. })
  79. </script>
  80. <style scoped>
  81. .v-list-item--dense {
  82. min-height: 25px;
  83. }
  84. .subAction {
  85. cursor: pointer;
  86. }
  87. </style>