SimpleTableRow.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. hasCheckbox?: boolean
  10. }
  11. const props = defineProps<Props>()
  12. const emit = defineEmits<{
  13. 'click-row': [TableItem]
  14. }>()
  15. const rowEventHandler = computed(() => {
  16. return (props.onClickRow || props.hasCheckbox) && !props.item.disabled
  17. ? {
  18. attrs: {
  19. role: props.hasCheckbox ? undefined : 'button',
  20. tabindex: props.hasCheckbox ? -1 : 0,
  21. ariaLabel: __('Select table row'),
  22. class:
  23. 'group focus-visible:outline-transparent cursor-pointer active:bg-blue-800 active:dark:bg-blue-800 focus-visible:bg-blue-800 focus-visible:dark:bg-blue-900 focus-within:text-white hover:bg-blue-600 dark:hover:bg-blue-900',
  24. },
  25. events: {
  26. click: () => {
  27. ;(document.activeElement as HTMLElement)?.blur()
  28. emit('click-row', props.item)
  29. },
  30. keydown: (event: KeyboardEvent) => {
  31. if (event.key !== 'Enter') return
  32. emit('click-row', props.item)
  33. },
  34. },
  35. }
  36. : { attrs: {}, events: {} }
  37. })
  38. </script>
  39. <template>
  40. <tr
  41. class="odd:bg-blue-200 odd:dark:bg-gray-700"
  42. :class="{
  43. '!bg-blue-800': !hasCheckbox && isRowSelected,
  44. }"
  45. style="clip-path: xywh(0 0 100% 100% round 0.375rem)"
  46. data-test-id="simple-table-row"
  47. v-bind="rowEventHandler.attrs"
  48. v-on="rowEventHandler.events"
  49. >
  50. <slot :is-row-selected="isRowSelected" />
  51. </tr>
  52. </template>