Skip to content

Commit

Permalink
feat(Table): fixes after CR - part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Fracala authored and Artur Fracala committed Dec 9, 2024
1 parent 128d089 commit 0716e85
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 17 deletions.
10 changes: 6 additions & 4 deletions packages/react-components/src/components/Table/Table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import * as Stories from './Table.stories';

```jsx

import React from 'react';
import { Button, Column, Table } from '@livechat/design-system-react-components';

type Data = {
id: number;
name: string;
Expand Down Expand Up @@ -87,11 +90,10 @@ const data: Data[] = [
},
];

const getRowId = (row: Data) => row.id;
const getRowId = (row: Data) => row.id;

return (
<Table size="medium" data={data} columns={columns} getRowId={getRowId} />
);
<Table size="medium" data={data} columns={columns} getRowId={getRowId} />

```

## Component API <a id="ComponentAPI" />
Expand Down
12 changes: 0 additions & 12 deletions packages/react-components/src/components/Table/Table.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ const data: Data[] = [
describe('<Table> component', () => {
const getRowId = (row: Data) => row.id;

it('should render a table with provided data and columns', () => {
const { getByRole, getAllByRole } = render(
<Table data={data} columns={columns} getRowId={getRowId} />
);

const table = getByRole('table');
expect(table).toBeInTheDocument();

const rows = getAllByRole('row');
expect(rows.length).toBe(data.length + 1);
});

it('should allow row selection if selectable prop is enabled', () => {
const onSelectionChange = vi.fn();
const selectedRows = new Set<string>();
Expand Down
2 changes: 2 additions & 0 deletions packages/react-components/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const Table = <T,>({
onSelectionChange,
rowSelectionMessage,
rowActions,
testId,
}: ITableProps<T>) => {
const columnRefs = React.useRef<(HTMLTableCellElement | null)[]>([]);
const [hoveredColumnIndex, setHoveredColumnIndex] = React.useState<
Expand Down Expand Up @@ -183,6 +184,7 @@ export const Table = <T,>({
styles[`${baseClass}--pinned_${pin}`],
styles[`${baseClass}--stripped_${stripped}`]
)}
data-testid={testId}
>
<TableHeader
columns={columns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $base-class: 'header';
bottom: 0;
background-color: var(--border-basic-secondary);
cursor: col-resize;
width: 1px;
width: 2px;
height: 100%;

&:hover,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
background-color: var(--background-01);
}

tr:hover > td:first-child {
background-color: var(--surface-primary-hover);
}

tr > td:first-child::after,
th:first-child::after {
position: absolute;
Expand All @@ -30,6 +34,10 @@
content: '';
clip-path: inset(0 -15px 0 0);
}

tr:hover > td:first-child::after {
background-color: var(--surface-primary-hover);
}
}

@else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
tbody tr:hover td:nth-child(even) {
background-color: var(--surface-primary-hover);
}

thead tr th:nth-child(even) {
background-color: var(--surface-secondary-default);
}

thead tr:hover th:nth-child(even) {
background-color: var(--surface-primary-hover);
}
}

@else {
Expand Down
4 changes: 4 additions & 0 deletions packages/react-components/src/components/Table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export interface ITableProps<T> {
* such as "Delete All" or "Export."
*/
rowActions?: React.ReactNode;
/**
* Sets the `data-testid` attribute, allowing the table to be easily selected in automated tests.
*/
testId?: string;
}

export interface SortConfig<T> {
Expand Down

0 comments on commit 0716e85

Please sign in to comment.