Submit.vue 2.0 KB

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