diff --git a/packages/apsara-ui/src/TableV2/Table.styles.tsx b/packages/apsara-ui/src/TableV2/Table.styles.tsx index ad175483..f990d4ee 100644 --- a/packages/apsara-ui/src/TableV2/Table.styles.tsx +++ b/packages/apsara-ui/src/TableV2/Table.styles.tsx @@ -3,6 +3,8 @@ import { textStyles } from "../mixin"; export const StyledTable = styled.div<{ height?: string; + disableHover?: boolean; + borderStyle?: string; }>` ${({ height }) => height && @@ -10,7 +12,7 @@ export const StyledTable = styled.div<{ height: ${height}; `} overflow-y: auto; - + table { background: transparent; background-color: ${({ theme }) => theme?.table?.bg}; @@ -45,7 +47,7 @@ export const StyledTable = styled.div<{ text-transform: capitalize; } - .virtual-table-cell{ + .virtual-table-cell { align-items: center; height: 48px; white-space: nowrap; @@ -129,8 +131,8 @@ export const StyledTable = styled.div<{ word-break: break-word; } - tr.apsara-table-placeholder > td:first-child{ - color: rgba(0,0,0,.25); + tr.apsara-table-placeholder > td:first-child { + color: rgba(0, 0, 0, 0.25); } tr > th, @@ -146,9 +148,9 @@ export const StyledTable = styled.div<{ a { display: block; color: unset; - text-decoration: none; - &:only-child{ - width:100%; + text-decoration: none; + &:only-child { + width: 100%; } white-space: nowrap; overflow: hidden; @@ -159,22 +161,39 @@ export const StyledTable = styled.div<{ } } - tr:hover { - td > a { - color: rgb(30, 122, 232) !important; + ${({ borderStyle, theme }) => + borderStyle === "contained" && + ` + tr > td { + border: 1px solid ${theme?.table?.border}; + } + `} + + ${({ disableHover }) => + !disableHover && + ` + tr:hover { + td > a { + color: rgb(30, 122, 232) !important; + } } } - } + `} tbody { border-bottom: 1px solid lightgray; + vertical-align: top; - tr:not(.selected):hover > td { - background: ${({ theme }) => theme?.table?.highlight}; - } + ${({ disableHover, theme }) => + !disableHover && + ` + tr:not(.selected):hover > td { + background: ${theme?.table?.highlight}; + } + `} tr.selected { background-color: ${({ theme }) => theme?.table?.selectedRowHighlight}; - } + } } th { diff --git a/packages/apsara-ui/src/TableV2/Table.tsx b/packages/apsara-ui/src/TableV2/Table.tsx index 8baf0175..27e920e4 100644 --- a/packages/apsara-ui/src/TableV2/Table.tsx +++ b/packages/apsara-ui/src/TableV2/Table.tsx @@ -17,6 +17,14 @@ import { StyledEmpty } from "../Table/Table.styles"; import { ListSkeleton } from "../Skeleton"; import Empty from "./Empty"; +type CellValue = + | any + | { + value: any; + rowSpan?: number; + isSpanned: boolean; + }; + interface ITableProps { selectedRowId?: number | null; alternate?: boolean; @@ -28,7 +36,7 @@ interface ITableProps { paginate?: boolean; fullPagination?: boolean; showPageSizeChanger?: boolean; - items?: any[]; + items?: CellValue[]; totalItems?: number; setPage?: (page: number, pageSize: number) => any; dataFetchFunction?: (options: { pageIndex?: number; pageSize?: number }) => any; @@ -36,6 +44,8 @@ interface ITableProps { isLoading?: boolean; height?: string; enableRowSelection?: boolean; + disableHover?: boolean; + borderStyle?: "default" | "contained"; } function Table({ @@ -54,6 +64,8 @@ function Table({ alternate = false, alternateHover = false, enableRowSelection = false, + disableHover = false, + borderStyle = "default", }: ITableProps) { const columns: any[] = []; const columnHelper = createColumnHelper(); @@ -153,6 +165,8 @@ function Table({ @@ -219,17 +233,25 @@ function Table({ }} className={row.getIsSelected() ? "selected" : ""} > - {row.getVisibleCells().map((cell) => ( - - ))} + {row.getVisibleCells().map((cell) => { + const value = (row.original as any)[cell.column.id] as any; + if (value?.isSpanned) return null; + + return ( + + ); + })} ))} {!table.getRowModel().rows.length && !isLoading && (
- {flexRender(cell.column.columnDef.cell, cell.getContext())} - + {flexRender(cell.column.columnDef.cell, cell.getContext())} +