CommonFlyoutActionFooter.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import CommonButton, {
  4. type Props as ButtonProps,
  5. } from '#desktop/components/CommonButton/CommonButton.vue'
  6. import { useForm } from '#shared/components/Form/useForm.ts'
  7. import { toRef } from 'vue'
  8. import type { FormRef } from '#shared/components/Form/types.ts'
  9. export interface Props {
  10. hideActionButton?: boolean
  11. actionLabel?: string
  12. actionButton?: Pick<
  13. ButtonProps,
  14. 'prefixIcon' | 'variant' | 'type' | 'disabled'
  15. >
  16. cancelLabel?: string
  17. cancelButton?: Pick<ButtonProps, 'prefixIcon' | 'variant' | 'disabled'>
  18. form?: FormRef
  19. }
  20. const props = withDefaults(defineProps<Props>(), {
  21. actionLabel: __('Update'),
  22. cancelLabel: __('Cancel & Go Back'),
  23. })
  24. const emit = defineEmits<{
  25. cancel: []
  26. action: []
  27. }>()
  28. // ** Form // **
  29. const { isDisabled, formNodeId } = useForm(toRef(props, 'form'))
  30. const cancel = () => {
  31. emit('cancel')
  32. }
  33. const execute = () => {
  34. emit('action')
  35. }
  36. </script>
  37. <template>
  38. <div class="flex items-center justify-end gap-2">
  39. <CommonButton
  40. size="large"
  41. :disabled="isDisabled || cancelButton?.disabled"
  42. :prefix-icon="cancelButton?.prefixIcon"
  43. :variant="cancelButton?.variant || 'secondary'"
  44. @click="cancel()"
  45. >
  46. {{ $t(cancelLabel) }}
  47. </CommonButton>
  48. <CommonButton
  49. v-if="!hideActionButton"
  50. size="large"
  51. :disabled="isDisabled || actionButton?.disabled"
  52. :form="formNodeId"
  53. :type="actionButton?.type"
  54. :prefix-icon="actionButton?.prefixIcon"
  55. :variant="actionButton?.variant || 'submit'"
  56. @click="execute()"
  57. >
  58. {{ $t(actionLabel) }}
  59. </CommonButton>
  60. </div>
  61. </template>