2020-04-02 16:58:18 -03:00
|
|
|
import React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import classnames from 'classnames';
|
2020-08-14 15:25:08 -03:00
|
|
|
import { Icon } from '../';
|
2021-07-26 13:22:25 +02:00
|
|
|
import getGridWidthClass from '../../utils/getGridWidthClass';
|
2020-04-02 16:58:18 -03:00
|
|
|
|
2020-05-11 21:17:22 -04:00
|
|
|
const StudyListTableRow = props => {
|
2020-04-02 16:58:18 -03:00
|
|
|
const { tableData } = props;
|
|
|
|
|
const { row, expandedContent, onClickRow, isExpanded } = tableData;
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2020-05-11 21:16:36 -04:00
|
|
|
<tr className="select-none">
|
2020-04-02 16:58:18 -03:00
|
|
|
<td
|
|
|
|
|
className={classnames('border-0 p-0', {
|
2020-04-02 17:09:38 -03:00
|
|
|
'border-b border-secondary-light bg-primary-dark': isExpanded,
|
2020-04-02 16:58:18 -03:00
|
|
|
})}
|
|
|
|
|
>
|
|
|
|
|
<div
|
2020-04-08 13:50:33 -03:00
|
|
|
className={classnames(
|
2022-09-19 20:02:53 -04:00
|
|
|
'w-full transition duration-300',
|
2020-04-08 13:50:33 -03:00
|
|
|
{
|
|
|
|
|
'border border-primary-light rounded overflow-hidden mb-2 hover:border-secondary-light': isExpanded,
|
2022-09-19 20:02:53 -04:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'border-transparent': !isExpanded,
|
2020-04-08 13:50:33 -03:00
|
|
|
}
|
|
|
|
|
)}
|
2020-04-02 16:58:18 -03:00
|
|
|
>
|
|
|
|
|
<table className={classnames('w-full p-4')}>
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr
|
|
|
|
|
className={classnames(
|
2022-09-19 20:02:53 -04:00
|
|
|
'cursor-pointer hover:bg-secondary-main transition duration-300',
|
2020-04-02 16:58:18 -03:00
|
|
|
{
|
2020-04-02 17:09:38 -03:00
|
|
|
'bg-primary-dark': !isExpanded,
|
2020-04-02 16:58:18 -03:00
|
|
|
},
|
2020-04-02 17:09:38 -03:00
|
|
|
{ 'bg-secondary-dark': isExpanded }
|
2020-04-02 16:58:18 -03:00
|
|
|
)}
|
|
|
|
|
onClick={onClickRow}
|
|
|
|
|
>
|
2020-05-11 21:17:22 -04:00
|
|
|
{row.map((cell, index) => {
|
2021-03-01 16:52:54 +01:00
|
|
|
const { content, title, gridCol } = cell;
|
2020-04-02 16:58:18 -03:00
|
|
|
return (
|
|
|
|
|
<td
|
2020-05-12 15:10:26 -04:00
|
|
|
key={index}
|
2020-04-02 16:58:18 -03:00
|
|
|
className={classnames(
|
2020-05-11 21:36:51 -04:00
|
|
|
'px-4 py-2 text-base truncate',
|
2020-04-02 17:09:38 -03:00
|
|
|
{ 'border-b border-secondary-light': !isExpanded },
|
2021-07-26 13:22:25 +02:00
|
|
|
getGridWidthClass(gridCol) || ''
|
2020-04-02 16:58:18 -03:00
|
|
|
)}
|
2020-05-11 21:17:22 -04:00
|
|
|
style={{
|
|
|
|
|
maxWidth: 0,
|
|
|
|
|
}}
|
2020-05-11 21:36:51 -04:00
|
|
|
title={title}
|
2020-04-02 16:58:18 -03:00
|
|
|
>
|
2021-08-19 08:05:33 -04:00
|
|
|
<div className="flex">
|
|
|
|
|
{index === 0 && (
|
|
|
|
|
<div>
|
|
|
|
|
<Icon
|
2022-09-19 20:02:53 -04:00
|
|
|
name={
|
|
|
|
|
isExpanded ? 'chevron-down' : 'chevron-right'
|
|
|
|
|
}
|
2021-08-19 08:05:33 -04:00
|
|
|
className="mr-4 inline-flex"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2022-09-19 20:02:53 -04:00
|
|
|
<div
|
|
|
|
|
className={classnames(
|
|
|
|
|
{ 'overflow-hidden': true },
|
|
|
|
|
{ truncate: true }
|
|
|
|
|
)}
|
|
|
|
|
>
|
2021-08-19 08:05:33 -04:00
|
|
|
{content}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2020-04-02 16:58:18 -03:00
|
|
|
</td>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</tr>
|
|
|
|
|
{isExpanded && (
|
2020-05-11 21:16:36 -04:00
|
|
|
<tr className="w-full bg-black select-text max-h-0 overflow-hidden">
|
2020-04-02 16:58:18 -03:00
|
|
|
<td colSpan={row.length}>{expandedContent}</td>
|
|
|
|
|
</tr>
|
|
|
|
|
)}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
|
|
|
|
</div>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
StudyListTableRow.propTypes = {
|
|
|
|
|
tableData: PropTypes.shape({
|
2020-05-12 00:05:15 -04:00
|
|
|
/** A table row represented by an array of "cell" objects */
|
2020-04-02 16:58:18 -03:00
|
|
|
row: PropTypes.arrayOf(
|
|
|
|
|
PropTypes.shape({
|
|
|
|
|
key: PropTypes.string.isRequired,
|
2020-05-12 00:05:15 -04:00
|
|
|
/** Optional content to render in row's cell */
|
|
|
|
|
content: PropTypes.node,
|
2020-05-11 21:36:51 -04:00
|
|
|
/** Title attribute to use for provided content */
|
|
|
|
|
title: PropTypes.string,
|
2020-04-02 16:58:18 -03:00
|
|
|
gridCol: PropTypes.number.isRequired,
|
|
|
|
|
})
|
|
|
|
|
).isRequired,
|
|
|
|
|
expandedContent: PropTypes.node.isRequired,
|
|
|
|
|
onClickRow: PropTypes.func.isRequired,
|
|
|
|
|
isExpanded: PropTypes.bool.isRequired,
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default StudyListTableRow;
|