SimpleTableRow.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import type { TableItem } from '#desktop/components/CommonSimpleTable/types.ts'
  5. export interface Props {
  6. item: TableItem
  7. onClickRow?: (tableItem: TableItem) => void
  8. isRowSelected?: boolean
  9. }
  10. const props = defineProps<Props>()
  11. const emit = defineEmits<{
  12. 'click-row': [TableItem]
  13. }>()
  14. const rowEventHandler = computed(() =>
  15. props.onClickRow
  16. ? {
  17. attrs: {
  18. role: 'button',
  19. tabindex: 0,
  20. ariaLabel: __('Select table row'),
  21. class:
  22. 'group focus-visible:outline-1 focus-visible:outline focus-visible:rounded-md active:bg-blue-800 active:dark:bg-blue-800 focus-visible:outline-blue-800 hover:bg-blue-600 dark:hover:bg-blue-900',
  23. },
  24. events: {
  25. click: () => emit('click-row', props.item),
  26. keydown: (event: KeyboardEvent) => {
  27. if (event.key !== 'Enter') return
  28. emit('click-row', props.item)
  29. },
  30. },
  31. }
  32. : { attrs: {}, events: {} },
  33. )
  34. </script>
  35. <template>
  36. <tr
  37. class="odd:bg-blue-200 odd:dark:bg-gray-700"
  38. :class="{
  39. '!bg-blue-800': isRowSelected,
  40. }"
  41. style="clip-path: xywh(0 0 100% 100% round 0.375rem)"
  42. data-test-id="simple-table-row"
  43. v-bind="rowEventHandler.attrs"
  44. v-on="rowEventHandler.events"
  45. >
  46. <slot :is-row-selected="isRowSelected" />
  47. </tr>
  48. </template>