Submit.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <v-btn class="mr-4 ot_green ot_white--text" :class="otherActions ? 'pr-0' : ''" @click="onClick(mainAction)" ref="mainBtn">
  3. {{ $t(mainAction) }}
  4. <v-divider class="ml-3" vertical v-if="otherActions"></v-divider>
  5. <v-menu
  6. :top="dropDirection==='top'"
  7. offset-y
  8. left
  9. v-if="otherActions"
  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="onClick(action)" />
  31. </v-list-item>
  32. </v-list>
  33. </v-menu>
  34. </v-btn>
  35. </template>
  36. <script lang="ts">
  37. import {computed, ComputedRef, defineComponent, ref, Ref} from "@nuxtjs/composition-api";
  38. export default defineComponent({
  39. props: {
  40. actions: {
  41. type: Array,
  42. required: true
  43. },
  44. dropDirection: {
  45. type: String,
  46. required: false,
  47. default:'bottom'
  48. }
  49. },
  50. setup(props, {emit}) {
  51. const mainBtn:Ref<any> = ref(null)
  52. const menuSize = computed(()=>{
  53. //Btn size + 40px de padding
  54. return mainBtn.value?.$el.clientWidth + 40
  55. })
  56. const onClick = (action: string) => {
  57. emit('submit', action)
  58. }
  59. const mainAction:ComputedRef<any> = computed(()=>{
  60. return props.actions[0] as string
  61. })
  62. const otherActions:ComputedRef<boolean> = computed(()=>{
  63. return props.actions.length > 1
  64. })
  65. return{
  66. mainBtn,
  67. menuSize,
  68. onClick,
  69. mainAction,
  70. otherActions
  71. }
  72. }
  73. })
  74. </script>
  75. <style scoped>
  76. .v-list-item--dense{
  77. min-height: 25px;
  78. }
  79. .subAction{
  80. cursor: pointer;
  81. }
  82. </style>