@gobolt/genesis 0.3.21 → 0.3.22

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.
Files changed (60) hide show
  1. package/dist/Table/Table.d.ts +51 -0
  2. package/dist/Table/Table.js +14 -0
  3. package/dist/Table/TableControls/CustomPagination.d.ts +13 -0
  4. package/dist/Table/TableControls/CustomPagination.js +158 -0
  5. package/dist/Table/TableControls/PaginationNumber.d.ts +7 -0
  6. package/dist/Table/TableControls/PaginationNumber.js +30 -0
  7. package/dist/Table/styles.d.ts +14 -0
  8. package/dist/Table/styles.js +64 -0
  9. package/dist/Table/useTable.d.ts +26 -0
  10. package/dist/Table/useTable.js +141 -0
  11. package/dist/Typography/Typography.d.ts +17 -0
  12. package/dist/Typography/Typography.js +16 -0
  13. package/dist/Typography/index.d.ts +2 -0
  14. package/dist/Typography/index.js +1 -0
  15. package/dist/Typography/styles.d.ts +3 -0
  16. package/dist/Typography/styles.js +54 -0
  17. package/dist/components/Badge/Badge.js +9 -32
  18. package/dist/components/Badge/styles.d.ts +1 -10
  19. package/dist/components/Badge/styles.js +39 -14
  20. package/dist/components/Button/Button.js +4 -27
  21. package/dist/components/Button/IconButton.js +4 -27
  22. package/dist/components/Button/icon-button-styles.d.ts +1 -12
  23. package/dist/components/Button/icon-button-styles.js +69 -16
  24. package/dist/components/Button/styles.d.ts +1 -16
  25. package/dist/components/Button/styles.js +88 -30
  26. package/dist/components/Input/Input.js +6 -29
  27. package/dist/components/Input/styles.d.ts +1 -18
  28. package/dist/components/Input/styles.js +146 -42
  29. package/dist/components/Select/Select.js +101 -125
  30. package/dist/components/Select/SelectTrigger.js +71 -57
  31. package/dist/components/Table/Table.js +8 -27
  32. package/dist/components/Table/TableControls/CustomPagination.js +50 -66
  33. package/dist/components/Table/TableControls/PaginationNumber.js +27 -43
  34. package/dist/components/Table/TableControls/PrimaryTableControlsRow.js +16 -17
  35. package/dist/components/Table/TableControls/SecondaryTableControlsRow.js +14 -36
  36. package/dist/components/Table/TableControls/TableControls.js +3 -4
  37. package/dist/components/Table/TablePagination.js +4 -21
  38. package/dist/components/Table/__mocks__/table-mocks.js +15 -24
  39. package/dist/components/Table/styles.d.ts +1 -15
  40. package/dist/components/Table/styles.js +57 -13
  41. package/dist/components/Table/useTable.js +69 -166
  42. package/dist/components/TableWithControls/TableWithControls.js +6 -7
  43. package/dist/components/TableWithControls/useTableWithControls.js +82 -63
  44. package/dist/components/Tooltip/Tooltip.js +1 -2
  45. package/dist/components/Tooltip/styles.d.ts +1 -14
  46. package/dist/components/Tooltip/styles.js +23 -14
  47. package/dist/components/Typography/Typography.js +6 -29
  48. package/dist/components/Typography/styles.d.ts +3 -21
  49. package/dist/components/Typography/styles.js +41 -24
  50. package/dist/components/UtilityButton/UtilityButton.js +4 -27
  51. package/dist/components/shared/DropdownChevron.js +3 -14
  52. package/dist/constants/index.js +14 -14
  53. package/dist/genesis-theme.types.d.ts +263 -0
  54. package/dist/genesis-theme.types.js +6 -0
  55. package/dist/index.js +89 -0
  56. package/dist/styled.d.ts +1 -0
  57. package/dist/styled.js +44 -0
  58. package/dist/utils/icon-util.d.ts +2 -2
  59. package/dist/utils/icon-util.js +16 -19
  60. package/package.json +1 -1
@@ -1,12 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import PrimaryTableControlsRow from "./PrimaryTableControlsRow";
3
3
  import SecondaryTableControlsRow from "./SecondaryTableControlsRow";
4
- var TableControls = function (_a) {
5
- var primaryTableRowData = _a.primaryTableRowData, secondaryTableRowData = _a.secondaryTableRowData, onChange = _a.onChange;
6
- var onPrimaryChange = function (actionEvent) {
4
+ const TableControls = ({ primaryTableRowData, secondaryTableRowData, onChange, }) => {
5
+ const onPrimaryChange = (actionEvent) => {
7
6
  onChange(actionEvent);
8
7
  };
9
- var onSecondaryChange = function (actionEvent) {
8
+ const onSecondaryChange = (actionEvent) => {
10
9
  onChange(actionEvent);
11
10
  };
12
11
  return (_jsxs("div", { "data-testid": "TableControls", style: { margin: "16px 0px" }, children: [_jsx(PrimaryTableControlsRow, { sortOptions: primaryTableRowData.sortOptions, searchByPlaceholder: primaryTableRowData.searchByPlaceholder, isSortedAscending: primaryTableRowData.isSortedAscending, onChange: onPrimaryChange, searchValue: primaryTableRowData.searchValue, selectedSortOption: primaryTableRowData.selectedSortOption }), secondaryTableRowData ? (_jsx(SecondaryTableControlsRow, { groups: secondaryTableRowData.groups, totalRecords: secondaryTableRowData.totalRecords, onChange: onSecondaryChange })) : null] }));
@@ -1,28 +1,11 @@
1
- var __read = (this && this.__read) || function (o, n) {
2
- var m = typeof Symbol === "function" && o[Symbol.iterator];
3
- if (!m) return o;
4
- var i = m.call(o), r, ar = [], e;
5
- try {
6
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
- }
8
- catch (error) { e = { error: error }; }
9
- finally {
10
- try {
11
- if (r && !r.done && (m = i["return"])) m.call(i);
12
- }
13
- finally { if (e) throw e.error; }
14
- }
15
- return ar;
16
- };
17
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
18
2
  import { useState } from "react";
19
3
  import Table from "./Table";
20
4
  import CustomPagination, { PaginationStyle, } from "./TableControls/CustomPagination";
21
- var TablePagination = function (_a) {
22
- var columns = _a.columns, dataSource = _a.dataSource, rowSelection = _a.rowSelection, onChange = _a.onChange, _b = _a.paginationStyle, paginationStyle = _b === void 0 ? PaginationStyle.SIMPLE : _b, _c = _a.pageSize, pageSize = _c === void 0 ? 10 : _c, isMainContentCell = _a.isMainContentCell;
23
- var _d = __read(useState(1), 2), current = _d[0], setCurrent = _d[1];
24
- var total = dataSource.length;
25
- var paginatedData = dataSource.slice((current - 1) * pageSize, current * pageSize);
5
+ const TablePagination = ({ columns, dataSource, rowSelection, onChange, paginationStyle = PaginationStyle.SIMPLE, pageSize = 10, isMainContentCell, }) => {
6
+ const [current, setCurrent] = useState(1);
7
+ const total = dataSource.length;
8
+ const paginatedData = dataSource.slice((current - 1) * pageSize, current * pageSize);
26
9
  return (_jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "0px" }, children: [_jsx(Table, { columns: columns, dataSource: paginatedData, rowSelection: rowSelection, onChange: onChange, pagination: false, isMainContentCell: isMainContentCell }), _jsx("div", { style: { display: "flex", justifyContent: "flex-end", marginTop: 16 }, children: _jsx(CustomPagination, { paginationStyle: paginationStyle, current: current, total: total, pageSize: pageSize, onChange: setCurrent }) })] }));
27
10
  };
28
11
  export default TablePagination;
@@ -1,26 +1,15 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
1
  import { Badge } from "@gobolt/genesis/components";
13
2
  import React from "react";
14
3
  // Helper function for title case
15
- var startCase = function (string_) {
4
+ const startCase = (string_) => {
16
5
  if (string_) {
17
6
  return string_
18
7
  .replaceAll(/([A-Z])/g, " $1")
19
- .replace(/^./, function (s) { return s.toUpperCase(); });
8
+ .replace(/^./, (s) => s.toUpperCase());
20
9
  }
21
10
  return string_;
22
11
  };
23
- export var mockColumns = [
12
+ export const mockColumns = [
24
13
  {
25
14
  key: "number",
26
15
  title: "Id",
@@ -35,13 +24,13 @@ export var mockColumns = [
35
24
  key: "status",
36
25
  title: "Status",
37
26
  dataIndex: "status",
38
- render: function (status) {
39
- var colorStateMap = {
27
+ render: (status) => {
28
+ const colorStateMap = {
40
29
  in_progress: "warning",
41
30
  scheduled: "generic",
42
31
  completed: "success",
43
32
  };
44
- var statusLabel = status === "in_progress" ? "in progress" : status;
33
+ const statusLabel = status === "in_progress" ? "in progress" : status;
45
34
  return React.createElement(Badge, {
46
35
  label: startCase(statusLabel),
47
36
  state: colorStateMap[status],
@@ -51,16 +40,16 @@ export var mockColumns = [
51
40
  {
52
41
  key: "address",
53
42
  title: "Address",
54
- render: function (appointment) {
55
- var _a = appointment.address, nickname = _a.nickname, address = _a.address;
56
- return nickname ? "".concat(nickname, " (").concat(address, ")") : address;
43
+ render: (appointment) => {
44
+ const { address: { nickname, address }, } = appointment;
45
+ return nickname ? `${nickname} (${address})` : address;
57
46
  },
58
47
  },
59
48
  {
60
49
  title: "Type",
61
50
  dataIndex: "job_subtype",
62
- render: function (jobSubtype) {
63
- var colorStateMap = {
51
+ render: (jobSubtype) => {
52
+ const colorStateMap = {
64
53
  delivery: "info",
65
54
  pickup: "success",
66
55
  };
@@ -72,8 +61,10 @@ export var mockColumns = [
72
61
  },
73
62
  ];
74
63
  // Note: it's important that we don't show the Ant Design sorting since it controlled via the table controls
75
- export var mockColumnsWithSortDisabled = mockColumns.map(function (column) { return (__assign({}, column)); });
76
- export var mockDataSource = {
64
+ export const mockColumnsWithSortDisabled = mockColumns.map((column) => ({
65
+ ...column,
66
+ }));
67
+ export const mockDataSource = {
77
68
  appointments: [
78
69
  {
79
70
  id: "1",
@@ -11,18 +11,4 @@ export declare const getGenesisClass: ({ colors, borderRadius, sizing, typograph
11
11
  typography: any;
12
12
  components: any;
13
13
  }, $isMainContentCell: any) => string;
14
- export declare const Table: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<Omit<TableProps<unknown> & {
15
- children?: import("react").ReactNode | undefined;
16
- } & import("react").RefAttributes<import("rc-table").Reference>, "ref"> & {
17
- ref?: ((instance: import("rc-table").Reference | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<import("rc-table").Reference> | null | undefined;
18
- }, StyledTableProps<any>>> & string & Omit<import("antd/es/table/interface").RefTable & {
19
- displayName?: string;
20
- SELECTION_COLUMN: typeof import("antd/es/table/hooks/useSelection").SELECTION_COLUMN;
21
- EXPAND_COLUMN: typeof import("rc-table").EXPAND_COLUMN;
22
- SELECTION_ALL: typeof import("antd/es/table/hooks/useSelection").SELECTION_ALL;
23
- SELECTION_INVERT: typeof import("antd/es/table/hooks/useSelection").SELECTION_INVERT;
24
- SELECTION_NONE: typeof import("antd/es/table/hooks/useSelection").SELECTION_NONE;
25
- Column: <RecordType extends import("antd/es/_util/type").AnyObject>(_: import("antd").TableColumnProps<RecordType>) => null;
26
- ColumnGroup: <RecordType extends import("antd/es/_util/type").AnyObject>(_: import("antd/es/table/ColumnGroup").ColumnGroupProps<RecordType>) => null;
27
- Summary: typeof import("rc-table").Summary;
28
- }, keyof import("react").Component<any, {}, any>>;
14
+ export declare const Table: any;
@@ -1,20 +1,64 @@
1
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
2
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
3
- return cooked;
4
- };
5
1
  import styled from "@gobolt/genesis/utils/styled";
6
2
  import { Table as AntTable } from "antd";
7
- export var getGenesisClass = function (_a, $isMainContentCell) {
3
+ export const getGenesisClass = ({ colors, borderRadius, sizing, typography, components }, $isMainContentCell) => {
8
4
  // Log the hovered color and the entire tableCell object
9
- var colors = _a.colors, borderRadius = _a.borderRadius, sizing = _a.sizing, typography = _a.typography, components = _a.components;
10
- return "\n &.ant-table-wrapper {\n // Add your custom styles here\n }\n\n .ant-table {\n // Add your custom table styles here\n }\n\n .ant-table-cell {\n font-size: ".concat($isMainContentCell ? "16px" : "14px", " !important;\n color: ").concat($isMainContentCell
5
+ return `
6
+ &.ant-table-wrapper {
7
+ // Add your custom styles here
8
+ }
9
+
10
+ .ant-table {
11
+ // Add your custom table styles here
12
+ }
13
+
14
+ .ant-table-cell {
15
+ font-size: ${$isMainContentCell ? "16px" : "14px"} !important;
16
+ color: ${$isMainContentCell
11
17
  ? colors.onsurface.copy
12
- : colors.onsurface["copy-light"], " !important;\n background-color: ").concat(components.tableCell.surface, " !important;\n transition: background-color 0.2s ease;\n }\n\n .ant-table-tbody > tr:hover > td,\n .ant-table-tbody > tr:hover > .ant-table-cell {\n background-color: ").concat(components.tableCell.hover, " !important;\n }\n\n .ant-table-cell-selected {\n background-color: ").concat(components.tableCell.selected, " !important;\n }\n\n .ant-table-thead > tr > th {\n // Add your custom header styles here\n font-family: 'Inter', sans-serif;\n font-size: ").concat($isMainContentCell ? "16px" : "14px", " !important;\n font-weight: 400;\n color: ").concat($isMainContentCell
18
+ : colors.onsurface["copy-light"]} !important;
19
+ background-color: ${components.tableCell.surface} !important;
20
+ transition: background-color 0.2s ease;
21
+ }
22
+
23
+ .ant-table-tbody > tr:hover > td,
24
+ .ant-table-tbody > tr:hover > .ant-table-cell {
25
+ background-color: ${components.tableCell.hover} !important;
26
+ }
27
+
28
+ .ant-table-cell-selected {
29
+ background-color: ${components.tableCell.selected} !important;
30
+ }
31
+
32
+ .ant-table-thead > tr > th {
33
+ // Add your custom header styles here
34
+ font-family: 'Inter', sans-serif;
35
+ font-size: ${$isMainContentCell ? "16px" : "14px"} !important;
36
+ font-weight: 400;
37
+ color: ${$isMainContentCell
13
38
  ? colors.onsurface.copy
14
- : colors.onsurface["copy-light"], " !important;\n }\n\n .ant-table-tbody > tr {\n // Add your custom row styles here\n }\n\n .ant-table-tbody > tr > td {\n // Add your custom cell styles here\n font-family: 'Inter', sans-serif;\n font-size: 14px;\n color: ").concat(colors.onsurface["copy-light"], ";\n }\n\n .ant-table-tbody > tr.ant-table-row-selected > td,\n .ant-table-tbody > tr.ant-table-row-selected > .ant-table-cell {\n background-color: ").concat(components.tableCell.selected, " !important;\n color: #fff !important;\n }\n ");
39
+ : colors.onsurface["copy-light"]} !important;
40
+ }
41
+
42
+ .ant-table-tbody > tr {
43
+ // Add your custom row styles here
44
+ }
45
+
46
+ .ant-table-tbody > tr > td {
47
+ // Add your custom cell styles here
48
+ font-family: 'Inter', sans-serif;
49
+ font-size: 14px;
50
+ color: ${colors.onsurface["copy-light"]};
51
+ }
52
+
53
+ .ant-table-tbody > tr.ant-table-row-selected > td,
54
+ .ant-table-tbody > tr.ant-table-row-selected > .ant-table-cell {
55
+ background-color: ${components.tableCell.selected} !important;
56
+ color: #fff !important;
57
+ }
58
+ `;
15
59
  };
16
- export var Table = styled(AntTable)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), function (_a) {
17
- var theme = _a.theme, $isMainContentCell = _a.$isMainContentCell;
60
+ export const Table = styled(AntTable) `
61
+ ${({ theme, $isMainContentCell }) => {
18
62
  return getGenesisClass(theme, $isMainContentCell);
19
- });
20
- var templateObject_1;
63
+ }}
64
+ `;
@@ -1,127 +1,33 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
23
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- var __read = (this && this.__read) || function (o, n) {
49
- var m = typeof Symbol === "function" && o[Symbol.iterator];
50
- if (!m) return o;
51
- var i = m.call(o), r, ar = [], e;
52
- try {
53
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
54
- }
55
- catch (error) { e = { error: error }; }
56
- finally {
57
- try {
58
- if (r && !r.done && (m = i["return"])) m.call(i);
59
- }
60
- finally { if (e) throw e.error; }
61
- }
62
- return ar;
63
- };
64
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
65
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
66
- if (ar || !(i in from)) {
67
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
68
- ar[i] = from[i];
69
- }
70
- }
71
- return to.concat(ar || Array.prototype.slice.call(from));
72
- };
73
- var __values = (this && this.__values) || function(o) {
74
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
75
- if (m) return m.call(o);
76
- if (o && typeof o.length === "number") return {
77
- next: function () {
78
- if (o && i >= o.length) o = void 0;
79
- return { value: o && o[i++], done: !o };
80
- }
81
- };
82
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
83
- };
84
1
  import { useState, useEffect, useCallback } from "react";
85
2
  // Function to sort data by field and order
86
- var sortData = function (data, sorter) {
3
+ const sortData = (data, sorter) => {
87
4
  // Handle case when no sorting is applied
88
5
  if (!sorter || (Array.isArray(sorter) && sorter.length === 0)) {
89
- return __spreadArray([], __read(data), false);
6
+ return [...data];
90
7
  }
91
8
  // Handle multiple sorters
92
9
  if (Array.isArray(sorter)) {
93
- return __spreadArray([], __read(data), false).sort(function (a, b) {
94
- var e_1, _a;
95
- try {
96
- for (var sorter_1 = __values(sorter), sorter_1_1 = sorter_1.next(); !sorter_1_1.done; sorter_1_1 = sorter_1.next()) {
97
- var sort = sorter_1_1.value;
98
- if (!sort.field)
99
- continue;
100
- var field = sort.field;
101
- var aValue = a[field];
102
- var bValue = b[field];
103
- if (aValue < bValue)
104
- return sort.order === "ascend" ? -1 : 1;
105
- if (aValue > bValue)
106
- return sort.order === "ascend" ? 1 : -1;
107
- }
108
- }
109
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
110
- finally {
111
- try {
112
- if (sorter_1_1 && !sorter_1_1.done && (_a = sorter_1.return)) _a.call(sorter_1);
113
- }
114
- finally { if (e_1) throw e_1.error; }
10
+ return [...data].sort((a, b) => {
11
+ for (const sort of sorter) {
12
+ if (!sort.field)
13
+ continue;
14
+ const field = sort.field;
15
+ const aValue = a[field];
16
+ const bValue = b[field];
17
+ if (aValue < bValue)
18
+ return sort.order === "ascend" ? -1 : 1;
19
+ if (aValue > bValue)
20
+ return sort.order === "ascend" ? 1 : -1;
115
21
  }
116
22
  return 0;
117
23
  });
118
24
  }
119
25
  // Handle single sorter
120
26
  if (sorter.field) {
121
- var field_1 = sorter.field;
122
- return __spreadArray([], __read(data), false).sort(function (a, b) {
123
- var aValue = a[field_1];
124
- var bValue = b[field_1];
27
+ const field = sorter.field;
28
+ return [...data].sort((a, b) => {
29
+ const aValue = a[field];
30
+ const bValue = b[field];
125
31
  if (sorter.order === "ascend") {
126
32
  if (aValue < bValue)
127
33
  return -1;
@@ -139,7 +45,7 @@ var sortData = function (data, sorter) {
139
45
  return 0;
140
46
  });
141
47
  }
142
- return __spreadArray([], __read(data), false);
48
+ return [...data];
143
49
  };
144
50
  /*
145
51
  Example of disableRowSelection function which can be passed to the useTable hook
@@ -148,71 +54,59 @@ const disableRowSelection = (record: any) => ({
148
54
  name: record.status.toString(),
149
55
  });
150
56
  */
151
- var defaultRowSelection = function (record) { return ({
57
+ const defaultRowSelection = (record) => ({
152
58
  disabled: false, // Add your disable logic here
153
59
  name: record.id,
154
- }); };
155
- export var useTable = function (useTableConfig) {
156
- var _a = __read(useState(true), 2), isLoading = _a[0], setLoading = _a[1];
157
- var _b = useTableConfig, columns = _b.columns, _c = _b.filters, filters = _c === void 0 ? null : _c, _d = _b.fetchUrl, fetchUrl = _d === void 0 ? "/table/data" : _d, _e = _b.fetchOptions, fetchOptions = _e === void 0 ? {
60
+ });
61
+ export const useTable = (useTableConfig) => {
62
+ const [isLoading, setLoading] = useState(true);
63
+ const { columns, filters = null, fetchUrl = "/table/data", fetchOptions = {
158
64
  method: "POST",
159
65
  headers: {
160
66
  "Content-Type": "application/json",
161
67
  },
162
68
  body: JSON.stringify(filters),
163
- } : _e, _f = _b.selectionType, selectionType = _f === void 0 ? "checkbox" : _f, _g = _b.simulateDelay, simulateDelay = _g === void 0 ? 0 : _g, _h = _b.disableRowSelection, disableRowSelection = _h === void 0 ? defaultRowSelection : _h, _j = _b.disableAutoFetch, disableAutoFetch = _j === void 0 ? false : _j, _k = _b.dataSource, initialDataSource = _k === void 0 ? [] : _k;
69
+ }, selectionType = "checkbox", simulateDelay = 0, disableRowSelection = defaultRowSelection, disableAutoFetch = false, dataSource: initialDataSource = [], } = useTableConfig;
164
70
  // State to hold the original data and the current data
165
- var _l = __read(useState(initialDataSource), 2), originalData = _l[0], setOriginalData = _l[1];
166
- var _m = __read(useState({
71
+ const [originalData, setOriginalData] = useState(initialDataSource);
72
+ const [data, setData] = useState({
167
73
  dataSource: initialDataSource,
168
- columns: columns,
74
+ columns,
169
75
  error: null,
170
- }), 2), data = _m[0], setData = _m[1];
171
- var _o = __read(useState([]), 2), selectedRows = _o[0], setSelectedRows = _o[1];
76
+ });
77
+ const [selectedRows, setSelectedRows] = useState([]);
172
78
  // Load initial data
173
- useEffect(function () {
79
+ useEffect(() => {
174
80
  // If auto-fetch is disabled and we have initial data, skip fetching
175
81
  if (disableAutoFetch && initialDataSource.length > 0) {
176
82
  setLoading(false);
177
83
  return;
178
84
  }
179
- var fetchData = function () { return __awaiter(void 0, void 0, void 0, function () {
180
- var response, result, sourceData, error_1;
181
- return __generator(this, function (_a) {
182
- switch (_a.label) {
183
- case 0:
184
- _a.trys.push([0, 3, 4, 5]);
185
- return [4 /*yield*/, fetch(fetchUrl, fetchOptions)];
186
- case 1:
187
- response = _a.sent();
188
- return [4 /*yield*/, response.json()];
189
- case 2:
190
- result = _a.sent();
191
- sourceData = result.data || [];
192
- setOriginalData(sourceData);
193
- setData({
194
- dataSource: sourceData,
195
- columns: columns,
196
- error: null,
197
- });
198
- return [3 /*break*/, 5];
199
- case 3:
200
- error_1 = _a.sent();
201
- console.error("Error fetching table data:", error_1);
202
- // Fallback to static data
203
- setData({
204
- dataSource: [],
205
- columns: columns,
206
- error: error_1 instanceof Error ? error_1 : new Error(String(error_1)),
207
- });
208
- return [3 /*break*/, 5];
209
- case 4:
210
- setLoading(false);
211
- return [7 /*endfinally*/];
212
- case 5: return [2 /*return*/];
213
- }
214
- });
215
- }); };
85
+ const fetchData = async () => {
86
+ try {
87
+ const response = await fetch(fetchUrl, fetchOptions);
88
+ const result = await response.json();
89
+ const sourceData = result.data || [];
90
+ setOriginalData(sourceData);
91
+ setData({
92
+ dataSource: sourceData,
93
+ columns,
94
+ error: null,
95
+ });
96
+ }
97
+ catch (error) {
98
+ console.error("Error fetching table data:", error);
99
+ // Fallback to static data
100
+ setData({
101
+ dataSource: [],
102
+ columns,
103
+ error: error instanceof Error ? error : new Error(String(error)),
104
+ });
105
+ }
106
+ finally {
107
+ setLoading(false);
108
+ }
109
+ };
216
110
  if (simulateDelay > 0) {
217
111
  setTimeout(fetchData, simulateDelay);
218
112
  }
@@ -220,19 +114,28 @@ export var useTable = function (useTableConfig) {
220
114
  fetchData();
221
115
  }
222
116
  }, [fetchOptions, disableAutoFetch, initialDataSource]);
223
- var handleRowSelection = useCallback(function (selectedRowKeys, selectedRows) {
117
+ const handleRowSelection = useCallback((selectedRowKeys, selectedRows) => {
224
118
  console.log("Row Selected:", selectedRowKeys, selectedRows);
225
119
  setSelectedRows(selectedRows);
226
120
  }, []);
227
121
  // Function to manually update data source (for external data fetching)
228
- var updateDataSource = useCallback(function (newDataSource) {
122
+ const updateDataSource = useCallback((newDataSource) => {
229
123
  setOriginalData(newDataSource);
230
- setData(function (prev) { return (__assign(__assign({}, prev), { dataSource: newDataSource })); });
124
+ setData((prev) => ({
125
+ ...prev,
126
+ dataSource: newDataSource,
127
+ }));
231
128
  }, []);
232
- var rowSelection = {
129
+ const rowSelection = {
233
130
  type: selectionType,
234
131
  onChange: handleRowSelection,
235
132
  getCheckboxProps: disableRowSelection,
236
133
  };
237
- return __assign(__assign({}, data), { isLoading: isLoading, rowSelection: rowSelection, selectedRows: selectedRows, updateDataSource: updateDataSource });
134
+ return {
135
+ ...data,
136
+ isLoading,
137
+ rowSelection,
138
+ selectedRows,
139
+ updateDataSource,
140
+ };
238
141
  };
@@ -1,19 +1,18 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import TableControls from "../Table/TableControls";
3
3
  import Table from "../Table";
4
- var TableWithControls = function (_a) {
5
- var tableData = _a.tableData, tableControlsData = _a.tableControlsData, onChange = _a.onChange;
6
- var primaryTableRowData = tableControlsData.primaryTableRowData, secondaryTableRowData = tableControlsData.secondaryTableRowData;
7
- var dataSource = tableData.dataSource, columns = tableData.columns, rowSelection = tableData.rowSelection;
4
+ const TableWithControls = ({ tableData, tableControlsData, onChange, }) => {
5
+ const { primaryTableRowData, secondaryTableRowData } = tableControlsData;
6
+ const { dataSource, columns, rowSelection } = tableData;
8
7
  // handle changes from the table controls
9
- var onTableControlsChange = function (event) {
8
+ const onTableControlsChange = (event) => {
10
9
  onChange(event);
11
10
  };
12
11
  // handle changes from the table
13
- var onTableChange = function (pagination, filters, sorter) {
12
+ const onTableChange = (pagination, filters, sorter) => {
14
13
  onChange({
15
14
  event: "tableChange",
16
- payload: { pagination: pagination, filters: filters, sorter: sorter },
15
+ payload: { pagination, filters, sorter },
17
16
  });
18
17
  };
19
18
  return (_jsxs(_Fragment, { children: [_jsx(TableControls, { primaryTableRowData: primaryTableRowData, secondaryTableRowData: secondaryTableRowData, onChange: onTableControlsChange }), _jsx(Table, { dataSource: dataSource, columns: columns, rowSelection: rowSelection, onChange: onTableChange })] }));