Skip to content

Commit

Permalink
feat(table): Add empty state for table
Browse files Browse the repository at this point in the history
  • Loading branch information
saescapa committed Mar 21, 2024
1 parent f59a223 commit 9c1955b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-toes-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"paris": patch
---

Add emptyState render for Table when there are no rows to display
8 changes: 8 additions & 0 deletions src/stories/table/Table.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
border-bottom: 1px solid var(--pte-colors-borderOpaque);
}

tr.empty {
border-bottom: none;

td {
padding: 20px 0 0 0;
}
}

tbody tr.clickable {
transition: background-color var(--pte-animations-interaction);

Expand Down
15 changes: 15 additions & 0 deletions src/stories/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export type TableProps<
* Whether the rows should be clickable.
*/
clickableRows?: boolean;

/**
* The content to display when the table is empty.
*/
emptyState?: ReactNode;
/**
* Prop overrides for rendered elements.
*/
Expand Down Expand Up @@ -87,6 +92,7 @@ export function Table<RowData extends Record<string, any>[]>({
rowRenderFn,
onRowClick,
clickableRows = true,
emptyState,
overrides,
}: TableProps<RowData>) {
const id = useId();
Expand Down Expand Up @@ -164,6 +170,15 @@ export function Table<RowData extends Record<string, any>[]>({
</tr>
</thead>
<tbody {...overrides?.tbody}>
{renderedRows.length === 0 && emptyState && (
<>
<tr className={styles.empty}>
<td colSpan={columns.length} className={styles.emptyState}>
{emptyState}
</td>
</tr>
</>
)}
{renderedRows}
</tbody>
</table>
Expand Down

0 comments on commit 9c1955b

Please sign in to comment.