blob: 9315a27921b303f1c4983a601b809799d70d0fa4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
import React from 'react';
interface Field {
key: string;
label: string;
}
interface Props {
items: any[];
fields: Field[];
handleRowClick?: (index: number) => void;
}
const ListTable: React.FC<Props> = ({ items, fields, handleRowClick = () => {} }) => {
return (
<table className="table-auto w-full">
<thead>
<tr className="border-b select-none">
{fields.map(field => <th>{field.label}</th>)}
</tr>
</thead>
<tbody>
{items.map((item, index) => (
<tr
className={`border-b hover:bg-gray-100 cursor-pointer ${index % 2 && 'bg-gray-50'}`}
onClick={() => handleRowClick(index)}
>
{fields.map(field => <td className="p-3">{item[field.key]}</td>)}
</tr>
))}
</tbody>
</table>
);
};
export default ListTable;
|