11import React , { ReactElement , ReactNode } from "react" ;
22import classNames from "classnames" ;
33import { Hint } from "./hint" ;
4+ import { Loading } from "./loading" ;
45
56export type CellPrimitive = ReactElement | string | number ;
67
@@ -13,6 +14,7 @@ export interface Column {
1314interface CommonTableProps {
1415 columns : Column [ ] ;
1516 data : Record < string , CellPrimitive > [ ] ;
17+ loading ?: boolean ;
1618 className ?: string ;
1719 tableClassName ?: string ;
1820 headerClassName ?: string ;
@@ -25,6 +27,7 @@ interface CommonTableProps {
2527export function CommonTable ( {
2628 columns,
2729 data,
30+ loading = false ,
2831 className = "" ,
2932 tableClassName = "" ,
3033 headerClassName = "bg-gray-700 border-gray-600" ,
@@ -62,58 +65,71 @@ export function CommonTable({
6265 </ div >
6366 ) }
6467
65- < div className = { classNames ( "overflow-x-auto" , tableClassName ) } >
66- < table className = "w-full border-collapse border border-gray-300 rounded-sm" >
67- < thead >
68- < tr className = "bg-gray-100" >
69- { columns . map ( ( column ) => (
70- < th
71- key = { column . name }
68+ < div className = "relative" >
69+ < div
70+ className = { classNames (
71+ "overflow-x-auto" ,
72+ tableClassName ,
73+ loading && "opacity-50 pointer-events-none" ,
74+ ) }
75+ >
76+ < table className = "w-full border-collapse border border-gray-300 rounded-sm" >
77+ < thead >
78+ < tr className = "bg-gray-100" >
79+ { columns . map ( ( column ) => (
80+ < th
81+ key = { column . name }
82+ className = { classNames (
83+ "border border-gray-300 px-2 py-1 text-center font-semibold text-gray-700" ,
84+ columnHeaderClassName ,
85+ ) }
86+ >
87+ { column . hint ? (
88+ < Hint hintContent = { column . hint } >
89+ < span > { column . name } </ span >
90+ </ Hint >
91+ ) : (
92+ column . name
93+ ) }
94+ </ th >
95+ ) ) }
96+ </ tr >
97+ </ thead >
98+
99+ < tbody >
100+ { data . map ( ( row , rowIndex ) => (
101+ < tr
102+ key = { rowIndex }
72103 className = { classNames (
73- "border border -gray-300 px-2 py-1 text-center font-semibold text-gray-700 " ,
74- columnHeaderClassName ,
104+ "bg -gray-700 hover:bg-gray-800 transition-colors duration-150 " ,
105+ onRowClick && "cursor-pointer" ,
75106 ) }
107+ onClick = { ( ) => onRowClick ?.( row , rowIndex ) }
76108 >
77- { column . hint ? (
78- < Hint hintContent = { column . hint } >
79- < span > { column . name } </ span >
80- </ Hint >
81- ) : (
82- column . name
83- ) }
84- </ th >
109+ { columns . map ( ( column ) => {
110+ const cellValue = row [ column . name ] ;
111+ return (
112+ < td
113+ key = { column . name }
114+ className = { classNames (
115+ "border border-gray-300 px-2 py-1" ,
116+ cellClassName ,
117+ ) }
118+ >
119+ { renderCell ( cellValue , column ) }
120+ </ td >
121+ ) ;
122+ } ) }
123+ </ tr >
85124 ) ) }
86- </ tr >
87- </ thead >
88-
89- < tbody >
90- { data . map ( ( row , rowIndex ) => (
91- < tr
92- key = { rowIndex }
93- className = { classNames (
94- "bg-gray-700 hover:bg-gray-800 transition-colors duration-150" ,
95- onRowClick && "cursor-pointer" ,
96- ) }
97- onClick = { ( ) => onRowClick ?.( row , rowIndex ) }
98- >
99- { columns . map ( ( column ) => {
100- const cellValue = row [ column . name ] ;
101- return (
102- < td
103- key = { column . name }
104- className = { classNames (
105- "border border-gray-300 px-2 py-1" ,
106- cellClassName ,
107- ) }
108- >
109- { renderCell ( cellValue , column ) }
110- </ td >
111- ) ;
112- } ) }
113- </ tr >
114- ) ) }
115- </ tbody >
116- </ table >
125+ </ tbody >
126+ </ table >
127+ </ div >
128+ { loading && (
129+ < div className = "absolute inset-0 flex items-center justify-center bg-gray-900/60" >
130+ < Loading />
131+ </ div >
132+ ) }
117133 </ div >
118134 </ div >
119135 ) ;
0 commit comments