Skip to content

Commit a74a5bf

Browse files
authored
Merge pull request #9 from tableflowhq/feature/stepper-styles
Adjusted stepper styles and added rowClick to the Table component
2 parents 5283aed + 70dec9c commit a74a5bf

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

src/Stepper/style/Stepper.module.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
&:not(:first-of-type) {
4545
&:before {
4646
content: "";
47-
height: 2px;
48-
width: min(140px, 10vw);
47+
height: 1px;
48+
width: min(140px, 4vw);
4949
background-color: var(--color-border);
5050
border-radius: 2px;
5151
margin-right: var(--m-xs);
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { ComponentMeta, ComponentStory } from "@storybook/react";
2+
import { StepperProps } from ".";
3+
import Stepper from "..";
4+
5+
const steps = [
6+
{ label: "Upload", id: "upload" },
7+
{ label: "Select Header Row", id: "row-selection" },
8+
{ label: "Review", id: "review" },
9+
{ label: "Complete", id: "complete" },
10+
];
11+
12+
export default {
13+
title: "User Interface/Stepper",
14+
component: Stepper,
15+
argTypes: {},
16+
} as ComponentMeta<typeof Stepper>;
17+
18+
const Template: ComponentStory<typeof Stepper> = (args: StepperProps) => {
19+
return (
20+
<div style={{ textAlign: "left" }}>
21+
<Stepper {...args} />
22+
</div>
23+
);
24+
};
25+
26+
export const Default = Template.bind({});
27+
Default.args = {
28+
steps,
29+
};

src/Table/Table.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ Table.args = {
2424
hideColumns: ["id"],
2525
fixHeader: true,
2626
};
27+
Table.args.onRowClick = (row: any) => console.log("Row clicked", row);

src/Table/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default function Table({
1818
columnWidths = [],
1919
columnAlignments = [],
2020
fixHeader = false,
21+
onRowClick,
2122
}: TableProps): React.ReactElement {
2223
// THEME
2324
// Tables receive a full CSS module as theme or applies default styles
@@ -60,7 +61,7 @@ export default function Table({
6061
<div className={style.tbody} role="rowgroup">
6162
{data.map((d, i) => {
6263
const key = keyAsId && d?.[keyAsId] ? d[keyAsId] : i;
63-
const props = { datum: d };
64+
const props = { datum: d, onClick: onRowClick };
6465
return <Row {...props} key={key?.toString()} />;
6566
})}
6667
</div>
@@ -74,13 +75,13 @@ export default function Table({
7475
);
7576
}
7677

77-
const Row = ({ datum }: RowProps) => {
78+
const Row = ({ datum, onClick }: RowProps) => {
7879
const { style, highlightColumns, hideColumns, columnWidths, columnAlignments } = useContext(TableContext);
7980

8081
const className = classes([style?.tr]);
8182

8283
return (
83-
<div className={className} role="row">
84+
<div className={className} role="row" onClick={() => onClick?.(datum)}>
8485
{Object.keys(datum)
8586
.filter((k) => !hideColumns.includes(datum[k]) && !hideColumns.includes(k))
8687
.map((k, i) => {

src/Table/types/index.ts

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

3637
export type RowProps = {
3738
datum: TableDatum;
3839
isHeading?: boolean;
40+
onClick?: (row: TableDatum) => void;
3941
};
4042

4143
export type CellProps = PropsWithChildren<{

0 commit comments

Comments
 (0)