Skip to content

Commit 68d8139

Browse files
committed
[#23] - [TableFlow] Add horizontal scrolling to "Select Header" preview table
resolves #23
1 parent e802cdb commit 68d8139

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

src/Table/Table.stories.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ComponentMeta, ComponentStory } from "@storybook/react";
22
import TableComponent from ".";
33
import { TableProps } from "./types";
4-
import storyData from "./storyData";
4+
import { storyData, storyDataTwo } from "./storyData";
55

66
export default {
77
title: "User Interface/Table",
@@ -24,4 +24,15 @@ Table.args = {
2424
hideColumns: ["id"],
2525
fixHeader: true,
2626
};
27+
28+
export const TableVScroll = Template.bind({});
29+
TableVScroll.args = {
30+
data: storyDataTwo,
31+
highlightColumns: ["Name"],
32+
hideColumns: ["id"],
33+
fixHeader: true,
34+
heading: <div style={{ textAlign: "center" }}>Header row</div>,
35+
hasScrollX: true,
36+
};
37+
2738
Table.args.onRowClick = (row: any) => console.log("Row clicked", row);

src/Table/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default function Table({
1818
columnWidths = [],
1919
columnAlignments = [],
2020
fixHeader = false,
21+
hasScrollX,
2122
onRowClick,
2223
}: TableProps): React.ReactElement {
2324
// THEME
@@ -58,7 +59,7 @@ export default function Table({
5859
<div className={tableStyle} role="table">
5960
{headingContent}
6061

61-
<div className={style.tbody} role="rowgroup">
62+
<div className={classes([style.tbody, hasScrollX && style.tVerticalScroll])} role="rowgroup">
6263
{data.map((d, i) => {
6364
const key = keyAsId && d?.[keyAsId] ? d[keyAsId] : i;
6465
const props = { datum: d, onClick: onRowClick };

src/Table/storyData.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const storyData = [
1+
export const storyData = [
22
{
33
id: 1,
44
Name: "John Doe",
@@ -127,4 +127,37 @@ const storyData = [
127127
},
128128
];
129129

130-
export default storyData;
130+
export const storyDataTwo = [
131+
{
132+
id: 1,
133+
firstName: "First Name First Name",
134+
lastName: "Last name Last name",
135+
phone: "(555) 555-5555",
136+
homePhone: "(+9) 123-12345",
137+
postalCode: "12345 own",
138+
email: "test@example.com",
139+
secondEmail: "testNumberTwo@example.com",
140+
address: "123 Main St",
141+
city: "Des Moines",
142+
country: "Des mones",
143+
State: "IA 1234",
144+
zipCode: "12355",
145+
owner: "Owner Owner",
146+
},
147+
{
148+
id: 1,
149+
firstName: "First Name First Name",
150+
lastName: "Last name Last name",
151+
phone: "(555) 555-5555",
152+
homePhone: "(+9) 123-12345",
153+
postalCode: "12345 own",
154+
email: "test@example.com",
155+
secondEmail: "testNumerTwo@example.com",
156+
address: "123 Main St",
157+
city: "Des Moines",
158+
country: "Des mones",
159+
State: "IA 1234",
160+
zipCode: "12355",
161+
owner: "Owner Owner",
162+
},
163+
];

src/Table/style/Default.module.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ $radius: var(--border-radius-2);
165165
}
166166
}
167167
}
168+
169+
.tVerticalScroll {
170+
display: table-cell;
171+
overflow-x: auto;
172+
}
168173
}
169174

170175
.emptyMsg {

src/Table/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export type TableProps = {
3131
columnWidths?: string[];
3232
columnAlignments?: ("left" | "center" | "right" | "")[];
3333
fixHeader?: boolean;
34+
hasScrollX?: boolean;
3435
onRowClick?: (row: TableDatum) => void;
3536
};
3637

0 commit comments

Comments
 (0)