mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
chore: application prettier
This commit is contained in:
@ -2,7 +2,19 @@ import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Pagination from '@/components/Pagination'; // Correction du chemin d'importatio,
|
||||
|
||||
const Table = ({ data, columns, renderCell, itemsPerPage = 0, currentPage, totalPages, onPageChange, onRowClick, selectedRows, isSelectable = false, defaultTheme='bg-emerald-50' }) => {
|
||||
const Table = ({
|
||||
data,
|
||||
columns,
|
||||
renderCell,
|
||||
itemsPerPage = 0,
|
||||
currentPage,
|
||||
totalPages,
|
||||
onPageChange,
|
||||
onRowClick,
|
||||
selectedRows,
|
||||
isSelectable = false,
|
||||
defaultTheme = 'bg-emerald-50',
|
||||
}) => {
|
||||
const handlePageChange = (newPage) => {
|
||||
onPageChange(newPage);
|
||||
};
|
||||
@ -13,7 +25,10 @@ const Table = ({ data, columns, renderCell, itemsPerPage = 0, currentPage, total
|
||||
<thead>
|
||||
<tr>
|
||||
{columns.map((column, index) => (
|
||||
<th key={index} className="py-2 px-4 border-b border-gray-200 bg-gray-100 text-center text-sm font-semibold text-gray-600">
|
||||
<th
|
||||
key={index}
|
||||
className="py-2 px-4 border-b border-gray-200 bg-gray-100 text-center text-sm font-semibold text-gray-600"
|
||||
>
|
||||
{column.name}
|
||||
</th>
|
||||
))}
|
||||
@ -21,8 +36,8 @@ const Table = ({ data, columns, renderCell, itemsPerPage = 0, currentPage, total
|
||||
</thead>
|
||||
<tbody>
|
||||
{data?.map((row, rowIndex) => (
|
||||
<tr
|
||||
key={rowIndex}
|
||||
<tr
|
||||
key={rowIndex}
|
||||
className={`
|
||||
${isSelectable ? 'cursor-pointer' : ''}
|
||||
${selectedRows?.includes(row.id) ? 'bg-emerald-300 text-white' : rowIndex % 2 === 0 ? `${defaultTheme}` : ''}
|
||||
@ -31,8 +46,13 @@ const Table = ({ data, columns, renderCell, itemsPerPage = 0, currentPage, total
|
||||
onClick={() => isSelectable && onRowClick && onRowClick(row)}
|
||||
>
|
||||
{columns.map((column, colIndex) => (
|
||||
<td key={colIndex} className={`py-2 px-4 border-b border-gray-200 text-center text-sm ${selectedRows?.includes(row.id) ? 'text-white' : 'text-gray-700'}`} >
|
||||
{renderCell ? renderCell(row, column.name) : column.transform(row)}
|
||||
<td
|
||||
key={colIndex}
|
||||
className={`py-2 px-4 border-b border-gray-200 text-center text-sm ${selectedRows?.includes(row.id) ? 'text-white' : 'text-gray-700'}`}
|
||||
>
|
||||
{renderCell
|
||||
? renderCell(row, column.name)
|
||||
: column.transform(row)}
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
@ -52,10 +72,12 @@ const Table = ({ data, columns, renderCell, itemsPerPage = 0, currentPage, total
|
||||
|
||||
Table.propTypes = {
|
||||
data: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||
columns: PropTypes.arrayOf(PropTypes.shape({
|
||||
name: PropTypes.string.isRequired,
|
||||
transform: PropTypes.func.isRequired,
|
||||
})).isRequired,
|
||||
columns: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
name: PropTypes.string.isRequired,
|
||||
transform: PropTypes.func.isRequired,
|
||||
})
|
||||
).isRequired,
|
||||
renderCell: PropTypes.func,
|
||||
itemsPerPage: PropTypes.number,
|
||||
currentPage: PropTypes.number.isRequired,
|
||||
|
||||
Reference in New Issue
Block a user