22import { ref , watch } from ' vue'
33import DsfrTableRow , { type DsfrTableRowProps } from ' ./DsfrTableRow.vue'
44import DsfrTableHeaders from ' ./DsfrTableHeaders.vue'
5- import { type DsfrTableHeaderProps } from ' ./DsfrTableHeader .vue'
5+ import { type DsfrTableHeadersProps } from ' ./DsfrTableHeaders .vue'
66
77const props = withDefaults (defineProps <{
88 title? : string
9- headers? : ( DsfrTableHeaderProps | string )[]
10- rows? : (DsfrTableRowProps | string )[]
9+ headers? : DsfrTableHeadersProps
10+ rows? : (DsfrTableRowProps | string [] )[]
1111 noCaption? : boolean
1212 pagination? : boolean
1313 defaultCurrentPage? : number
@@ -20,9 +20,8 @@ const props = withDefaults(defineProps<{
2020 defaultOptionSelected: 10 ,
2121})
2222
23- const getRowData = (row : (DsfrTableRowProps | string | ({component: string } & Record <string , any >))) => {
24- // @ts-ignore TODO: find a way to improve types here
25- return row .rowData || row
23+ const getRowData = (row : (DsfrTableRowProps | string [])) => {
24+ return Array .isArray (row ) ? row : row .rowData
2625}
2726
2827const currentPage = ref (props .defaultCurrentPage )
@@ -33,12 +32,12 @@ const returnLowestLimit = () => currentPage.value * optionSelected.value - optio
3332const returnHighestLimit = () => currentPage .value * optionSelected .value
3433let truncatedResults = props .rows .slice (returnLowestLimit (), returnHighestLimit ())
3534
36- watch (() => optionSelected .value , (newVal , OldVal ) => {
35+ watch (() => optionSelected .value , (newVal ) => {
3736 props .rows .length > optionSelected .value ? pageCount .value = Math .ceil (props .rows .length / newVal ) : pageCount .value = 1
3837 truncatedResults = props .rows .slice (returnLowestLimit (), returnHighestLimit ())
3938})
4039
41- watch (() => currentPage .value , (newVal , OldVal ) => {
40+ watch (() => currentPage .value , () => {
4241 truncatedResults = props .rows .slice (returnLowestLimit (), returnHighestLimit ())
4342})
4443
@@ -54,7 +53,6 @@ const goNextPage = () => {
5453 }
5554}
5655const goLastPage = () => { currentPage .value = pageCount .value }
57-
5856 </script >
5957
6058<template >
@@ -85,7 +83,7 @@ const goLastPage = () => { currentPage.value = pageCount.value }
8583 v-for =" (row, i) of truncatedResults"
8684 :key =" i"
8785 :row-data =" getRowData(row)"
88- :row-attrs =" typeof row === 'string' ? {} : row.rowAttrs"
86+ :row-attrs =" 'rowAttrs' in row ? row.rowAttrs : {} "
8987 />
9088 </template >
9189 <tr v-if =" pagination" >
0 commit comments