Skip to content

Commit 41ab5b4

Browse files
authored
Merge pull request #1258 from inplayer-org/change/add-table-buttons
Change/add table buttons
2 parents 74ea26f + 4e981a4 commit 41ab5b4

File tree

4 files changed

+45
-20
lines changed

4 files changed

+45
-20
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
# [2.4.3] - 15-11-2020
6+
7+
### Changes
8+
9+
- Add the possibility to have more than one table button
10+
511
# [2.5.0] - 12-01-2021
612
### Changes
713

index.d.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ export interface TableOptions<T extends TableRowData> {
147147
headerSection?: Node | JSX.Element | null;
148148
}
149149

150+
export interface TableButtonProps {
151+
label: string;
152+
icon?: string | ReactNode;
153+
onClick: (e: SyntheticEvent) => any;
154+
type: string;
155+
};
156+
150157
export interface TableProps<TableData extends TableRowData = TableRowData> {
151158
columns: Array<TableColumn<TableData>>;
152159
data: Array<TableData>;
@@ -155,12 +162,7 @@ export interface TableProps<TableData extends TableRowData = TableRowData> {
155162
className?: string;
156163
style?: CSSProperties;
157164
options?: Partial<TableOptions<TableData>>;
158-
tableButton?: {
159-
label: string;
160-
icon?: string | Node | JSX.Element;
161-
onClick: (e: SyntheticEvent) => any;
162-
type: string;
163-
};
165+
tableButton?: Array<TableButtonProps>;
164166
actionsRowTitle?: string;
165167
}
166168

src/components/Table/Table.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ type TableOptions<T> = {
5252
};
5353

5454
// eslint-disable-next-line @typescript-eslint/no-use-before-define
55+
type TableButtonProps = {
56+
label: string;
57+
icon?: string | ReactNode;
58+
onClick: (e: SyntheticEvent) => any;
59+
type: string;
60+
};
61+
5562
type Props<T = Data> = {
5663
columns: Array<Column> | any;
5764
data: Array<any>;
@@ -60,12 +67,7 @@ type Props<T = Data> = {
6067
options: TableOptions<T>;
6168
showLoader?: boolean;
6269
renderEmptyTable?: boolean;
63-
tableButton?: {
64-
label: string;
65-
icon?: string | Node;
66-
onClick: (e: SyntheticEvent) => any;
67-
type: string;
68-
};
70+
tableButton?: Array<TableButtonProps>;
6971
actionsRowTitle?: string;
7072
};
7173

@@ -94,7 +96,7 @@ class Table<T> extends Component<Props<T>, State> {
9496
},
9597
showLoader: false,
9698
renderEmptyTable: false,
97-
tableButton: null,
99+
tableButton: [],
98100
actionsRowTitle: 'Actions',
99101
};
100102

@@ -264,23 +266,23 @@ class Table<T> extends Component<Props<T>, State> {
264266
</thead>
265267
<tbody>{this.renderData(columns, data)}</tbody>
266268
<tfoot>
267-
{tableButton && (
268-
<ButtonTableRow>
269+
{tableButton?.map((button: TableButtonProps) => (
270+
<ButtonTableRow key={button.label}>
269271
<TableCell colSpan={columnContent.length}>
270272
<TableButton
271273
modifiers={['buttonLink']}
272274
fullWidth
273275
fullHeight
274-
onClick={tableButton.onClick}
275-
icon={tableButton.icon}
276+
onClick={button.onClick}
277+
icon={button.icon}
276278
iconPosition="left"
277-
type={tableButton.type}
279+
type={button.type}
278280
>
279-
{tableButton.label}
281+
{button.label}
280282
</TableButton>
281283
</TableCell>
282284
</ButtonTableRow>
283-
)}
285+
))}
284286
</tfoot>
285287
</TableWrapper>
286288
);

src/components/Table/table.stories.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Table from './'
44
import { MdDelete, MdErrorOutline } from 'react-icons/md';
55
import Pagination from '../Pagination'
66
import { columns, data } from './data.tsx'
7+
import { IoIosAddCircleOutline } from 'react-icons/io';
78

89
<Meta title="Table" component={<Table/>} />
910

@@ -32,6 +33,20 @@ const Page = () => (
3233
{ icon: "trash", onClick: (id) => console.log(id) },
3334
],
3435
}}
36+
tableButton={[
37+
{
38+
label: 'Table button 1',
39+
icon: <IoIosAddCircleOutline />,
40+
onClick: () => null,
41+
type: 'button',
42+
},
43+
{
44+
label: 'Table button 2',
45+
icon: <IoIosAddCircleOutline />,
46+
onClick: () => null,
47+
type: 'button',
48+
}
49+
]}
3550
/>
3651
<Pagination
3752
onPageChange={console.log}

0 commit comments

Comments
 (0)