Submit.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <v-btn v-if="!readonly" 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 v-slot: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 "~/use/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 {readonly} = $useForm()
  53. const mainBtn:Ref<any> = ref(null)
  54. const menuSize = computed(()=>{
  55. //Btn size + 40px de padding
  56. return mainBtn.value?.$el.clientWidth + 40
  57. })
  58. const onClick = (action: string) => {
  59. emit('submit', action)
  60. }
  61. const mainAction:ComputedRef<any> = computed(()=>{
  62. return props.actions[0] as string
  63. })
  64. const otherActions:ComputedRef<boolean> = computed(()=>{
  65. return props.actions.length > 1
  66. })
  67. return{
  68. mainBtn,
  69. menuSize,
  70. readonly,
  71. onClick,
  72. mainAction,
  73. otherActions
  74. }
  75. }
  76. })
  77. </script>
  78. <style scoped>
  79. .v-list-item--dense{
  80. min-height: 25px;
  81. }
  82. .subAction{
  83. cursor: pointer;
  84. }
  85. </style>