import React, { useMemo } from 'react'; import { Scrollbars } from 'react-custom-scrollbars'; import { Wrapper } from '@geenee/ui/src/lib/component/wrapper/wrapper.component'; import { DataRow } from './components/DataRow'; import { TableHeader } from './components/TableHeader'; import { BorderLine, ColumnContainer, RowContainer, TableContainer } from './styles'; export type StyledTableColumns = { key: string; label: string | JSX.Element; render?: (item: T) => JSX.Element; onClick?: (val: string | number | boolean | T) => void | Promise; width?: string; className?: string; } export enum TableActionName { Remove = 'remove', Edit = 'edit2' } type StyledTableProps = { columns: StyledTableColumns[]; data: T[]; rowActions?: { id: TableActionName; onClick: (item: T) => void }[]; preTableRow?: JSX.Element; tableWidth?: string; styles?: { row: React.CSSProperties; }; minWidth?: string; tableBottomContent?: JSX.Element; scrollHeight?: string; disabled?: boolean; emptyContent?: JSX.Element; } export function StyledTable({ columns, data, rowActions, disabled, emptyContent, preTableRow, tableWidth, styles, minWidth, tableBottomContent, scrollHeight = '80%' }: StyledTableProps): JSX.Element { const tableContent = useMemo(() => { if (!data.length) { return emptyContent || ( List is empty ); } return ( data.map((item, index) => ( { index ? : <> } row={ item } columns={ columns } rowActions={ rowActions } style={ styles?.row } /> )) ); }, [ data ]); return ( { preTableRow || null } { tableContent } { tableBottomContent } ); }