import * as React from 'react'; import { IExtra, IFormatterValueType, OnCheckChange, OnTreeRowCollapse, OnToggleRowDetails } from '../../TableTypes'; import { css } from '@patternfly/react-styles'; import styles from '@patternfly/react-styles/css/components/Table/table'; import stylesTreeView from '@patternfly/react-styles/css/components/Table/table-tree-view'; import { Button } from '@patternfly/react-core/dist/esm/components/Button'; import { Checkbox } from '@patternfly/react-core/dist/esm/components/Checkbox'; import AngleDownIcon from '@patternfly/react-icons/dist/esm/icons/angle-down-icon'; import EllipsisHIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-h-icon'; export const treeRow = (onCollapse: OnTreeRowCollapse, onCheckChange?: OnCheckChange, onToggleRowDetails?: OnToggleRowDetails) => (value: IFormatterValueType, { rowIndex, rowData }: IExtra) => { const { isExpanded, isDetailsExpanded, 'aria-level': level, 'aria-setsize': setsize, toggleAriaLabel, checkAriaLabel, showDetailsAriaLabel, isChecked, checkboxId, icon } = rowData.props; const content = value.title || value; const text = (
{icon && ( {icon} )} {content as React.ReactNode}
); const onChange = (isChecked: boolean, event: React.FormEvent) => { onCheckChange(event, isChecked, rowIndex, content as React.ReactNode, rowData); }; return { component: 'th', className: stylesTreeView.tableTreeViewTitleCell, children: level !== undefined ? (
{setsize > 0 && (
)} {!!onCheckChange && ( onChange(checked, event)} /> )} {text} {!!onToggleRowDetails && (
)}
) : ( text ) };