Submit.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. {{ dropDirection === 'top' ? 'fa fa-caret-up' : 'fa fa-caret-down'}}
  23. </v-icon>
  24. </v-toolbar-title>
  25. </template>
  26. <v-list
  27. :min-width="menuSize"
  28. >
  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 v-text="$t(action)" @click="submitAction(action)" />
  37. </v-list-item>
  38. </v-list>
  39. </v-menu>
  40. </v-btn>
  41. </template>
  42. <script setup lang="ts">
  43. import {computed, ref} from "@vue/reactivity";
  44. import type {ComputedRef, Ref} from "@vue/reactivity";
  45. const props = defineProps({
  46. actions: {
  47. type: Array,
  48. required: true
  49. },
  50. dropDirection: {
  51. type: String,
  52. required: false,
  53. default:'bottom'
  54. },
  55. validationPending: {
  56. type: Boolean,
  57. required: false,
  58. default: false
  59. }
  60. })
  61. const emit = defineEmits(['submit'])
  62. const mainBtn: Ref = ref(null)
  63. const menuSize = computed(()=>{
  64. // Btn size + 40px de padding
  65. return mainBtn.value?.$el.clientWidth + 40
  66. })
  67. const submitAction = (action: string) => {
  68. emit('submit', action)
  69. }
  70. const mainAction: ComputedRef<string> = computed(()=>{
  71. return props.actions[0] as string
  72. })
  73. const hasOtherActions: ComputedRef<boolean> = computed(()=>{
  74. return props.actions.length > 1
  75. })
  76. </script>
  77. <style scoped>
  78. .v-list-item--dense{
  79. min-height: 25px;
  80. }
  81. .subAction{
  82. cursor: pointer;
  83. }
  84. </style>