Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support rowspan and table with border style #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions packages/apsara-ui/src/TableV2/Table.styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { textStyles } from "../mixin";

export const StyledTable = styled.div<{
height?: string;
disableHover?: boolean;
borderStyle?: string;
}>`
${({ height }) =>
height &&
`
height: ${height};
`}
overflow-y: auto;

table {
background: transparent;
background-color: ${({ theme }) => theme?.table?.bg};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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 {
Expand Down
46 changes: 34 additions & 12 deletions packages/apsara-ui/src/TableV2/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,14 +36,16 @@ 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;
rowClick?: (props: any) => any;
isLoading?: boolean;
height?: string;
enableRowSelection?: boolean;
disableHover?: boolean;
borderStyle?: "default" | "contained";
}

function Table({
Expand All @@ -54,6 +64,8 @@ function Table({
alternate = false,
alternateHover = false,
enableRowSelection = false,
disableHover = false,
borderStyle = "default",
}: ITableProps) {
const columns: any[] = [];
const columnHelper = createColumnHelper();
Expand Down Expand Up @@ -153,6 +165,8 @@ function Table({
<StyledTable
className={`${alternate ? "alternate" : ""} ${alternateHover ? "alternate-hover" : ""}`}
height={height}
disableHover={disableHover}
borderStyle={borderStyle}
>
<TableWrapper className="apsara-table-content">
<table>
Expand Down Expand Up @@ -219,17 +233,25 @@ function Table({
}}
className={row.getIsSelected() ? "selected" : ""}
>
{row.getVisibleCells().map((cell) => (
<td
key={cell.id}
style={{
width:
cell.column.getSize() !== 150 ? cell.column.getSize() : undefined,
}}
>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</td>
))}
{row.getVisibleCells().map((cell) => {
const value = (row.original as any)[cell.column.id] as any;
if (value?.isSpanned) return null;

return (
<td
key={cell.id}
style={{
width:
cell.column.getSize() !== 150
? cell.column.getSize()
: undefined,
}}
rowSpan={value?.rowSpan || undefined}
>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</td>
);
})}
</tr>
))}
{!table.getRowModel().rows.length && !isLoading && (
Expand Down