DocSpace-client/packages/asc-web-components/table-container/TableHeaderCell.js

85 lines
2.1 KiB
JavaScript
Raw Normal View History

import React from "react";
import PropTypes from "prop-types";
import Text from "../text";
import Link from "../link";
import IconButton from "../icon-button";
import globalColors from "../utils/globalColors";
import { StyledTableHeaderCell } from "./StyledTableContainer";
2021-07-28 14:22:50 +00:00
const TableHeaderCell = ({
column,
index,
onMouseDown,
resizable,
sortBy,
sorted,
}) => {
const { options, title, enable, active } = column;
const isActive = column.sortBy === sortBy || active;
2021-07-27 12:22:51 +00:00
const onClick = (e) => {
2021-07-27 12:22:51 +00:00
column.onClick(column.sortBy, e);
};
return (
<StyledTableHeaderCell
sorted={sorted}
2021-07-27 12:22:51 +00:00
isActive={isActive}
className="table-container_header-cell"
id={`column_${index + 1}`}
data-enable={enable}
>
<div className="table-container_header-item">
{column.onClick ? (
<div className="header-container-text-wrapper">
<Link
onClick={onClick}
fontWeight={600}
color={globalColors.gray}
className="header-container-text"
data={options}
noHover
>
2021-07-27 10:51:56 +00:00
{enable ? title : ""}
</Link>
<IconButton
onClick={column.onIconClick ? column.onIconClick : column.onClick}
iconName="/static/images/folder arrow.react.svg"
className="header-container-text-icon"
size="small"
/>
</div>
) : (
<Text
fontWeight={600}
color={globalColors.gray}
className="header-container-text"
>
2021-07-27 10:51:56 +00:00
{enable ? title : ""}
</Text>
)}
{resizable && (
<div
data-column={`${index + 1}`}
className="resize-handle not-selectable"
onMouseDown={onMouseDown}
/>
)}
</div>
</StyledTableHeaderCell>
);
};
TableHeaderCell.propTypes = {
column: PropTypes.object,
index: PropTypes.number,
onMouseDown: PropTypes.func,
resizable: PropTypes.bool,
2021-07-28 14:22:50 +00:00
sorted: PropTypes.bool,
2021-07-27 12:22:51 +00:00
sortBy: PropTypes.string,
};
export default TableHeaderCell;