@gobolt/genesis 0.3.22 → 0.3.23

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 (173) hide show
  1. package/dist/components/Badge/Badge.js +32 -9
  2. package/dist/components/Badge/styles.d.ts +10 -1
  3. package/dist/components/Badge/styles.js +14 -39
  4. package/dist/components/Button/Button.js +27 -4
  5. package/dist/components/Button/IconButton.js +27 -4
  6. package/dist/components/Button/components/Button/Button.d.ts +16 -0
  7. package/dist/components/Button/components/Button/Button.js +13 -0
  8. package/dist/components/Button/components/Button/styles.d.ts +1 -0
  9. package/dist/components/Button/components/Button/styles.js +118 -0
  10. package/dist/components/Button/constants/index.d.ts +163 -0
  11. package/dist/components/Button/constants/index.js +89 -0
  12. package/dist/components/Button/icon-button-styles.d.ts +12 -1
  13. package/dist/components/Button/icon-button-styles.js +16 -69
  14. package/dist/components/Button/styles.d.ts +16 -1
  15. package/dist/components/Button/styles.js +30 -88
  16. package/dist/components/Input/Input.js +29 -6
  17. package/dist/components/Input/styles.d.ts +18 -1
  18. package/dist/components/Input/styles.js +42 -146
  19. package/dist/components/Select/Select.js +125 -101
  20. package/dist/components/Select/SelectTrigger.js +57 -71
  21. package/dist/components/Table/Table.js +27 -8
  22. package/dist/components/Table/TableControls/CustomPagination.js +66 -50
  23. package/dist/components/Table/TableControls/PaginationNumber.js +43 -27
  24. package/dist/components/Table/TableControls/PrimaryTableControlsRow.js +17 -16
  25. package/dist/components/Table/TableControls/SecondaryTableControlsRow.js +36 -14
  26. package/dist/components/Table/TableControls/TableControls.js +4 -3
  27. package/dist/components/Table/TablePagination.js +21 -4
  28. package/dist/components/Table/__mocks__/table-mocks.js +24 -15
  29. package/dist/components/Table/styles.d.ts +15 -1
  30. package/dist/components/Table/styles.js +13 -57
  31. package/dist/components/Table/useTable.js +166 -69
  32. package/dist/components/TableWithControls/TableWithControls.js +7 -6
  33. package/dist/components/TableWithControls/components/Badge/Badge.d.ts +16 -0
  34. package/dist/components/TableWithControls/components/Badge/Badge.js +28 -0
  35. package/dist/components/TableWithControls/components/Badge/index.d.ts +2 -0
  36. package/dist/components/TableWithControls/components/Badge/index.js +1 -0
  37. package/dist/components/TableWithControls/components/Badge/styles.d.ts +4 -0
  38. package/dist/components/TableWithControls/components/Badge/styles.js +46 -0
  39. package/dist/components/TableWithControls/components/Button/Button.d.ts +16 -0
  40. package/dist/components/TableWithControls/components/Button/Button.js +13 -0
  41. package/dist/components/TableWithControls/components/Button/IconButton.d.ts +8 -0
  42. package/dist/components/TableWithControls/components/Button/IconButton.js +9 -0
  43. package/dist/components/TableWithControls/components/Button/icon-button-styles.d.ts +1 -0
  44. package/dist/components/TableWithControls/components/Button/icon-button-styles.js +76 -0
  45. package/dist/components/TableWithControls/components/Button/index.d.ts +4 -0
  46. package/dist/components/TableWithControls/components/Button/index.js +2 -0
  47. package/dist/components/TableWithControls/components/Button/styles.d.ts +1 -0
  48. package/dist/components/TableWithControls/components/Button/styles.js +118 -0
  49. package/dist/components/TableWithControls/components/Input/Input.d.ts +13 -0
  50. package/dist/components/TableWithControls/components/Input/Input.js +34 -0
  51. package/dist/components/TableWithControls/components/Input/index.d.ts +2 -0
  52. package/dist/components/TableWithControls/components/Input/index.js +1 -0
  53. package/dist/components/TableWithControls/components/Input/styles.d.ts +1 -0
  54. package/dist/components/TableWithControls/components/Input/styles.js +180 -0
  55. package/dist/components/TableWithControls/components/Select/Select.d.ts +26 -0
  56. package/dist/components/TableWithControls/components/Select/Select.js +175 -0
  57. package/dist/components/TableWithControls/components/Select/SelectTrigger.d.ts +23 -0
  58. package/dist/components/TableWithControls/components/Select/SelectTrigger.js +103 -0
  59. package/dist/components/TableWithControls/components/Select/index.d.ts +2 -0
  60. package/dist/components/TableWithControls/components/Select/index.js +1 -0
  61. package/dist/components/TableWithControls/components/Table/Table.d.ts +51 -0
  62. package/dist/components/TableWithControls/components/Table/Table.js +14 -0
  63. package/dist/components/TableWithControls/components/Table/TableControls/CustomPagination.d.ts +13 -0
  64. package/dist/components/TableWithControls/components/Table/TableControls/CustomPagination.js +158 -0
  65. package/dist/components/TableWithControls/components/Table/TableControls/PaginationNumber.d.ts +7 -0
  66. package/dist/components/TableWithControls/components/Table/TableControls/PaginationNumber.js +30 -0
  67. package/dist/components/TableWithControls/components/Table/TableControls/PrimaryTableControlsRow.d.ts +18 -0
  68. package/dist/components/TableWithControls/components/Table/TableControls/PrimaryTableControlsRow.js +77 -0
  69. package/dist/components/TableWithControls/components/Table/TableControls/SecondaryTableControlsRow.d.ts +11 -0
  70. package/dist/components/TableWithControls/components/Table/TableControls/SecondaryTableControlsRow.js +43 -0
  71. package/dist/components/TableWithControls/components/Table/TableControls/TableControls.d.ts +14 -0
  72. package/dist/components/TableWithControls/components/Table/TableControls/TableControls.js +13 -0
  73. package/dist/components/TableWithControls/components/Table/TableControls/index.d.ts +2 -0
  74. package/dist/components/TableWithControls/components/Table/TableControls/index.js +1 -0
  75. package/dist/components/TableWithControls/components/Table/TablePagination.d.ts +13 -0
  76. package/dist/components/TableWithControls/components/Table/TablePagination.js +11 -0
  77. package/dist/components/TableWithControls/components/Table/__mocks__/table-mocks.d.ts +20 -0
  78. package/dist/components/TableWithControls/components/Table/__mocks__/table-mocks.js +301 -0
  79. package/dist/components/TableWithControls/components/Table/index.d.ts +6 -0
  80. package/dist/components/TableWithControls/components/Table/index.js +3 -0
  81. package/dist/components/TableWithControls/components/Table/styles.d.ts +14 -0
  82. package/dist/components/TableWithControls/components/Table/styles.js +64 -0
  83. package/dist/components/TableWithControls/components/Table/useTable.d.ts +26 -0
  84. package/dist/components/TableWithControls/components/Table/useTable.js +141 -0
  85. package/dist/components/TableWithControls/components/TableWithControls/TableWithControls.d.ts +12 -0
  86. package/dist/components/TableWithControls/components/TableWithControls/TableWithControls.js +20 -0
  87. package/dist/components/TableWithControls/components/TableWithControls/useTableWithControls.d.ts +29 -0
  88. package/dist/components/TableWithControls/components/TableWithControls/useTableWithControls.js +136 -0
  89. package/dist/components/TableWithControls/components/Tooltip/Tooltip.d.ts +7 -0
  90. package/dist/components/TableWithControls/components/Tooltip/Tooltip.js +8 -0
  91. package/dist/components/TableWithControls/components/Tooltip/index.d.ts +2 -0
  92. package/dist/components/TableWithControls/components/Tooltip/index.js +1 -0
  93. package/dist/components/TableWithControls/components/Tooltip/styles.d.ts +6 -0
  94. package/dist/components/TableWithControls/components/Tooltip/styles.js +26 -0
  95. package/dist/components/TableWithControls/components/Typography/Typography.d.ts +17 -0
  96. package/dist/components/TableWithControls/components/Typography/Typography.js +16 -0
  97. package/dist/components/TableWithControls/components/Typography/index.d.ts +2 -0
  98. package/dist/components/TableWithControls/components/Typography/index.js +1 -0
  99. package/dist/components/TableWithControls/components/Typography/styles.d.ts +3 -0
  100. package/dist/components/TableWithControls/components/Typography/styles.js +54 -0
  101. package/dist/components/TableWithControls/components/UtilityButton/UtilityButton.d.ts +5 -0
  102. package/dist/components/TableWithControls/components/UtilityButton/UtilityButton.js +9 -0
  103. package/dist/components/TableWithControls/components/UtilityButton/index.d.ts +2 -0
  104. package/dist/components/TableWithControls/components/UtilityButton/index.js +1 -0
  105. package/dist/components/TableWithControls/components/shared/DropdownChevron.d.ts +2 -0
  106. package/dist/components/TableWithControls/components/shared/DropdownChevron.js +7 -0
  107. package/dist/components/TableWithControls/constants/index.d.ts +163 -0
  108. package/dist/components/TableWithControls/constants/index.js +89 -0
  109. package/dist/components/TableWithControls/types/events.d.ts +22 -0
  110. package/dist/components/TableWithControls/types/events.js +1 -0
  111. package/dist/components/TableWithControls/useTableWithControls.js +63 -82
  112. package/dist/components/TableWithControls/utils/icon-util.d.ts +3 -0
  113. package/dist/components/TableWithControls/utils/icon-util.js +116 -0
  114. package/dist/components/Tooltip/Tooltip.js +2 -1
  115. package/dist/components/Tooltip/styles.d.ts +14 -1
  116. package/dist/components/Tooltip/styles.js +14 -23
  117. package/dist/components/Typography/Typography.js +29 -6
  118. package/dist/components/Typography/styles.d.ts +21 -3
  119. package/dist/components/Typography/styles.js +24 -41
  120. package/dist/components/UtilityButton/UtilityButton.js +27 -4
  121. package/dist/components/UtilityButton/components/Button/Button.d.ts +16 -0
  122. package/dist/components/UtilityButton/components/Button/Button.js +13 -0
  123. package/dist/components/UtilityButton/components/Button/IconButton.d.ts +8 -0
  124. package/dist/components/UtilityButton/components/Button/IconButton.js +9 -0
  125. package/dist/components/UtilityButton/components/Button/icon-button-styles.d.ts +1 -0
  126. package/dist/components/UtilityButton/components/Button/icon-button-styles.js +76 -0
  127. package/dist/components/UtilityButton/components/Button/index.d.ts +4 -0
  128. package/dist/components/UtilityButton/components/Button/index.js +2 -0
  129. package/dist/components/UtilityButton/components/Button/styles.d.ts +1 -0
  130. package/dist/components/UtilityButton/components/Button/styles.js +118 -0
  131. package/dist/components/UtilityButton/components/UtilityButton/UtilityButton.d.ts +5 -0
  132. package/dist/components/UtilityButton/components/UtilityButton/UtilityButton.js +9 -0
  133. package/dist/components/UtilityButton/constants/index.d.ts +163 -0
  134. package/dist/components/UtilityButton/constants/index.js +89 -0
  135. package/dist/components/index.d.ts +6 -6
  136. package/dist/components/index.js +7 -0
  137. package/dist/components/index.ts +6 -6
  138. package/dist/components/shared/DropdownChevron.js +14 -3
  139. package/dist/index.d.ts +9 -9
  140. package/dist/index.js +10 -89
  141. package/dist/index.ts +9 -9
  142. package/dist/utils/icon-util.d.ts +2 -2
  143. package/dist/utils/icon-util.js +19 -16
  144. package/package.json +1 -1
  145. package/dist/components/Button/Button.tsx +0 -59
  146. package/dist/components/Table/Table.tsx +0 -112
  147. package/dist/components/Table/useTable.ts +0 -194
  148. package/dist/components/TableWithControls/TableWithControls.tsx +0 -54
  149. package/dist/components/TableWithControls/useTableWithControls.tsx +0 -161
  150. package/dist/components/UtilityButton/UtilityButton.tsx +0 -36
  151. package/dist/constants/index.ts +0 -98
  152. package/dist/genesis-theme.types.d.ts +0 -263
  153. package/dist/genesis-theme.types.js +0 -6
  154. package/dist/styled.d.ts +0 -1
  155. package/dist/styled.js +0 -44
  156. package/dist/styles/theme/genesis-theme.types.ts +0 -297
  157. package/dist/utils/styled.ts +0 -52
  158. /package/dist/{Table → components/Table/Table}/Table.d.ts +0 -0
  159. /package/dist/{Table → components/Table/Table}/Table.js +0 -0
  160. /package/dist/{Table → components/Table/Table}/TableControls/CustomPagination.d.ts +0 -0
  161. /package/dist/{Table → components/Table/Table}/TableControls/CustomPagination.js +0 -0
  162. /package/dist/{Table → components/Table/Table}/TableControls/PaginationNumber.d.ts +0 -0
  163. /package/dist/{Table → components/Table/Table}/TableControls/PaginationNumber.js +0 -0
  164. /package/dist/{Table → components/Table/Table}/styles.d.ts +0 -0
  165. /package/dist/{Table → components/Table/Table}/styles.js +0 -0
  166. /package/dist/{Table → components/Table/Table}/useTable.d.ts +0 -0
  167. /package/dist/{Table → components/Table/Table}/useTable.js +0 -0
  168. /package/dist/{Typography → components/Table/Typography}/Typography.d.ts +0 -0
  169. /package/dist/{Typography → components/Table/Typography}/Typography.js +0 -0
  170. /package/dist/{Typography → components/Table/Typography}/index.d.ts +0 -0
  171. /package/dist/{Typography → components/Table/Typography}/index.js +0 -0
  172. /package/dist/{Typography → components/Table/Typography}/styles.d.ts +0 -0
  173. /package/dist/{Typography → components/Table/Typography}/styles.js +0 -0
@@ -1,3 +1,3 @@
1
- export declare const getIcon: (name: string) => import("react/jsx-runtime").JSX.Element;
1
+ export declare const getIcon: (name: string) => import("react/jsx-runtime").JSX.Element | null;
2
2
  export declare const getIconColor: (state: any, theme: any) => any;
3
- export declare const getBadgeStateIcon: (state: any, color: any, isFilled?: boolean, hasIcon?: boolean, customIcon?: any) => any;
3
+ export declare const getBadgeStateIcon: (state: any, color: any, isFilled?: boolean, hasIcon?: boolean, customIcon?: null) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { STATE } from "@gobolt/genesis/constants";
3
- const iconSize = 18;
3
+ var iconSize = 18;
4
4
  // check circle filled & outline
5
5
  import { FaCircleCheck } from "react-icons/fa6";
6
6
  import { HiOutlineCheckCircle } from "react-icons/hi";
@@ -21,7 +21,7 @@ import { HiOutlineClock } from "react-icons/hi";
21
21
  import { HiOutlineGlobe } from "react-icons/hi";
22
22
  import { TbFiles } from "react-icons/tb";
23
23
  import { LuTag } from "react-icons/lu";
24
- export const getIcon = (name) => {
24
+ export var getIcon = function (name) {
25
25
  switch (name.toLowerCase()) {
26
26
  case "orders": {
27
27
  return _jsx(LuTag, {});
@@ -37,7 +37,7 @@ export const getIcon = (name) => {
37
37
  }
38
38
  }
39
39
  };
40
- export const getIconColor = (state, theme) => {
40
+ export var getIconColor = function (state, theme) {
41
41
  switch (state) {
42
42
  case STATE.error: {
43
43
  return theme.colors.status.error.onsurface;
@@ -60,7 +60,10 @@ export const getIconColor = (state, theme) => {
60
60
  }
61
61
  }
62
62
  };
63
- export const getBadgeStateIcon = (state, color, isFilled = true, hasIcon = true, customIcon = null) => {
63
+ export var getBadgeStateIcon = function (state, color, isFilled, hasIcon, customIcon) {
64
+ if (isFilled === void 0) { isFilled = true; }
65
+ if (hasIcon === void 0) { hasIcon = true; }
66
+ if (customIcon === void 0) { customIcon = null; }
64
67
  if (!state || !hasIcon) {
65
68
  return null;
66
69
  }
@@ -71,46 +74,46 @@ export const getBadgeStateIcon = (state, color, isFilled = true, hasIcon = true,
71
74
  switch (state) {
72
75
  // isFilled is false
73
76
  case STATE.warning: {
74
- return _jsx(HiOutlineExclamationCircle, { size: iconSize, style: { color } });
77
+ return _jsx(HiOutlineExclamationCircle, { size: iconSize, style: { color: color } });
75
78
  }
76
79
  case STATE.error: {
77
- return _jsx(HiOutlineXCircle, { size: iconSize, style: { color } });
80
+ return _jsx(HiOutlineXCircle, { size: iconSize, style: { color: color } });
78
81
  }
79
82
  case STATE.success: {
80
- return _jsx(HiOutlineCheckCircle, { size: iconSize, style: { color } });
83
+ return _jsx(HiOutlineCheckCircle, { size: iconSize, style: { color: color } });
81
84
  }
82
85
  case STATE.progress: {
83
- return _jsx(HiOutlineClock, { size: iconSize, style: { color } });
86
+ return _jsx(HiOutlineClock, { size: iconSize, style: { color: color } });
84
87
  }
85
88
  case STATE.removed: {
86
- return _jsx(HiOutlineMinusCircle, { size: iconSize, style: { color } });
89
+ return _jsx(HiOutlineMinusCircle, { size: iconSize, style: { color: color } });
87
90
  }
88
91
  case STATE.info:
89
92
  default: {
90
- return _jsx(PiInfo, { size: iconSize, style: { color } });
93
+ return _jsx(PiInfo, { size: iconSize, style: { color: color } });
91
94
  }
92
95
  }
93
96
  }
94
97
  switch (state) {
95
98
  // isFilled is true
96
99
  case STATE.warning: {
97
- return _jsx(HiExclamationCircle, { size: iconSize, style: { color } });
100
+ return _jsx(HiExclamationCircle, { size: iconSize, style: { color: color } });
98
101
  }
99
102
  case STATE.error: {
100
- return _jsx(HiXCircle, { size: iconSize, style: { color } });
103
+ return _jsx(HiXCircle, { size: iconSize, style: { color: color } });
101
104
  }
102
105
  case STATE.success: {
103
- return _jsx(FaCircleCheck, { size: iconSize, style: { color } });
106
+ return _jsx(FaCircleCheck, { size: iconSize, style: { color: color } });
104
107
  }
105
108
  case STATE.progress: {
106
- return _jsx(HiClock, { size: iconSize, style: { color } });
109
+ return _jsx(HiClock, { size: iconSize, style: { color: color } });
107
110
  }
108
111
  case STATE.removed: {
109
- return _jsx(HiMinusCircle, { size: iconSize, style: { color } });
112
+ return _jsx(HiMinusCircle, { size: iconSize, style: { color: color } });
110
113
  }
111
114
  case STATE.info:
112
115
  default: {
113
- return _jsx(PiInfoFill, { size: iconSize, style: { color } });
116
+ return _jsx(PiInfoFill, { size: iconSize, style: { color: color } });
114
117
  }
115
118
  }
116
119
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobolt/genesis",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "description": "genesis design system",
5
5
  "author": "gobolt",
6
6
  "license": "MIT",
@@ -1,59 +0,0 @@
1
- import React, { MouseEvent } from "react";
2
- import * as S from "./styles";
3
- import type { ButtonProps as AntButtonProperties } from "antd/es/button";
4
- import { STATE } from "../../constants";
5
-
6
- type ButtonThemeType =
7
- | "primary"
8
- | "secondary"
9
- | "tertiary"
10
- | "destructive"
11
- | "utility"
12
- | "icon";
13
-
14
- export interface ButtonProps
15
- extends Omit<AntButtonProperties, "type" | "size"> {
16
- onClick?: (event: MouseEvent<HTMLButtonElement>) => void;
17
- children?: React.ReactNode;
18
- themeType?: ButtonThemeType;
19
- state?: keyof typeof STATE;
20
- isIconButton?: boolean;
21
- size?: "small" | "normal" | "large";
22
- isSelected?: boolean;
23
- icon?: React.ReactNode;
24
- }
25
-
26
- const getState = (state: keyof typeof STATE, isSelected: boolean) => {
27
- if (isSelected) {
28
- return "selected";
29
- }
30
- return state === "active" || state === "disabled" ? state : "active";
31
- };
32
-
33
- const Button: React.FC<ButtonProps> = ({
34
- children,
35
- onClick,
36
- themeType = "primary",
37
- state = "active",
38
- isIconButton = false,
39
- size = "normal",
40
- isSelected,
41
- ...rest
42
- }) => {
43
- const buttonState = getState(state, isSelected);
44
- return (
45
- <S.Button
46
- onClick={onClick}
47
- $themeType={themeType}
48
- $state={buttonState}
49
- disabled={state === "disabled" || rest.disabled}
50
- $isIconButton={isIconButton}
51
- size={size}
52
- {...rest}
53
- >
54
- {children}
55
- </S.Button>
56
- );
57
- };
58
-
59
- export default Button;
@@ -1,112 +0,0 @@
1
- /*
2
- This component is used to display a table with Ant Design pagination
3
- Instead, we use TablePagination component that leverages
4
- this Table but replaces the default pagination with CustomPagination components
5
- */
6
-
7
- import * as React from "react";
8
- import * as S from "./styles";
9
- import { ColumnType } from "antd/es/table";
10
- import type { TablePaginationConfig } from "antd/es/table";
11
- import type { StyledTableProps } from "./styles";
12
- import CustomPagination, {
13
- PaginationStyle,
14
- } from "./TableControls/CustomPagination";
15
- import type { ActionEvent } from "@/lib/types";
16
-
17
- export type Change = (actionEvent: ActionEvent) => void;
18
-
19
- export type SelectionType = "checkbox" | "radio";
20
-
21
- export interface TableProps<T extends Record<string, any>> {
22
- dataSource: T[];
23
- columns: ColumnType<T>[];
24
- rowKey?: keyof T | ((record: T) => React.Key);
25
- size?: "small" | "middle" | "large";
26
- rowSelection?: {
27
- type?: SelectionType;
28
- selectedRowKeys?: React.Key[];
29
- onChange?: (selectedRowKeys: React.Key[], selectedRows: T[]) => void;
30
- getCheckboxProps?: (record: T) => { disabled?: boolean; name?: string };
31
- };
32
- onChange?: (
33
- pagination: TablePaginationType,
34
- filters: Record<string, React.Key[]>,
35
- sorter: SorterResult<T> | SorterResult<T>[]
36
- ) => void;
37
- loading?: boolean;
38
- pagination?:
39
- | (TablePaginationConfig & { paginationStyle?: PaginationStyle })
40
- | false;
41
- scroll?: {
42
- x?: number | string;
43
- y?: number | string;
44
- };
45
- bordered?: boolean;
46
- locale?: {
47
- emptyText?: React.ReactNode;
48
- };
49
- [key: string]: any; // Allow additional props
50
- isMainContentCell?: boolean;
51
- }
52
-
53
- // Additional type definitions
54
- export type TablePaginationType = {
55
- pageSize?: number;
56
- current?: number;
57
- total?: number;
58
- onChange?: (page: number, pageSize: number) => void;
59
- };
60
-
61
- export type SorterResult<T> = {
62
- column?: ColumnType<T>;
63
- order?: "ascend" | "descend" | null;
64
- field?: keyof T | string | React.Key | readonly React.Key[];
65
- columnKey?: React.Key;
66
- };
67
-
68
- function Table<T extends Record<string, any>>({
69
- columns,
70
- dataSource,
71
- rowKey = "id",
72
- size = "small",
73
- onChange,
74
- rowSelection,
75
- pagination,
76
- isMainContentCell = false,
77
- ...rest
78
- }: TableProps<T>) {
79
- const paginationConfig =
80
- pagination === false
81
- ? false
82
- : {
83
- ...pagination,
84
- itemRender: undefined, // Clear any existing itemRender to avoid conflicts
85
- render: (properties: TablePaginationConfig) => (
86
- <CustomPagination
87
- {...properties}
88
- paginationStyle={
89
- pagination?.paginationStyle || PaginationStyle.SIMPLE
90
- }
91
- />
92
- ),
93
- };
94
-
95
- return (
96
- <S.Table
97
- data-testid="Table"
98
- dataSource={dataSource}
99
- columns={columns}
100
- rowKey={rowKey}
101
- locale={{ emptyText: "No Data" }}
102
- size={size}
103
- onChange={onChange}
104
- rowSelection={rowSelection}
105
- pagination={paginationConfig}
106
- $isMainContentCell={isMainContentCell}
107
- {...rest}
108
- />
109
- );
110
- }
111
-
112
- export default Table;
@@ -1,194 +0,0 @@
1
- import { useState, useEffect, useCallback } from "react";
2
-
3
- import type { ColumnsType } from "antd/es/table";
4
- import type { SelectionType } from "./Table";
5
-
6
- type SorterResult<T> = {
7
- column?: ColumnsType<T>[number];
8
- order?: "ascend" | "descend" | null;
9
- field?: keyof T | string;
10
- };
11
-
12
- // Function to sort data by field and order
13
- const sortData = <T extends Record<string, any>>(
14
- data: T[],
15
- sorter: SorterResult<T> | SorterResult<T>[]
16
- ): T[] => {
17
- // Handle case when no sorting is applied
18
- if (!sorter || (Array.isArray(sorter) && sorter.length === 0)) {
19
- return [...data];
20
- }
21
-
22
- // Handle multiple sorters
23
- if (Array.isArray(sorter)) {
24
- return [...data].sort((a, b) => {
25
- for (const sort of sorter) {
26
- if (!sort.field) continue;
27
-
28
- const field = sort.field as keyof T;
29
- const aValue = a[field];
30
- const bValue = b[field];
31
-
32
- if (aValue < bValue) return sort.order === "ascend" ? -1 : 1;
33
- if (aValue > bValue) return sort.order === "ascend" ? 1 : -1;
34
- }
35
- return 0;
36
- });
37
- }
38
-
39
- // Handle single sorter
40
- if (sorter.field) {
41
- const field = sorter.field as keyof T;
42
- return [...data].sort((a, b) => {
43
- const aValue = a[field];
44
- const bValue = b[field];
45
-
46
- if (sorter.order === "ascend") {
47
- if (aValue < bValue) return -1;
48
- if (aValue > bValue) return 1;
49
- return 0;
50
- }
51
-
52
- if (sorter.order === "descend") {
53
- if (aValue < bValue) return 1;
54
- if (aValue > bValue) return -1;
55
- return 0;
56
- }
57
-
58
- return 0;
59
- });
60
- }
61
-
62
- return [...data];
63
- };
64
-
65
- /*
66
- Example of disableRowSelection function which can be passed to the useTable hook
67
- const disableRowSelection = (record: any) => ({
68
- disabled: record.status === "completed", // Column configuration not to be checked
69
- name: record.status.toString(),
70
- });
71
- */
72
-
73
- const defaultRowSelection = (record: any) => ({
74
- disabled: false, // Add your disable logic here
75
- name: record.id,
76
- });
77
-
78
- export type UseTableConfig = {
79
- columns: ColumnsType<any>;
80
- filters?: Record<string, any>;
81
- fetchUrl?: string;
82
- fetchOptions?: RequestInit;
83
- selectionType?: SelectionType;
84
- simulateDelay?: number;
85
- disableRowSelection?: (record: any) => unknown;
86
- disableAutoFetch?: boolean; // New option to disable automatic fetching
87
- dataSource?: any[]; // Allow passing data directly
88
- };
89
-
90
- export const useTable = <T extends Record<string, any>>(useTableConfig) => {
91
- const [isLoading, setLoading] = useState(true);
92
-
93
- const {
94
- columns,
95
- filters = null,
96
- fetchUrl = "/table/data",
97
- fetchOptions = {
98
- method: "POST",
99
- headers: {
100
- "Content-Type": "application/json",
101
- },
102
- body: JSON.stringify(filters),
103
- },
104
- selectionType = "checkbox",
105
- simulateDelay = 0,
106
- disableRowSelection = defaultRowSelection,
107
- disableAutoFetch = false,
108
- dataSource: initialDataSource = [],
109
- } = useTableConfig as UseTableConfig;
110
- // State to hold the original data and the current data
111
-
112
- const [originalData, setOriginalData] = useState<T[]>(initialDataSource);
113
- const [data, setData] = useState<{
114
- dataSource: T[];
115
- columns: ColumnsType<T>;
116
- error: Error | null;
117
- }>({
118
- dataSource: initialDataSource,
119
- columns,
120
- error: null,
121
- });
122
- const [selectedRows, setSelectedRows] = useState<T[]>([]);
123
-
124
- // Load initial data
125
- useEffect(() => {
126
- // If auto-fetch is disabled and we have initial data, skip fetching
127
- if (disableAutoFetch && initialDataSource.length > 0) {
128
- setLoading(false);
129
- return;
130
- }
131
-
132
- const fetchData = async () => {
133
- try {
134
- const response = await fetch(fetchUrl, fetchOptions);
135
- const result = await response.json();
136
- const sourceData = result.data || [];
137
- setOriginalData(sourceData);
138
- setData({
139
- dataSource: sourceData,
140
- columns,
141
- error: null,
142
- });
143
- } catch (error) {
144
- console.error("Error fetching table data:", error);
145
- // Fallback to static data
146
- setData({
147
- dataSource: [],
148
- columns,
149
- error: error instanceof Error ? error : new Error(String(error)),
150
- });
151
- } finally {
152
- setLoading(false);
153
- }
154
- };
155
-
156
- if (simulateDelay > 0) {
157
- setTimeout(fetchData, simulateDelay);
158
- } else {
159
- fetchData();
160
- }
161
- }, [fetchOptions, disableAutoFetch, initialDataSource]);
162
-
163
- const handleRowSelection = useCallback(
164
- (selectedRowKeys: React.Key[], selectedRows: T[]) => {
165
- console.log("Row Selected:", selectedRowKeys, selectedRows);
166
-
167
- setSelectedRows(selectedRows);
168
- },
169
- []
170
- );
171
-
172
- // Function to manually update data source (for external data fetching)
173
- const updateDataSource = useCallback((newDataSource: T[]) => {
174
- setOriginalData(newDataSource);
175
- setData((prev) => ({
176
- ...prev,
177
- dataSource: newDataSource,
178
- }));
179
- }, []);
180
-
181
- const rowSelection = {
182
- type: selectionType,
183
- onChange: handleRowSelection,
184
- getCheckboxProps: disableRowSelection,
185
- };
186
-
187
- return {
188
- ...data,
189
- isLoading,
190
- rowSelection,
191
- selectedRows,
192
- updateDataSource,
193
- };
194
- };
@@ -1,54 +0,0 @@
1
- import TableControls from "../Table/TableControls";
2
- import Table from "../Table";
3
- import type { TableProps } from "../Table";
4
- import { type TableControlsData } from "../Table/TableControls/TableControls";
5
- import type { Change } from "../Table/Table";
6
-
7
- export interface TableWithControlsProps {
8
- tableControlsData: TableControlsData;
9
- tableData: TableProps<Record<string, any>>;
10
- onChange: (event: { event: string; payload: any }) => void;
11
- }
12
-
13
- const TableWithControls = ({
14
- tableData,
15
- tableControlsData,
16
- onChange,
17
- }: TableWithControlsProps) => {
18
- const { primaryTableRowData, secondaryTableRowData } = tableControlsData;
19
- const { dataSource, columns, rowSelection } = tableData;
20
-
21
- // handle changes from the table controls
22
- const onTableControlsChange: Change = (event: {
23
- event: string;
24
- payload: any;
25
- }) => {
26
- onChange(event);
27
- };
28
-
29
- // handle changes from the table
30
- const onTableChange = (pagination: any, filters: any, sorter: any) => {
31
- onChange({
32
- event: "tableChange",
33
- payload: { pagination, filters, sorter },
34
- });
35
- };
36
-
37
- return (
38
- <>
39
- <TableControls
40
- primaryTableRowData={primaryTableRowData}
41
- secondaryTableRowData={secondaryTableRowData}
42
- onChange={onTableControlsChange}
43
- />
44
- <Table
45
- dataSource={dataSource}
46
- columns={columns}
47
- rowSelection={rowSelection}
48
- onChange={onTableChange}
49
- />
50
- </>
51
- );
52
- };
53
-
54
- export default TableWithControls;
@@ -1,161 +0,0 @@
1
- import { useState } from "react";
2
-
3
- import { useTable, type UseTableConfig } from "../Table/useTable";
4
- import { mockColumns, mockDataSource } from "../Table/__mocks__/table-mocks";
5
- import { ActionEvent, TableEventPayload } from "../../types/events";
6
-
7
- //import
8
-
9
- const tableControlsData = {
10
- primaryTableRowData: {
11
- sortOptions: [
12
- { value: "status", label: <span>Status</span> },
13
- { value: "address", label: <span>Address</span> },
14
- { value: "job_subtype", label: <span>Type</span> },
15
- ],
16
- searchByPlaceholder: "Search by Address",
17
- isSortedAscending: true,
18
- },
19
- secondaryTableRowData: {
20
- groups: {
21
- orders: ["Cancelled", "Paused"],
22
- warehouse: ["D2C"],
23
- availability: ["Out of Stock"],
24
- },
25
- totalRecords: mockDataSource.appointments.length,
26
- },
27
- };
28
-
29
- const startingUseTableConfig: UseTableConfig = {
30
- columns: mockColumns,
31
- filters: {
32
- order: "asc",
33
- },
34
- // Disable auto-fetch to allow external data management
35
- disableAutoFetch: true,
36
- dataSource: [],
37
- };
38
-
39
- export const useTableWithControls = (tableConfig: UseTableConfig) => {
40
- const [useTableConfig, setUseTableConfig] = useState<UseTableConfig>(
41
- startingUseTableConfig
42
- );
43
-
44
- const [groups, setGroups] = useState(
45
- tableControlsData.secondaryTableRowData.groups
46
- );
47
-
48
- const [primaryTableRowData, setPrimaryTableRowData] = useState(
49
- tableControlsData.primaryTableRowData
50
- );
51
-
52
- const { secondaryTableRowData } = tableControlsData;
53
-
54
- const newSecondaryTableRowData = {
55
- ...secondaryTableRowData,
56
- groups,
57
- totalRecords: safeDataSource.length,
58
- };
59
-
60
- const { dataSource, columns, rowSelection, updateDataSource } =
61
- useTable(useTableConfig);
62
-
63
- // Ensure we always return a valid object, even if dataSource is empty
64
- const safeDataSource = dataSource || [];
65
-
66
- const onGroupItemClick = (title: string, item: string) => {
67
- const newGroups = { ...groups };
68
- newGroups[title] = newGroups[title].filter((group) => group !== item);
69
- setGroups(newGroups);
70
- };
71
-
72
- const onChange = (actionEvent: ActionEvent<TableEventPayload>) => {
73
- if (actionEvent.event === "inputChange") {
74
- const { value } = actionEvent.payload;
75
- if (typeof value === "string") {
76
- setUseTableConfig((previous) => ({
77
- ...previous,
78
- filters: {
79
- ...previous.filters,
80
- search: value,
81
- },
82
- fetchOptions: {
83
- ...previous.fetchOptions,
84
- body: JSON.stringify({
85
- filters: {
86
- ...previous.filters,
87
- search: value,
88
- },
89
- }),
90
- },
91
- }));
92
- }
93
- }
94
-
95
- if (actionEvent.event === "primaryChange") {
96
- const { value } = actionEvent.payload;
97
- if (typeof value === "string") {
98
- setUseTableConfig((previous) => ({
99
- ...previous,
100
- filters: {
101
- ...previous.filters,
102
- sort: value,
103
- },
104
- fetchOptions: {
105
- ...previous.fetchOptions,
106
- body: JSON.stringify({
107
- filters: {
108
- ...previous.filters,
109
- sort: value,
110
- },
111
- }),
112
- },
113
- }));
114
- }
115
- }
116
-
117
- if (actionEvent.event === "groupItemClick") {
118
- const { title, item } = actionEvent.payload;
119
- if (typeof title === "string" && typeof item === "string") {
120
- onGroupItemClick(title, item);
121
- }
122
- }
123
-
124
- if (actionEvent.event === "orderClick") {
125
- setPrimaryTableRowData((previous) => ({
126
- ...previous,
127
- isSortedAscending: !previous.isSortedAscending,
128
- }));
129
-
130
- const { value } = actionEvent.payload;
131
- if (typeof value === "string") {
132
- setUseTableConfig((previous) => ({
133
- ...previous,
134
- filters: {
135
- ...previous.filters,
136
- order: value,
137
- },
138
- fetchOptions: {
139
- ...previous.fetchOptions,
140
- body: JSON.stringify({
141
- filters: {
142
- ...previous.filters,
143
- order: value,
144
- },
145
- }),
146
- },
147
- }));
148
- }
149
- }
150
- };
151
-
152
- return {
153
- onChange,
154
- primaryTableRowData,
155
- secondaryTableRowData: newSecondaryTableRowData,
156
- dataSource: safeDataSource,
157
- columns,
158
- rowSelection,
159
- updateDataSource,
160
- };
161
- };