2020-08-07 08:02:24 +02:00
|
|
|
import React from 'react';
|
2020-08-07 09:24:01 +02:00
|
|
|
import classNames from 'classnames';
|
2020-08-07 08:02:24 +02:00
|
|
|
import styles from './Table.module.css';
|
|
|
|
|
|
|
|
export default function Table({ columns, rows }) {
|
|
|
|
return (
|
2020-08-07 09:24:01 +02:00
|
|
|
<div className={styles.table}>
|
|
|
|
<div className={styles.header}>
|
2020-08-07 11:27:12 +02:00
|
|
|
{columns.map(({ key, label, header }) => (
|
|
|
|
<div
|
|
|
|
key={key}
|
|
|
|
className={classNames(styles.head, header?.className)}
|
|
|
|
style={header?.style}
|
|
|
|
>
|
2020-08-07 09:24:01 +02:00
|
|
|
{label}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<div className={styles.body}>
|
2020-08-07 08:02:24 +02:00
|
|
|
{rows.map((row, rowIndex) => (
|
2020-08-07 09:24:01 +02:00
|
|
|
<div className={styles.row} key={rowIndex}>
|
2020-08-07 11:27:12 +02:00
|
|
|
{columns.map(({ key, render, cell }) => (
|
2020-08-07 09:24:01 +02:00
|
|
|
<div
|
|
|
|
key={`${rowIndex}${key}`}
|
2020-08-07 11:27:12 +02:00
|
|
|
className={classNames(styles.cell, cell?.className)}
|
|
|
|
style={cell?.style}
|
2020-08-07 09:24:01 +02:00
|
|
|
>
|
|
|
|
{render ? render(row) : row[key]}
|
|
|
|
</div>
|
2020-08-07 08:02:24 +02:00
|
|
|
))}
|
2020-08-07 09:24:01 +02:00
|
|
|
</div>
|
2020-08-07 08:02:24 +02:00
|
|
|
))}
|
2020-08-07 09:24:01 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-08-07 08:02:24 +02:00
|
|
|
);
|
|
|
|
}
|