2020-04-02 16:58:18 -03:00
|
|
|
import React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
import classnames from 'classnames';
|
2020-05-11 21:17:22 -04:00
|
|
|
import Icon from './../Icon';
|
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(
|
|
|
|
|
'w-full transition border-transparent duration-300',
|
|
|
|
|
{
|
|
|
|
|
'border border-primary-light rounded overflow-hidden mb-2 hover:border-secondary-light': isExpanded,
|
|
|
|
|
}
|
|
|
|
|
)}
|
2020-04-02 16:58:18 -03:00
|
|
|
>
|
|
|
|
|
<table className={classnames('w-full p-4')}>
|
|
|
|
|
<tbody>
|
|
|
|
|
<tr
|
|
|
|
|
className={classnames(
|
2020-04-02 17:09:38 -03:00
|
|
|
'cursor-pointer hover:bg-secondary-main transition duration-300 bg-black',
|
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) => {
|
2020-04-02 16:58:18 -03:00
|
|
|
const { content, gridCol, name } = cell;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<td
|
|
|
|
|
key={name}
|
|
|
|
|
className={classnames(
|
|
|
|
|
'px-4 py-2 text-base',
|
2020-04-02 17:09:38 -03:00
|
|
|
{ 'border-b border-secondary-light': !isExpanded },
|
2020-04-02 16:58:18 -03:00
|
|
|
`w-${gridCol}/24` || ''
|
|
|
|
|
)}
|
2020-05-11 21:17:22 -04:00
|
|
|
style={{
|
|
|
|
|
maxWidth: 0,
|
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
|
}}
|
2020-04-02 16:58:18 -03:00
|
|
|
>
|
2020-05-11 21:17:22 -04:00
|
|
|
<div
|
|
|
|
|
className="flex flex-row items-center pl-1"
|
|
|
|
|
style={{
|
|
|
|
|
width: '100%',
|
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{index === 0 && (
|
|
|
|
|
<Icon
|
|
|
|
|
name={
|
|
|
|
|
isExpanded ? 'chevron-down' : 'chevron-right'
|
|
|
|
|
}
|
|
|
|
|
className="mr-4"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2020-04-02 16:58:18 -03:00
|
|
|
{content}
|
|
|
|
|
</div>
|
|
|
|
|
</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({
|
|
|
|
|
row: PropTypes.arrayOf(
|
|
|
|
|
PropTypes.shape({
|
|
|
|
|
key: PropTypes.string.isRequired,
|
|
|
|
|
content: PropTypes.node.isRequired,
|
|
|
|
|
gridCol: PropTypes.number.isRequired,
|
|
|
|
|
})
|
|
|
|
|
).isRequired,
|
|
|
|
|
expandedContent: PropTypes.node.isRequired,
|
|
|
|
|
onClickRow: PropTypes.func.isRequired,
|
|
|
|
|
isExpanded: PropTypes.bool.isRequired,
|
|
|
|
|
}),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default StudyListTableRow;
|