1- import { Fragment , useEffect , useMemo , useState } from 'react' ;
1+ import { useEffect , useMemo , useState } from 'react' ;
22
33import {
44 flexRender ,
@@ -45,10 +45,10 @@ type DataTableColumn<TData extends { [key: string]: unknown }> =
4545type DataTableProps < TData extends { [ key : string ] : unknown } > = {
4646 columns : DataTableColumn < TData > [ ] ;
4747 data : TData [ ] ;
48- headerAction ?: {
48+ headerActions ?: {
4949 label : string ;
5050 onClick : ( ) => void ;
51- } ;
51+ } [ ] ;
5252 rowActions ?: RowAction < TData > [ ] ;
5353 search ?: {
5454 key : Extract < keyof TData , string > ;
@@ -65,7 +65,7 @@ function isStaticColumn<TData extends { [key: string]: unknown }>(
6565export const DataTable = < TData extends { [ key : string ] : unknown } > ( {
6666 columns,
6767 data,
68- headerAction ,
68+ headerActions ,
6969 rowActions,
7070 search
7171} : DataTableProps < TData > ) => {
@@ -173,7 +173,7 @@ export const DataTable = <TData extends { [key: string]: unknown }>({
173173 const pageIndexOptions = range ( start , end ) ;
174174
175175 return (
176- < Fragment >
176+ < div className = "flex flex-col" >
177177 < DestructiveActionDialog
178178 destructiveActionPending = { destructiveActionPending }
179179 setDestructiveActionPending = { setDestructiveActionPending }
@@ -186,10 +186,14 @@ export const DataTable = <TData extends { [key: string]: unknown }>({
186186 value = { searchValue }
187187 onValueChange = { setSearchValue }
188188 />
189- { headerAction && (
190- < Button type = "button" variant = "outline" onClick = { headerAction . onClick } >
191- { headerAction . label }
192- </ Button >
189+ { headerActions && (
190+ < div className = "flex gap-2" >
191+ { headerActions . map ( ( { label, onClick } , i ) => (
192+ < Button key = { i } type = "button" variant = "outline" onClick = { onClick } >
193+ { label }
194+ </ Button >
195+ ) ) }
196+ </ div >
193197 ) }
194198 </ div >
195199 ) }
@@ -230,30 +234,29 @@ export const DataTable = <TData extends { [key: string]: unknown }>({
230234 </ Table . Body >
231235 </ Table >
232236 </ div >
233- < div className = "mx-auto flex w-min pt-6 pb-4 " >
237+ < div className = "flex w-min gap-0.5 py-4 [&>button]:h-9 " >
234238 < Button
235- className = "flex gap-1"
236239 disabled = { ! table . getCanPreviousPage ( ) }
240+ size = "icon"
237241 type = "button"
238242 variant = "ghost"
239243 onClick = { ( ) => table . firstPage ( ) }
240244 >
241- < ChevronsLeftIcon className = "-ml-1 h-4 w-4" />
242- < span > { t ( 'pagination.first' ) } </ span >
245+ < ChevronsLeftIcon className = "h-4 w-4" />
243246 </ Button >
244247 < Button
245- className = "mr-1 flex gap-1"
246248 disabled = { ! table . getCanPreviousPage ( ) }
249+ size = "icon"
247250 type = "button"
248251 variant = "ghost"
249252 onClick = { ( ) => table . previousPage ( ) }
250253 >
251- < ChevronLeftIcon className = "-ml-1 h-4 w-4" />
252- < span > { t ( 'pagination.previous' ) } </ span >
254+ < ChevronLeftIcon className = "h-4 w-4" />
253255 </ Button >
254256 { pageIndexOptions . map ( ( index ) => (
255257 < Button
256258 key = { index }
259+ size = "icon"
257260 type = "button"
258261 variant = { index === pagination . pageIndex ? 'outline' : 'ghost' }
259262 onClick = { ( ) => table . setPageIndex ( index ) }
@@ -262,27 +265,25 @@ export const DataTable = <TData extends { [key: string]: unknown }>({
262265 </ Button >
263266 ) ) }
264267 < Button
265- className = "ml-1 flex gap-1"
266268 disabled = { ! table . getCanNextPage ( ) }
269+ size = "icon"
267270 type = "button"
268271 variant = "ghost"
269272 onClick = { ( ) => table . nextPage ( ) }
270273 >
271- < span > { t ( 'pagination.next' ) } </ span >
272- < ChevronRightIcon className = "-mr-1 h-4 w-4" />
274+ < ChevronRightIcon className = "h-4 w-4" />
273275 </ Button >
274276 < Button
275- className = "flex gap-1"
276277 disabled = { ! table . getCanNextPage ( ) }
278+ size = "icon"
277279 type = "button"
278280 variant = "ghost"
279281 onClick = { ( ) => table . lastPage ( ) }
280282 >
281- < span > { t ( 'pagination.last' ) } </ span >
282- < ChevronsRightIcon className = "-mr-1 h-4 w-4" />
283+ < ChevronsRightIcon className = "h-4 w-4" />
283284 </ Button >
284285 </ div >
285- </ Fragment >
286+ </ div >
286287 ) ;
287288} ;
288289
0 commit comments