Skip to content
Merged
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
33 changes: 33 additions & 0 deletions e2e/nextjs-app/src/app/components/table/basic.e2e.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use client";
import { Table } from "@lifesg/react-design-system/table";

export default function Story() {
return (
<Table data-testid="table">
<Table.Head>
<Table.Row>
<Table.HeaderCell>Name</Table.HeaderCell>
<Table.HeaderCell>Email</Table.HeaderCell>
<Table.HeaderCell>Status</Table.HeaderCell>
</Table.Row>
</Table.Head>
<Table.Body>
<Table.Row data-testid="row-1">
<Table.Cell>Alice Tan</Table.Cell>
<Table.Cell>alice@example.com</Table.Cell>
<Table.Cell>Active</Table.Cell>
</Table.Row>
<Table.Row data-testid="row-2">
<Table.Cell>Bob Lim</Table.Cell>
<Table.Cell>bob@example.com</Table.Cell>
<Table.Cell>Inactive</Table.Cell>
</Table.Row>
<Table.Row data-testid="row-3">
<Table.Cell>Carol Wong</Table.Cell>
<Table.Cell>carol@example.com</Table.Cell>
<Table.Cell>Pending</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use client";
import { Table } from "@lifesg/react-design-system/table";
import styles from "./table.module.css";

export default function Story() {
return (
<div className={styles["table-overflow"]}>
<Table data-testid="table">
<Table.Head>
<Table.Row>
<Table.HeaderCell>First name</Table.HeaderCell>
<Table.HeaderCell>Last name</Table.HeaderCell>
<Table.HeaderCell>Email address</Table.HeaderCell>
<Table.HeaderCell>Department</Table.HeaderCell>
<Table.HeaderCell>Status</Table.HeaderCell>
</Table.Row>
</Table.Head>
<Table.Body>
<Table.Row>
<Table.Cell>Alice</Table.Cell>
<Table.Cell>Tan</Table.Cell>
<Table.Cell>alice@example.com</Table.Cell>
<Table.Cell>Engineering</Table.Cell>
<Table.Cell>Active</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>Bob</Table.Cell>
<Table.Cell>Lim</Table.Cell>
<Table.Cell>bob@example.com</Table.Cell>
<Table.Cell>Design</Table.Cell>
<Table.Cell>Inactive</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
</div>
);
}
7 changes: 7 additions & 0 deletions e2e/nextjs-app/src/app/components/table/table.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.table-overflow {
width: 400px;
}

.table-vertical-overflow {
max-height: 200px;
}
33 changes: 33 additions & 0 deletions e2e/nextjs-app/src/app/components/table/vertical-overflow.e2e.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use client";
import { Table } from "@lifesg/react-design-system/table";
import styles from "./table.module.css";

export default function Story() {
return (
<Table.Container
data-testid="table-wrapper"
className={styles["table-vertical-overflow"]}
>
<Table.Table data-testid="table">
<Table.Head>
<Table.Row>
<Table.HeaderCell>Name</Table.HeaderCell>
<Table.HeaderCell>Email</Table.HeaderCell>
<Table.HeaderCell>Status</Table.HeaderCell>
</Table.Row>
</Table.Head>
<Table.Body>
{Array.from({ length: 10 }).map((_, i) => (
<Table.Row key={i} data-testid={`row-${i + 1}`}>
<Table.Cell>User {i + 1}</Table.Cell>
<Table.Cell>user{i + 1}@example.com</Table.Cell>
<Table.Cell>
{i % 2 === 0 ? "Active" : "Inactive"}
</Table.Cell>
</Table.Row>
))}
</Table.Body>
</Table.Table>
</Table.Container>
);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 107 additions & 0 deletions e2e/tests/components/table/table.e2e.spec.ts
Comment thread
qroll marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { test as base, expect, Locator, Page } from "@playwright/test";
import { AbstractStoryPage, compareScreenshot } from "../../utils";

class StoryPage extends AbstractStoryPage {
protected readonly component = "table";

public readonly locators: {
table: Locator;
tableWrapper: Locator;
};

constructor(page: Page) {
super(page);

this.locators = {
table: page.getByTestId("table"),
tableWrapper: page.getByTestId("table-wrapper"),
};
}
}

const test = base.extend<{ story: StoryPage }>({
story: async ({ page }, use) => {
const story = new StoryPage(page);
await use(story);
},
});

test.describe("Table", () => {
test.describe(() => {
test.beforeEach(async ({ story }) => {
await story.init("basic");
});

test("Default table", async ({ story }) => {
await compareScreenshot(story, "mount");

await expect(story.locators.table).toMatchAriaSnapshot(`
- table:
- rowgroup:
- row "Name Email Status":
- columnheader "Name"
- columnheader "Email"
- columnheader "Status"
- rowgroup:
- row "Alice Tan alice@example.com Active":
- cell "Alice Tan"
- cell "alice@example.com"
- cell "Active"
- row "Bob Lim bob@example.com Inactive":
- cell "Bob Lim"
- cell "bob@example.com"
- cell "Inactive"
- row "Carol Wong carol@example.com Pending":
- cell "Carol Wong"
- cell "carol@example.com"
- cell "Pending"
`);
});
});

test.describe(() => {
test.beforeEach(async ({ story }) => {
await story.init("basic", { mode: "dark" });
});

test("Default table (dark mode)", async ({ story }) => {
await compareScreenshot(story, "mount");
});
});

test.describe(() => {
test.beforeEach(async ({ story }) => {
await story.init("horizontal-overflow");
});

test("Horizontal overflow scrollable table", async ({ story }) => {
await compareScreenshot(story, "mount");
});

test("Table can be scrolled horizontally", async ({ story }) => {
await story.locators.tableWrapper.hover();
await story.page.mouse.wheel(200, 0);
await compareScreenshot(story, "scrolled", {
locator: story.locators.tableWrapper,
});
});
Comment thread
qroll marked this conversation as resolved.
});

test.describe(() => {
test.beforeEach(async ({ story }) => {
await story.init("vertical-overflow");
});

test("Vertical overflow scrollable table", async ({ story }) => {
await compareScreenshot(story, "mount");
});

test("Table can be scrolled vertically", async ({ story }) => {
await story.locators.tableWrapper.hover();
await story.page.mouse.wheel(0, 200);
await compareScreenshot(story, "scrolled", {
locator: story.locators.tableWrapper,
});
});
});
});
79 changes: 79 additions & 0 deletions src/table/table.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { css } from "@linaria/core";

import { Border, Colour, Radius, Spacing } from "../theme";

// =============================================================================
// STYLES CONSTANTS
// =============================================================================
const borderColor = Colour["border"];
const fontColor = Colour["text"];

// =============================================================================
// STYLES
// =============================================================================
export const tableWrapper = css`
overflow: auto;
border: ${Border["width-010"]} ${Border["solid"]} ${borderColor};
border-radius: ${Radius["md"]};

/* Hide scrollbar */
&::-webkit-scrollbar {
display: none;
}
* {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}
`;

export const tableComponent = css`
text-align: left;
border-collapse: separate;
border-spacing: 0;
width: 100%;
`;

export const tableBody = css`
:where(tr:last-child) {
td {
border-bottom: none;
}
}
`;

export const headerCell = css`
padding: ${Spacing["spacing-20"]} ${Spacing["spacing-16"]};
text-align: left;
cursor: default;
vertical-align: middle;
color: ${fontColor};
background-color: ${Colour["bg-stronger"]};
height: 6rem;
border-bottom: ${Border["width-010"]} ${Border["solid"]} ${borderColor};

&:where(&:first-child) {
padding-left: ${Spacing["spacing-24"]};
}
&:where(&:last-child) {
padding-right: ${Spacing["spacing-24"]};
}
`;

export const bodyRow = css`
background-color: ${Colour["bg"]};
border-top: ${Border["width-010"]} ${Border["solid"]} ${borderColor};
`;
Comment thread
zhaoyanxzy marked this conversation as resolved.

export const bodyCell = css`
padding: ${Spacing["spacing-20"]} ${Spacing["spacing-16"]};
vertical-align: middle;
color: ${fontColor};
border-bottom: ${Border["width-010"]} ${Border["solid"]} ${borderColor};

&:where(&:first-child) {
padding-left: ${Spacing["spacing-24"]};
}
&:where(&:last-child) {
padding-right: ${Spacing["spacing-24"]};
}
`;
85 changes: 0 additions & 85 deletions src/table/table.styles.tsx

This file was deleted.

Loading