import React, { useEffect, useRef, useState } from "react"; import PropTypes from "prop-types"; import { StyledTableRow } from "./StyledTableContainer"; import TableCell from "./TableCell"; import ContextMenu from "../context-menu"; import ContextMenuButton from "../context-menu-button"; import Checkbox from "../checkbox"; const TableRow = (props) => { const { fileContextClick, children, contextOptions, checked, element, onContentSelect, item, className, style, selectionProp, ...rest } = props; const cm = useRef(); const row = useRef(); const onContextMenu = (e) => { fileContextClick && fileContextClick(); if (cm.current && !cm.current.menuRef.current) { row.current.click(e); } cm.current.show(e); }; const renderContext = Object.prototype.hasOwnProperty.call(props, "contextOptions") && contextOptions.length > 0; const getOptions = () => { fileContextClick && fileContextClick(); return contextOptions; }; const [iconVisible, setIconVisible] = useState(!checked); const onMouseOver = () => { if (checked) return; setIconVisible(false); }; const onMouseLeave = () => { if (checked) return; setIconVisible(true); }; useEffect(() => { setIconVisible(!checked); }, [checked]); const onChange = (e) => { onContentSelect && onContentSelect(e.target.checked, item); }; return ( {iconVisible ? ( element ) : ( )} {children}
{renderContext ? ( ) : (
)}
); }; TableRow.propTypes = { fileContextClick: PropTypes.func, children: PropTypes.any, contextOptions: PropTypes.array, checked: PropTypes.bool, element: PropTypes.any, onContentSelect: PropTypes.func, item: PropTypes.object, selectionProp: PropTypes.object, className: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), style: PropTypes.object, }; export default TableRow;