This code violates both DRY and KISS principles by:
1. Repeating cell structure and styling
2. Making the component too complex with inline styling
A better approach would be:
const TableCell = ({ icon: Icon, children }) => (
<td>
<div className="flex items-center space-x-2">
{Icon && <Icon className="w-4 h-4 text-gray-400" />}
{children}
</div>
</td>
);
const ActionButton = ({ icon: Icon, onClick, variant }) => (
<button
onClick={onClick}
className={`p-2 text-${variant}-600 hover:bg-${variant}-50 rounded-full`}
>
<Icon className="w-4 h-4" />
</button>
);
function DataTable({ data, onEdit, onDelete }) {
return (
<table>
{/* ... header ... */}
<tbody>
{data.map(item => (
<tr key={item.id}>
<TableCell>
<img src={item.avatar} alt={item.name} className="w-8 h-8 rounded-full" />
<span className="font-medium">{item.name}</span>
</TableCell>
<TableCell icon={MailIcon}>{item.email}</TableCell>
<TableCell icon={UserIcon}>{item.role}</TableCell>
<TableCell icon={StatusIcon}>{item.status}</TableCell>
<TableCell>
<div className="flex items-center space-x-2">
<ActionButton icon={EditIcon} onClick={() => onEdit(item)} variant="blue" />
<ActionButton icon={DeleteIcon} onClick={() => onDelete(item)} variant="red" />
</div>
</TableCell>
</tr>
))}
</tbody>
</table>
);
}