umami/components/common/Table.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

import React from 'react';
2020-08-07 09:24:01 +02:00
import classNames from 'classnames';
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-09 08:48:43 +02:00
{columns.map(({ key, label, className, style, header }) => (
2020-08-07 11:27:12 +02:00
<div
key={key}
2020-08-09 08:48:43 +02:00
className={classNames(styles.head, className, header?.className)}
style={{ ...style, ...header?.style }}
2020-08-07 11:27:12 +02:00
>
2020-08-07 09:24:01 +02:00
{label}
</div>
))}
</div>
<div className={styles.body}>
{rows.map((row, rowIndex) => (
2020-08-07 09:24:01 +02:00
<div className={styles.row} key={rowIndex}>
2020-08-09 08:48:43 +02:00
{columns.map(({ key, render, className, style, cell }) => (
2020-08-07 09:24:01 +02:00
<div
key={`${rowIndex}${key}`}
2020-08-09 08:48:43 +02:00
className={classNames(styles.cell, className, cell?.className)}
style={{ ...style, ...cell?.style }}
2020-08-07 09:24:01 +02:00
>
{render ? render(row) : row[key]}
</div>
))}
2020-08-07 09:24:01 +02:00
</div>
))}
2020-08-07 09:24:01 +02:00
</div>
</div>
);
}