Skip to content

Added Horizontal scroll version of the table component #13

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

Open
wants to merge 4 commits 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
13 changes: 12 additions & 1 deletion src/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentMeta, ComponentStory } from "@storybook/react";
import TableComponent from ".";
import { TableProps } from "./types";
import storyData from "./storyData";
import { storyData, storyDataTwo } from "./storyData";

export default {
title: "User Interface/Table",
Expand All @@ -24,4 +24,15 @@ Table.args = {
hideColumns: ["id"],
fixHeader: true,
};

export const TableVScroll = Template.bind({});
TableVScroll.args = {
data: storyDataTwo,
highlightColumns: ["Name"],
hideColumns: ["id"],
fixHeader: true,
heading: <div style={{ textAlign: "center" }}>Header row</div>,
hasScrollX: true,
};

Table.args.onRowClick = (row: any) => console.log("Row clicked", row);
3 changes: 2 additions & 1 deletion src/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default function Table({
columnWidths = [],
columnAlignments = [],
fixHeader = false,
hasScrollX,
onRowClick,
}: TableProps): React.ReactElement {
// THEME
Expand Down Expand Up @@ -73,7 +74,7 @@ export default function Table({
<div className={tableStyle} role="table">
{headingContent}

<div className={style.tbody} role="rowgroup">
<div className={classes([style.tbody, hasScrollX && style.horizontalScroll])} role="rowgroup">
{data.map((d, i) => {
const key = keyAsId && d?.[keyAsId] ? d[keyAsId] : i;
const props = { datum: d, onClick: onRowClick };
Expand Down
37 changes: 35 additions & 2 deletions src/Table/storyData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const storyData = [
export const storyData = [
{
id: 1,
Name: {
Expand Down Expand Up @@ -131,4 +131,37 @@ const storyData = [
},
];

export default storyData;
export const storyDataTwo = [
{
id: 1,
firstName: "First Name First Name",
lastName: "Last name Last name",
phone: "(555) 555-5555",
homePhone: "(+9) 123-12345",
postalCode: "12345 own",
email: "[email protected]",
secondEmail: "[email protected]",
address: "123 Main St",
city: "Des Moines",
country: "Des mones",
State: "IA 1234",
zipCode: "12355",
owner: "Owner Owner",
},
{
id: 1,
firstName: "First Name First Name",
lastName: "Last name Last name",
phone: "(555) 555-5555",
homePhone: "(+9) 123-12345",
postalCode: "12345 own",
email: "[email protected]",
secondEmail: "[email protected]",
address: "123 Main St",
city: "Des Moines",
country: "Des mones",
State: "IA 1234",
zipCode: "12355",
owner: "Owner Owner",
},
];
5 changes: 5 additions & 0 deletions src/Table/style/Default.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ $radius: var(--border-radius-2);
}
}
}

.horizontalScroll {
display: table-cell;
overflow-x: auto;
}
}

.emptyMsg {
Expand Down
1 change: 1 addition & 0 deletions src/Table/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export type TableProps = {
columnWidths?: string[];
columnAlignments?: ("left" | "center" | "right" | "")[];
fixHeader?: boolean;
hasScrollX?: boolean;
onRowClick?: (row: TableDatum) => void;
};

Expand Down