Submit.vue 2.1 KB

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