2023-07-09 20:39:11 +00:00
|
|
|
import clsx from 'clsx';
|
|
|
|
import { Children, PropsWithChildren } from 'react';
|
2022-05-09 21:01:15 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
headers?: string[];
|
|
|
|
dataCy?: string;
|
2023-07-09 20:39:11 +00:00
|
|
|
className?: string;
|
|
|
|
emptyMessage?: string;
|
2022-05-09 21:01:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export function DetailsTable({
|
|
|
|
headers = [],
|
|
|
|
dataCy,
|
2023-07-09 20:39:11 +00:00
|
|
|
className,
|
|
|
|
emptyMessage,
|
2022-05-09 21:01:15 +00:00
|
|
|
children,
|
|
|
|
}: PropsWithChildren<Props>) {
|
|
|
|
return (
|
2023-07-09 20:39:11 +00:00
|
|
|
<table className={clsx('table', className)} data-cy={dataCy}>
|
2022-05-09 21:01:15 +00:00
|
|
|
{headers.length > 0 && (
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
{headers.map((header) => (
|
|
|
|
<th key={header}>{header}</th>
|
|
|
|
))}
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
)}
|
2023-07-09 20:39:11 +00:00
|
|
|
<tbody>
|
|
|
|
{Children.count(children) > 0 ? (
|
|
|
|
children
|
|
|
|
) : (
|
|
|
|
<tr>
|
|
|
|
<td colSpan={headers.length} className="text-muted text-center">
|
|
|
|
{emptyMessage}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
)}
|
|
|
|
</tbody>
|
2022-05-09 21:01:15 +00:00
|
|
|
</table>
|
|
|
|
);
|
|
|
|
}
|