CommonButtonGroup.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import CommonButton from '#desktop/components/CommonButton/CommonButton.vue'
  5. import type { CommonButtonItem } from './types.ts'
  6. export interface Props {
  7. items: CommonButtonItem[]
  8. }
  9. const props = defineProps<Props>()
  10. const filteredItems = computed(() => {
  11. return props.items.filter((item) => !item.hidden)
  12. })
  13. const onButtonClick = (item: CommonButtonItem) => {
  14. if (item.disabled) return
  15. item.onActionClick?.()
  16. }
  17. </script>
  18. <template>
  19. <div class="flex flex-wrap gap-2">
  20. <CommonButton
  21. v-for="item of filteredItems"
  22. :key="item.label"
  23. :variant="item.variant"
  24. :type="item.type"
  25. :size="item.size"
  26. :disabled="item.disabled"
  27. :prefix-icon="item.icon"
  28. :class="[
  29. {
  30. 'opacity-50': item.disabled,
  31. },
  32. ]"
  33. class="basis-full"
  34. @click="onButtonClick(item)"
  35. >
  36. <slot name="item" v-bind="item">
  37. {{ $t(item.label, ...(item.labelPlaceholder || [])) }}
  38. </slot>
  39. </CommonButton>
  40. </div>
  41. </template>