Files
ohif-viewer/platform/ui/src/components/StudyListTable/StudyListTableRow.tsx
T

116 lines
3.8 KiB
TypeScript
Raw Normal View History

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import getGridWidthClass from '../../utils/getGridWidthClass';
import Icon from '../Icon';
const StudyListTableRow = props => {
const { tableData } = props;
const { row, expandedContent, onClickRow, isExpanded, dataCY, clickableCY } = tableData;
return (
<>
<tr
className="select-none"
data-cy={dataCY}
>
<td
className={classnames('border-0 p-0', {
'border-secondary-light bg-primary-dark border-b': isExpanded,
})}
>
<div
className={classnames(
2022-09-19 20:02:53 -04:00
'w-full transition duration-300',
{
'border-primary-light hover:border-secondary-light mb-2 overflow-visible rounded border':
isExpanded,
2022-09-19 20:02:53 -04:00
},
{
'border-transparent': !isExpanded,
}
)}
>
<table className={classnames('w-full p-4')}>
<tbody>
<tr
className={classnames(
'hover:bg-secondary-main cursor-pointer transition duration-300',
{
2020-04-02 17:09:38 -03:00
'bg-primary-dark': !isExpanded,
},
2020-04-02 17:09:38 -03:00
{ 'bg-secondary-dark': isExpanded }
)}
onClick={onClickRow}
data-cy={clickableCY}
>
{row.map((cell, index) => {
const { content, title, gridCol } = cell;
return (
<td
2020-05-12 15:10:26 -04:00
key={index}
className={classnames(
'truncate px-4 py-2 text-base',
{ 'border-secondary-light border-b': !isExpanded },
getGridWidthClass(gridCol) || ''
)}
style={{
maxWidth: 0,
}}
2020-05-11 21:36:51 -04:00
title={title}
>
<div className="flex">
{index === 0 && (
<div>
<Icon
name={isExpanded ? 'chevron-down' : 'chevron-right'}
className="mr-4 inline-flex"
/>
</div>
)}
2022-09-19 20:02:53 -04:00
<div
className={classnames({ 'overflow-hidden': true }, { truncate: true })}
2022-09-19 20:02:53 -04:00
>
{content}
</div>
</div>
</td>
);
})}
</tr>
{isExpanded && (
<tr className="max-h-0 w-full select-text overflow-hidden bg-black">
<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 */
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,
gridCol: PropTypes.number.isRequired,
})
).isRequired,
expandedContent: PropTypes.node.isRequired,
onClickRow: PropTypes.func.isRequired,
isExpanded: PropTypes.bool.isRequired,
dataCY: PropTypes.string,
clickableCY: PropTypes.string,
}),
};
export default StudyListTableRow;