@typeolymp/ui-components 1.18.6 → 1.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,20 @@
1
1
  import { FC, ReactNode } from "react";
2
+ export declare type ColumnType = {
3
+ title?: string;
4
+ dataIndex: string;
5
+ render?(value: any, row: any): ReactNode;
6
+ align?: "left" | "right" | "center";
7
+ };
8
+ export declare type DataType = {
9
+ key: string;
10
+ [key: string]: any;
11
+ };
2
12
  export declare type PropsType = {
3
- columns: Array<{
4
- title?: string;
5
- dataIndex: string;
6
- render?(value: any, row: any): ReactNode;
7
- align?: "left" | "right" | "center";
8
- }>;
9
- data: Array<{
10
- [key: string]: any;
11
- }>;
13
+ columns: ColumnType[];
14
+ data: DataType[];
15
+ rowSelection?: {
16
+ onChange(selectedRowKeys: string[], selectedRowKey: string, selectedRows: DataType[], selectedRow: DataType): void;
17
+ };
12
18
  empytText?: string;
13
19
  };
14
20
  declare const Table: FC<PropsType>;
package/build/index.es.js CHANGED
@@ -48230,16 +48230,36 @@ var EmptyTableCell = styled.td(templateObject_8 || (templateObject_8 = __makeTem
48230
48230
  var templateObject_1$1, templateObject_2$1, templateObject_3$1, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8;
48231
48231
 
48232
48232
  var Table = function (_a) {
48233
- var columns = _a.columns, data = _a.data, empytText = _a.empytText;
48234
- return (jsxs(Container$1, { children: [jsx$1(TableHead, { children: jsx$1(TableRow, { children: columns.map(function (_a, index) {
48235
- var title = _a.title, dataIndex = _a.dataIndex;
48236
- return (jsx$1(ColumnTitle, { children: title && (jsx$1(Heading, __assign$2({ type: "h6", as: "span" }, { children: title }))) }, "".concat(dataIndex, "-").concat(index)));
48237
- }) }) }), jsx$1(TableBody, { children: data.length === 0 ? (jsx$1(TableRow, { children: jsx$1(EmptyTableCell, __assign$2({ colSpan: columns.length }, { children: jsx$1(Paragraph, __assign$2({ align: "center", size: "small", weight: "regular" }, { children: empytText || "No data" })) })) })) : (data.map(function (row, index) {
48238
- return (jsx$1(TableRow, { children: columns.map(function (_a, index) {
48239
- var dataIndex = _a.dataIndex, render = _a.render, align = _a.align;
48240
- var data = row[dataIndex];
48241
- return (jsx$1(TableCell, __assign$2({ align: align }, { children: render ? render(data, row) : data }), "col-".concat(index)));
48242
- }) }, "row-".concat(index)));
48233
+ var columns = _a.columns, data = _a.data, empytText = _a.empytText, rowSelection = _a.rowSelection;
48234
+ var _b = useState([]), selectedRowKeys = _b[0], setSelectedRowKeys = _b[1];
48235
+ var onSelectRow = function (selectedKey) {
48236
+ var index = selectedRowKeys.indexOf(selectedKey);
48237
+ var newSelectedRowKeys = __spreadArray([], selectedRowKeys, true);
48238
+ if (index === -1)
48239
+ newSelectedRowKeys.push(selectedKey);
48240
+ else
48241
+ newSelectedRowKeys.splice(index, 1);
48242
+ setSelectedRowKeys(newSelectedRowKeys);
48243
+ var selectedRows = data.filter(function (_a) {
48244
+ var key = _a.key;
48245
+ return newSelectedRowKeys.includes(key);
48246
+ });
48247
+ var selectedRow = data.find(function (_a) {
48248
+ var key = _a.key;
48249
+ return key === selectedKey;
48250
+ });
48251
+ if (rowSelection && rowSelection.onChange)
48252
+ rowSelection.onChange(newSelectedRowKeys, selectedKey, selectedRows, selectedRow);
48253
+ };
48254
+ return (jsxs(Container$1, { children: [jsx$1(TableHead, { children: jsxs(TableRow, { children: [rowSelection && jsx$1("th", { style: { width: 55 } }), columns.map(function (_a, index) {
48255
+ var title = _a.title, dataIndex = _a.dataIndex;
48256
+ return (jsx$1(ColumnTitle, { children: title && (jsx$1(Heading, __assign$2({ type: "h6", as: "span" }, { children: title }))) }, "".concat(dataIndex, "-").concat(index)));
48257
+ })] }) }), jsx$1(TableBody, { children: data.length === 0 ? (jsx$1(TableRow, { children: jsx$1(EmptyTableCell, __assign$2({ colSpan: columns.length }, { children: jsx$1(Paragraph, __assign$2({ align: "center", size: "small", weight: "regular" }, { children: empytText || "No data" })) })) })) : (data.map(function (row, rowIndex) {
48258
+ return (jsxs(TableRow, { children: [rowSelection && (jsx$1(TableCell, { children: jsx$1(Checkbox, { id: "".concat(rowIndex), name: "".concat(rowIndex), value: row.key, onChange: onSelectRow }) }, "row-select-".concat(rowIndex))), columns.map(function (_a, colIndex) {
48259
+ var dataIndex = _a.dataIndex, render = _a.render, align = _a.align;
48260
+ var data = row[dataIndex];
48261
+ return (jsx$1(TableCell, __assign$2({ align: align }, { children: render ? render(data, row) : data }), "col-".concat(colIndex)));
48262
+ })] }, "row-".concat(rowIndex)));
48243
48263
  })) })] }));
48244
48264
  };
48245
48265