import React, { useState, useEffect } from 'react' import { map, set } from 'lodash/fp' import classnames from 'classnames' import uuidv1 from 'uuid/v1' import { makeStyles } from '@material-ui/core/styles' import { Table, THead, Tr, TBody, Td, Th } from '../fake-table/Table' import { ReactComponent as ExpandClosedIcon } from '../../styling/icons/action/expand/closed.svg' import { ReactComponent as ExpandOpenIcon } from '../../styling/icons/action/expand/open.svg' import { mainWidth } from '../../styling/variables' const styles = { hideDetailsRow: { display: 'none' }, expandButton: { border: 'none', backgroundColor: 'transparent', cursor: 'pointer', padding: 4 } } const useStyles = makeStyles(styles) const ExpRow = ({ id, columns, details, sizes, expanded, className, expandRow, ...props }) => { const classes = useStyles() const detailsRowClasses = { [classes.detailsRow]: true, [classes.hideDetailsRow]: expanded } return ( <> {columns.map((col, idx) => ( {col.value} ))} {details} ) } /* headers = [{ value, className, textAlign }] * rows = [{ columns = [{ value, className, textAlign }], details, className, error, errorMessage }] */ const ExpTable = ({ headers = [], rows = [], sizes = [], className, ...props }) => { const [rowStates, setRowStates] = useState(null) useEffect(() => { setRowStates(rows && rows.map((x) => { return { id: x.id, expanded: false } })) }, [rows]) const expandRow = (id) => { setRowStates(map(r => set('expanded', r.id === id ? !r.expanded : false, r))) } return ( {headers.map((header, idx) => ( ))} {rowStates && rowStates.map((r, idx) => { const row = rows[idx] return ( ) })}
{header.value}
) } export default ExpTable