2020-04-09 20:31:21 -03:00
|
|
|
import React, { useState } from 'react';
|
2020-04-10 15:05:06 -03:00
|
|
|
import PropTypes from 'prop-types';
|
2020-04-09 20:31:21 -03:00
|
|
|
import classnames from 'classnames';
|
2020-04-10 15:05:06 -03:00
|
|
|
import { Icon } from '@ohif/ui';
|
2020-04-09 20:31:21 -03:00
|
|
|
|
2020-04-10 15:05:06 -03:00
|
|
|
const MeasurementTable = ({ title, amount, data }) => {
|
2020-04-09 20:31:21 -03:00
|
|
|
const [activeItem, setActiveItem] = useState(null);
|
|
|
|
|
|
2020-04-10 15:05:06 -03:00
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<div className="flex justify-between px-2 py-1 bg-secondary-main">
|
|
|
|
|
<span className="text-base font-bold text-white tracking-widest uppercase">
|
|
|
|
|
{title}
|
|
|
|
|
</span>
|
|
|
|
|
<span className="text-base font-bold text-white">{amount}</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="overflow-y-auto overflow-x-hidden ohif-scrollbar max-h-80">
|
|
|
|
|
{!!data.length &&
|
|
|
|
|
data.map((e, i) => {
|
|
|
|
|
const itemKey = i;
|
|
|
|
|
const currentItem = i + 1;
|
|
|
|
|
const isActive = !!activeItem && activeItem[title] === i;
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={i}
|
|
|
|
|
className={classnames(
|
|
|
|
|
'group flex cursor-default bg-black border border-transparent transition duration-300 ',
|
|
|
|
|
{
|
|
|
|
|
'rounded overflow-hidden border-primary-light': isActive,
|
|
|
|
|
}
|
|
|
|
|
)}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setActiveItem((s) => {
|
|
|
|
|
return {
|
|
|
|
|
...s,
|
|
|
|
|
[title]: s && s[title] === itemKey ? null : itemKey,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
2020-04-09 20:31:21 -03:00
|
|
|
<div
|
|
|
|
|
className={classnames(
|
2020-04-10 15:05:06 -03:00
|
|
|
'text-center w-6 py-1 text-base transition duration-300',
|
2020-04-09 20:31:21 -03:00
|
|
|
{
|
2020-04-10 15:05:06 -03:00
|
|
|
'bg-primary-light text-black': isActive,
|
|
|
|
|
'bg-primary-dark text-primary-light group-hover:bg-secondary-main': !isActive,
|
2020-04-09 20:31:21 -03:00
|
|
|
}
|
|
|
|
|
)}
|
|
|
|
|
>
|
2020-04-10 15:05:06 -03:00
|
|
|
{currentItem}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="px-2 py-1 flex flex-1 flex-col relative">
|
|
|
|
|
<span className="text-base text-primary-light mb-1">
|
|
|
|
|
Label short description
|
|
|
|
|
</span>
|
|
|
|
|
<span className="pl-2 border-l border-primary-light text-base text-white">
|
|
|
|
|
24.0 x 24.0 mm (S:4, I:22)
|
|
|
|
|
</span>
|
|
|
|
|
<Icon
|
2020-04-09 20:31:21 -03:00
|
|
|
className={classnames(
|
2020-04-10 15:05:06 -03:00
|
|
|
'text-white w-4 absolute cursor-pointer transition duration-300',
|
2020-04-09 20:31:21 -03:00
|
|
|
{
|
2020-04-10 15:05:06 -03:00
|
|
|
'invisible opacity-0 mr-2': !isActive,
|
2020-04-09 20:31:21 -03:00
|
|
|
}
|
|
|
|
|
)}
|
2020-04-10 15:05:06 -03:00
|
|
|
name="pencil"
|
|
|
|
|
style={{
|
|
|
|
|
top: 4,
|
|
|
|
|
right: 4,
|
|
|
|
|
transform: isActive ? '' : 'translateX(100%)',
|
|
|
|
|
}}
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
// stopPropagation needed to avoid disable the current active item
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
alert('Edit');
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2020-04-09 20:31:21 -03:00
|
|
|
</div>
|
2020-04-10 15:05:06 -03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
{!data.length && (
|
|
|
|
|
<div
|
|
|
|
|
className={classnames(
|
|
|
|
|
'group flex cursor-default bg-black border border-transparent transition duration-300 '
|
|
|
|
|
)}
|
|
|
|
|
>
|
2020-04-10 13:40:05 -03:00
|
|
|
<div
|
|
|
|
|
className={classnames(
|
2020-04-10 15:05:06 -03:00
|
|
|
'text-center w-6 py-1 text-base transition duration-300 bg-primary-dark text-primary-light group-hover:bg-secondary-main'
|
2020-04-10 13:40:05 -03:00
|
|
|
)}
|
2020-04-10 15:05:06 -03:00
|
|
|
></div>
|
|
|
|
|
<div className="px-2 py-4 flex flex-1 items-center justify-between">
|
|
|
|
|
<span className="text-base text-primary-light mb-1 flex items-center flex-1">
|
|
|
|
|
No tracked measurements
|
|
|
|
|
</span>
|
2020-04-10 13:40:05 -03:00
|
|
|
</div>
|
2020-04-10 13:33:14 -03:00
|
|
|
</div>
|
2020-04-10 15:05:06 -03:00
|
|
|
)}
|
2020-04-09 20:31:21 -03:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-10 15:05:06 -03:00
|
|
|
MeasurementTable.defaultProps = {
|
|
|
|
|
amount: null,
|
|
|
|
|
data: [],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MeasurementTable.propTypes = {
|
|
|
|
|
title: PropTypes.string.isRequired,
|
|
|
|
|
amount: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
|
|
|
data: PropTypes.array, // TODO: define better the array structure
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-09 20:31:21 -03:00
|
|
|
export default MeasurementTable;
|