Submit.vue 1.9 KB

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