@gobolt/genesis 0.3.21 → 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.
- package/dist/components/Button/components/Button/Button.d.ts +16 -0
- package/dist/components/Button/components/Button/Button.js +13 -0
- package/dist/components/Button/components/Button/styles.d.ts +1 -0
- package/dist/components/Button/components/Button/styles.js +118 -0
- package/dist/components/Button/constants/index.d.ts +163 -0
- package/dist/components/Button/constants/index.js +89 -0
- package/dist/components/Table/Table/Table.d.ts +51 -0
- package/dist/components/Table/Table/Table.js +14 -0
- package/dist/components/Table/Table/TableControls/CustomPagination.d.ts +13 -0
- package/dist/components/Table/Table/TableControls/CustomPagination.js +158 -0
- package/dist/components/Table/Table/TableControls/PaginationNumber.d.ts +7 -0
- package/dist/components/Table/Table/TableControls/PaginationNumber.js +30 -0
- package/dist/components/Table/Table/styles.d.ts +14 -0
- package/dist/components/Table/Table/styles.js +64 -0
- package/dist/components/Table/Table/useTable.d.ts +26 -0
- package/dist/components/Table/Table/useTable.js +141 -0
- package/dist/components/Table/Typography/Typography.d.ts +17 -0
- package/dist/components/Table/Typography/Typography.js +16 -0
- package/dist/components/Table/Typography/index.d.ts +2 -0
- package/dist/components/Table/Typography/index.js +1 -0
- package/dist/components/Table/Typography/styles.d.ts +3 -0
- package/dist/components/Table/Typography/styles.js +54 -0
- package/dist/components/TableWithControls/components/Badge/Badge.d.ts +16 -0
- package/dist/components/TableWithControls/components/Badge/Badge.js +28 -0
- package/dist/components/TableWithControls/components/Badge/index.d.ts +2 -0
- package/dist/components/TableWithControls/components/Badge/index.js +1 -0
- package/dist/components/TableWithControls/components/Badge/styles.d.ts +4 -0
- package/dist/components/TableWithControls/components/Badge/styles.js +46 -0
- package/dist/components/TableWithControls/components/Button/Button.d.ts +16 -0
- package/dist/components/TableWithControls/components/Button/Button.js +13 -0
- package/dist/components/TableWithControls/components/Button/IconButton.d.ts +8 -0
- package/dist/components/TableWithControls/components/Button/IconButton.js +9 -0
- package/dist/components/TableWithControls/components/Button/icon-button-styles.d.ts +1 -0
- package/dist/components/TableWithControls/components/Button/icon-button-styles.js +76 -0
- package/dist/components/TableWithControls/components/Button/index.d.ts +4 -0
- package/dist/components/TableWithControls/components/Button/index.js +2 -0
- package/dist/components/TableWithControls/components/Button/styles.d.ts +1 -0
- package/dist/components/TableWithControls/components/Button/styles.js +118 -0
- package/dist/components/TableWithControls/components/Input/Input.d.ts +13 -0
- package/dist/components/TableWithControls/components/Input/Input.js +34 -0
- package/dist/components/TableWithControls/components/Input/index.d.ts +2 -0
- package/dist/components/TableWithControls/components/Input/index.js +1 -0
- package/dist/components/TableWithControls/components/Input/styles.d.ts +1 -0
- package/dist/components/TableWithControls/components/Input/styles.js +180 -0
- package/dist/components/TableWithControls/components/Select/Select.d.ts +26 -0
- package/dist/components/TableWithControls/components/Select/Select.js +175 -0
- package/dist/components/TableWithControls/components/Select/SelectTrigger.d.ts +23 -0
- package/dist/components/TableWithControls/components/Select/SelectTrigger.js +103 -0
- package/dist/components/TableWithControls/components/Select/index.d.ts +2 -0
- package/dist/components/TableWithControls/components/Select/index.js +1 -0
- package/dist/components/TableWithControls/components/Table/Table.d.ts +51 -0
- package/dist/components/TableWithControls/components/Table/Table.js +14 -0
- package/dist/components/TableWithControls/components/Table/TableControls/CustomPagination.d.ts +13 -0
- package/dist/components/TableWithControls/components/Table/TableControls/CustomPagination.js +158 -0
- package/dist/components/TableWithControls/components/Table/TableControls/PaginationNumber.d.ts +7 -0
- package/dist/components/TableWithControls/components/Table/TableControls/PaginationNumber.js +30 -0
- package/dist/components/TableWithControls/components/Table/TableControls/PrimaryTableControlsRow.d.ts +18 -0
- package/dist/components/TableWithControls/components/Table/TableControls/PrimaryTableControlsRow.js +77 -0
- package/dist/components/TableWithControls/components/Table/TableControls/SecondaryTableControlsRow.d.ts +11 -0
- package/dist/components/TableWithControls/components/Table/TableControls/SecondaryTableControlsRow.js +43 -0
- package/dist/components/TableWithControls/components/Table/TableControls/TableControls.d.ts +14 -0
- package/dist/components/TableWithControls/components/Table/TableControls/TableControls.js +13 -0
- package/dist/components/TableWithControls/components/Table/TableControls/index.d.ts +2 -0
- package/dist/components/TableWithControls/components/Table/TableControls/index.js +1 -0
- package/dist/components/TableWithControls/components/Table/TablePagination.d.ts +13 -0
- package/dist/components/TableWithControls/components/Table/TablePagination.js +11 -0
- package/dist/components/TableWithControls/components/Table/__mocks__/table-mocks.d.ts +20 -0
- package/dist/components/TableWithControls/components/Table/__mocks__/table-mocks.js +301 -0
- package/dist/components/TableWithControls/components/Table/index.d.ts +6 -0
- package/dist/components/TableWithControls/components/Table/index.js +3 -0
- package/dist/components/TableWithControls/components/Table/styles.d.ts +14 -0
- package/dist/components/TableWithControls/components/Table/styles.js +64 -0
- package/dist/components/TableWithControls/components/Table/useTable.d.ts +26 -0
- package/dist/components/TableWithControls/components/Table/useTable.js +141 -0
- package/dist/components/TableWithControls/components/TableWithControls/TableWithControls.d.ts +12 -0
- package/dist/components/TableWithControls/components/TableWithControls/TableWithControls.js +20 -0
- package/dist/components/TableWithControls/components/TableWithControls/useTableWithControls.d.ts +29 -0
- package/dist/components/TableWithControls/components/TableWithControls/useTableWithControls.js +136 -0
- package/dist/components/TableWithControls/components/Tooltip/Tooltip.d.ts +7 -0
- package/dist/components/TableWithControls/components/Tooltip/Tooltip.js +8 -0
- package/dist/components/TableWithControls/components/Tooltip/index.d.ts +2 -0
- package/dist/components/TableWithControls/components/Tooltip/index.js +1 -0
- package/dist/components/TableWithControls/components/Tooltip/styles.d.ts +6 -0
- package/dist/components/TableWithControls/components/Tooltip/styles.js +26 -0
- package/dist/components/TableWithControls/components/Typography/Typography.d.ts +17 -0
- package/dist/components/TableWithControls/components/Typography/Typography.js +16 -0
- package/dist/components/TableWithControls/components/Typography/index.d.ts +2 -0
- package/dist/components/TableWithControls/components/Typography/index.js +1 -0
- package/dist/components/TableWithControls/components/Typography/styles.d.ts +3 -0
- package/dist/components/TableWithControls/components/Typography/styles.js +54 -0
- package/dist/components/TableWithControls/components/UtilityButton/UtilityButton.d.ts +5 -0
- package/dist/components/TableWithControls/components/UtilityButton/UtilityButton.js +9 -0
- package/dist/components/TableWithControls/components/UtilityButton/index.d.ts +2 -0
- package/dist/components/TableWithControls/components/UtilityButton/index.js +1 -0
- package/dist/components/TableWithControls/components/shared/DropdownChevron.d.ts +2 -0
- package/dist/components/TableWithControls/components/shared/DropdownChevron.js +7 -0
- package/dist/components/TableWithControls/constants/index.d.ts +163 -0
- package/dist/components/TableWithControls/constants/index.js +89 -0
- package/dist/components/TableWithControls/types/events.d.ts +22 -0
- package/dist/components/TableWithControls/types/events.js +1 -0
- package/dist/components/TableWithControls/utils/icon-util.d.ts +3 -0
- package/dist/components/TableWithControls/utils/icon-util.js +116 -0
- package/dist/components/UtilityButton/components/Button/Button.d.ts +16 -0
- package/dist/components/UtilityButton/components/Button/Button.js +13 -0
- package/dist/components/UtilityButton/components/Button/IconButton.d.ts +8 -0
- package/dist/components/UtilityButton/components/Button/IconButton.js +9 -0
- package/dist/components/UtilityButton/components/Button/icon-button-styles.d.ts +1 -0
- package/dist/components/UtilityButton/components/Button/icon-button-styles.js +76 -0
- package/dist/components/UtilityButton/components/Button/index.d.ts +4 -0
- package/dist/components/UtilityButton/components/Button/index.js +2 -0
- package/dist/components/UtilityButton/components/Button/styles.d.ts +1 -0
- package/dist/components/UtilityButton/components/Button/styles.js +118 -0
- package/dist/components/UtilityButton/components/UtilityButton/UtilityButton.d.ts +5 -0
- package/dist/components/UtilityButton/components/UtilityButton/UtilityButton.js +9 -0
- package/dist/components/UtilityButton/constants/index.d.ts +163 -0
- package/dist/components/UtilityButton/constants/index.js +89 -0
- package/dist/components/index.d.ts +6 -6
- package/dist/components/index.js +7 -0
- package/dist/components/index.ts +6 -6
- package/dist/constants/index.js +14 -14
- package/dist/index.d.ts +9 -9
- package/dist/index.js +10 -0
- package/dist/index.ts +9 -9
- package/package.json +1 -1
- package/dist/components/Button/Button.tsx +0 -59
- package/dist/components/Table/Table.tsx +0 -112
- package/dist/components/Table/useTable.ts +0 -194
- package/dist/components/TableWithControls/TableWithControls.tsx +0 -54
- package/dist/components/TableWithControls/useTableWithControls.tsx +0 -161
- package/dist/components/UtilityButton/UtilityButton.tsx +0 -36
- package/dist/constants/index.ts +0 -98
- package/dist/styles/theme/genesis-theme.types.ts +0 -297
- package/dist/utils/styled.ts +0 -52
package/dist/components/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
|
-
export { default as Button } from './Button/Button';
|
|
3
|
-
export { default as UtilityButton } from './UtilityButton/UtilityButton';
|
|
4
|
-
export { default as TableWithControls } from './TableWithControls/TableWithControls';
|
|
5
|
-
export { useTableWithControls } from './TableWithControls/useTableWithControls';
|
|
6
|
-
export { default as Table } from './Table/Table';
|
|
7
|
-
export { useTable } from './Table/useTable';
|
|
2
|
+
export { default as Button } from './Button/Button.js';
|
|
3
|
+
export { default as UtilityButton } from './UtilityButton/UtilityButton.js';
|
|
4
|
+
export { default as TableWithControls } from './TableWithControls/TableWithControls.js';
|
|
5
|
+
export { useTableWithControls } from './TableWithControls/useTableWithControls.js';
|
|
6
|
+
export { default as Table } from './Table/Table.js';
|
|
7
|
+
export { useTable } from './Table/useTable.js';
|
package/dist/constants/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const TYPE = {
|
|
2
2
|
primary: "primary",
|
|
3
3
|
secondary: "secondary",
|
|
4
4
|
tertiary: "tertiary",
|
|
@@ -6,12 +6,12 @@ export var TYPE = {
|
|
|
6
6
|
utility: "utility",
|
|
7
7
|
icon: "icon",
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export const BREAKPOINTS = {
|
|
10
10
|
wide: "wide",
|
|
11
11
|
medium: "medium",
|
|
12
12
|
narrow: "narrow",
|
|
13
13
|
};
|
|
14
|
-
export
|
|
14
|
+
export const STATE = {
|
|
15
15
|
active: "active",
|
|
16
16
|
hover: "hover",
|
|
17
17
|
pressed: "pressed",
|
|
@@ -27,7 +27,7 @@ export var STATE = {
|
|
|
27
27
|
removed: "removed",
|
|
28
28
|
hollow: "hollow",
|
|
29
29
|
};
|
|
30
|
-
export
|
|
30
|
+
export const TYPOGRAPHY_VARIANT = {
|
|
31
31
|
display1: "display1",
|
|
32
32
|
display2: "display2",
|
|
33
33
|
display3: "display3",
|
|
@@ -56,18 +56,18 @@ export var TYPOGRAPHY_VARIANT = {
|
|
|
56
56
|
digits2: "digits2",
|
|
57
57
|
digits3: "digits3",
|
|
58
58
|
};
|
|
59
|
-
export
|
|
59
|
+
export const BUTTON_VARIANT = {
|
|
60
60
|
primary: "primary",
|
|
61
61
|
secondary: "secondary",
|
|
62
62
|
tertiary: "tertiary",
|
|
63
63
|
};
|
|
64
|
-
export
|
|
64
|
+
export const SIZE = {
|
|
65
65
|
small: "small",
|
|
66
66
|
medium: "medium",
|
|
67
67
|
large: "large",
|
|
68
68
|
standard: "standard",
|
|
69
69
|
};
|
|
70
|
-
export
|
|
70
|
+
export const BADGE = {
|
|
71
71
|
appointment: "appointment",
|
|
72
72
|
asn: "asn",
|
|
73
73
|
inventory: "inventory",
|
|
@@ -79,11 +79,11 @@ export var BADGE = {
|
|
|
79
79
|
system: "system",
|
|
80
80
|
};
|
|
81
81
|
export default {
|
|
82
|
-
TYPE
|
|
83
|
-
BREAKPOINTS
|
|
84
|
-
STATE
|
|
85
|
-
TYPOGRAPHY_VARIANT
|
|
86
|
-
BUTTON_VARIANT
|
|
87
|
-
SIZE
|
|
88
|
-
BADGE
|
|
82
|
+
TYPE,
|
|
83
|
+
BREAKPOINTS,
|
|
84
|
+
STATE,
|
|
85
|
+
TYPOGRAPHY_VARIANT,
|
|
86
|
+
BUTTON_VARIANT,
|
|
87
|
+
SIZE,
|
|
88
|
+
BADGE,
|
|
89
89
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
export { default as Button } from './components/Button/Button';
|
|
3
|
-
export { default as UtilityButton } from './components/UtilityButton/UtilityButton';
|
|
4
|
-
export { default as TableWithControls } from './components/TableWithControls/TableWithControls';
|
|
5
|
-
export { useTableWithControls } from './components/TableWithControls/useTableWithControls';
|
|
6
|
-
export { default as Table } from './components/Table/Table';
|
|
7
|
-
export { useTable } from './components/Table/useTable';
|
|
8
|
-
export * from './constants';
|
|
9
|
-
export * from './utils/styled';
|
|
10
|
-
export * from './styles/theme/genesis-theme.types';
|
|
2
|
+
export { default as Button } from './components/Button/Button.js';
|
|
3
|
+
export { default as UtilityButton } from './components/UtilityButton/UtilityButton.js';
|
|
4
|
+
export { default as TableWithControls } from './components/TableWithControls/TableWithControls.js';
|
|
5
|
+
export { useTableWithControls } from './components/TableWithControls/useTableWithControls.js';
|
|
6
|
+
export { default as Table } from './components/Table/Table.js';
|
|
7
|
+
export { useTable } from './components/Table/useTable.js';
|
|
8
|
+
export * from './constants/index.js';
|
|
9
|
+
export * from './utils/styled.js';
|
|
10
|
+
export * from './styles/theme/genesis-theme.types.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
|
|
2
|
+
export { default as Button } from './components/Button/Button.js';
|
|
3
|
+
export { default as UtilityButton } from './components/UtilityButton/UtilityButton.js';
|
|
4
|
+
export { default as TableWithControls } from './components/TableWithControls/TableWithControls.js';
|
|
5
|
+
export { useTableWithControls } from './components/TableWithControls/useTableWithControls.js';
|
|
6
|
+
export { default as Table } from './components/Table/Table.js';
|
|
7
|
+
export { useTable } from './components/Table/useTable.js';
|
|
8
|
+
export * from './constants/index.js';
|
|
9
|
+
export * from './utils/styled.js';
|
|
10
|
+
export * from './styles/theme/genesis-theme.types.js';
|
package/dist/index.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
export { default as Button } from './components/Button/Button';
|
|
3
|
-
export { default as UtilityButton } from './components/UtilityButton/UtilityButton';
|
|
4
|
-
export { default as TableWithControls } from './components/TableWithControls/TableWithControls';
|
|
5
|
-
export { useTableWithControls } from './components/TableWithControls/useTableWithControls';
|
|
6
|
-
export { default as Table } from './components/Table/Table';
|
|
7
|
-
export { useTable } from './components/Table/useTable';
|
|
8
|
-
export * from './constants';
|
|
9
|
-
export * from './utils/styled';
|
|
10
|
-
export * from './styles/theme/genesis-theme.types';
|
|
2
|
+
export { default as Button } from './components/Button/Button.js';
|
|
3
|
+
export { default as UtilityButton } from './components/UtilityButton/UtilityButton.js';
|
|
4
|
+
export { default as TableWithControls } from './components/TableWithControls/TableWithControls.js';
|
|
5
|
+
export { useTableWithControls } from './components/TableWithControls/useTableWithControls.js';
|
|
6
|
+
export { default as Table } from './components/Table/Table.js';
|
|
7
|
+
export { useTable } from './components/Table/useTable.js';
|
|
8
|
+
export * from './constants/index.js';
|
|
9
|
+
export * from './utils/styled.js';
|
|
10
|
+
export * from './styles/theme/genesis-theme.types.js';
|
package/package.json
CHANGED
|
@@ -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;
|