@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
@@ -0,0 +1,51 @@
1
+ import * as React from "react";
2
+ import { ColumnType } from "antd/es/table";
3
+ import type { TablePaginationConfig } from "antd/es/table";
4
+ import { PaginationStyle } from "./TableControls/CustomPagination";
5
+ import type { ActionEvent } from "@/lib/types";
6
+ export type Change = (actionEvent: ActionEvent) => void;
7
+ export type SelectionType = "checkbox" | "radio";
8
+ export interface TableProps<T extends Record<string, any>> {
9
+ dataSource: T[];
10
+ columns: ColumnType<T>[];
11
+ rowKey?: keyof T | ((record: T) => React.Key);
12
+ size?: "small" | "middle" | "large";
13
+ rowSelection?: {
14
+ type?: SelectionType;
15
+ selectedRowKeys?: React.Key[];
16
+ onChange?: (selectedRowKeys: React.Key[], selectedRows: T[]) => void;
17
+ getCheckboxProps?: (record: T) => {
18
+ disabled?: boolean;
19
+ name?: string;
20
+ };
21
+ };
22
+ onChange?: (pagination: TablePaginationType, filters: Record<string, React.Key[]>, sorter: SorterResult<T> | SorterResult<T>[]) => void;
23
+ loading?: boolean;
24
+ pagination?: (TablePaginationConfig & {
25
+ paginationStyle?: PaginationStyle;
26
+ }) | false;
27
+ scroll?: {
28
+ x?: number | string;
29
+ y?: number | string;
30
+ };
31
+ bordered?: boolean;
32
+ locale?: {
33
+ emptyText?: React.ReactNode;
34
+ };
35
+ [key: string]: any;
36
+ isMainContentCell?: boolean;
37
+ }
38
+ export type TablePaginationType = {
39
+ pageSize?: number;
40
+ current?: number;
41
+ total?: number;
42
+ onChange?: (page: number, pageSize: number) => void;
43
+ };
44
+ export type SorterResult<T> = {
45
+ column?: ColumnType<T>;
46
+ order?: "ascend" | "descend" | null;
47
+ field?: keyof T | string | React.Key | readonly React.Key[];
48
+ columnKey?: React.Key;
49
+ };
50
+ declare function Table<T extends Record<string, any>>({ columns, dataSource, rowKey, size, onChange, rowSelection, pagination, isMainContentCell, ...rest }: TableProps<T>): import("react/jsx-runtime").JSX.Element;
51
+ export default Table;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as S from "./styles";
3
+ import CustomPagination, { PaginationStyle, } from "./TableControls/CustomPagination";
4
+ function Table({ columns, dataSource, rowKey = "id", size = "small", onChange, rowSelection, pagination, isMainContentCell = false, ...rest }) {
5
+ const paginationConfig = pagination === false
6
+ ? false
7
+ : {
8
+ ...pagination,
9
+ itemRender: undefined, // Clear any existing itemRender to avoid conflicts
10
+ render: (properties) => (_jsx(CustomPagination, { ...properties, paginationStyle: pagination?.paginationStyle || PaginationStyle.SIMPLE })),
11
+ };
12
+ return (_jsx(S.Table, { "data-testid": "Table", dataSource: dataSource, columns: columns, rowKey: rowKey, locale: { emptyText: "No Data" }, size: size, onChange: onChange, rowSelection: rowSelection, pagination: paginationConfig, "$isMainContentCell": isMainContentCell, ...rest }));
13
+ }
14
+ export default Table;
@@ -0,0 +1,13 @@
1
+ import React from "react";
2
+ import type { PaginationProps } from "antd";
3
+ export declare enum PaginationStyle {
4
+ SIMPLE = "simple",// Shows just 1-5
5
+ TRUNCATED = "truncated",// Shows 1-5...20
6
+ CENTERED = "centered",// Shows 1...4-5-6-7-8...20
7
+ END_FOCUSED = "endFocused"
8
+ }
9
+ interface CustomPaginationProperties extends Omit<PaginationProps, "itemRender"> {
10
+ paginationStyle?: PaginationStyle;
11
+ }
12
+ declare const CustomPagination: React.FC<CustomPaginationProperties>;
13
+ export default CustomPagination;
@@ -0,0 +1,158 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import styled from "styled-components";
3
+ import { PaginationNumber } from "./PaginationNumber";
4
+ export var PaginationStyle;
5
+ (function (PaginationStyle) {
6
+ PaginationStyle["SIMPLE"] = "simple";
7
+ PaginationStyle["TRUNCATED"] = "truncated";
8
+ PaginationStyle["CENTERED"] = "centered";
9
+ PaginationStyle["END_FOCUSED"] = "endFocused";
10
+ })(PaginationStyle || (PaginationStyle = {}));
11
+ const PaginationContainer = styled.div `
12
+ display: flex;
13
+ align-items: center;
14
+ justify-content: flex-start;
15
+ margin: 0;
16
+ gap: 0 0;
17
+ `;
18
+ const ChevronButton = styled.button `
19
+ background: transparent;
20
+ border: none;
21
+ color: ${({ theme, disabled }) => disabled ? theme.colors.onsurface["copy-light"] || "#B0B0B0" : "#222"};
22
+ font-size: 32px;
23
+ height: 40px;
24
+ border-radius: 10px;
25
+ display: flex;
26
+ align-items: center;
27
+ justify-content: center;
28
+ cursor: ${({ disabled }) => (disabled ? "not-allowed" : "pointer")};
29
+ margin-right: ${({ $right }) => ($right ? "0" : "8px")};
30
+ margin-left: ${({ $right }) => ($right ? "8px" : "0")};
31
+ transition: color 0.2s;
32
+ `;
33
+ const ChevronIcon = ({ left = false }) => (_jsx("svg", { width: "28", height: "28", viewBox: "0 0 28 28", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: left ? "M17.5 21L11.5 14L17.5 7" : "M10.5 7L16.5 14L10.5 21", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round" }) }));
34
+ const getSimplePages = (current, total) => {
35
+ // Always show 1-5, but don't exceed total
36
+ const pages = [];
37
+ for (let index = 1; index <= Math.min(5, total); index++) {
38
+ pages.push(index);
39
+ }
40
+ return pages;
41
+ };
42
+ const CustomPagination = ({ paginationStyle = PaginationStyle.SIMPLE, current = 1, total = 1, pageSize = 10, onChange, ...properties }) => {
43
+ const pageCount = Math.ceil(total / pageSize);
44
+ const handleChange = (page) => {
45
+ if (onChange)
46
+ onChange(page, pageSize);
47
+ };
48
+ if (paginationStyle === PaginationStyle.SIMPLE) {
49
+ const pages = getSimplePages(current, pageCount);
50
+ return (_jsxs(PaginationContainer, { children: [_jsx(ChevronButton, { onClick: () => handleChange(current - 1), disabled: current === 1, "aria-label": "Previous Page", children: _jsx(ChevronIcon, { left: true }) }), pages.map((number_) => (_jsx(PaginationNumber, { active: number_ === current, onClick: () => handleChange(number_), "aria-label": `Page ${number_}`, children: number_ }, number_))), _jsx(ChevronButton, { onClick: () => handleChange(current + 1), disabled: current === pageCount, "aria-label": "Next Page", "$right": true, children: _jsx(ChevronIcon, {}) })] }));
51
+ }
52
+ if (paginationStyle === PaginationStyle.TRUNCATED) {
53
+ // Show 1 2 3 4 5 ... last
54
+ const pages = [];
55
+ for (let index = 1; index <= Math.min(5, pageCount); index++) {
56
+ pages.push(index);
57
+ }
58
+ return (_jsxs(PaginationContainer, { children: [_jsx(ChevronButton, { onClick: () => handleChange(current - 1), disabled: current === 1, "aria-label": "Previous Page", children: _jsx(ChevronIcon, { left: true }) }), pages.map((number_) => (_jsx(PaginationNumber, { active: number_ === current, onClick: () => handleChange(number_), "aria-label": `Page ${number_}`, children: number_ }, number_))), pageCount > 5 && (_jsxs(_Fragment, { children: [_jsx("span", { style: {
59
+ color: "#7F7F7F",
60
+ fontWeight: 600,
61
+ fontSize: 16,
62
+ margin: "0 8px",
63
+ display: "flex",
64
+ alignItems: "center",
65
+ justifyContent: "center",
66
+ paddingBottom: 10,
67
+ }, children: "..." }), _jsx(PaginationNumber, { active: current === pageCount, onClick: () => handleChange(pageCount), "aria-label": `Page ${pageCount}`, children: pageCount }, pageCount)] })), _jsx(ChevronButton, { onClick: () => handleChange(current + 1), disabled: current === pageCount, "aria-label": "Next Page", "$right": true, children: _jsx(ChevronIcon, {}) })] }));
68
+ }
69
+ if (paginationStyle === PaginationStyle.CENTERED) {
70
+ // Show 1 ... left mid mid mid mid ... last
71
+ // Always show 5 numbers, current centered if possible
72
+ const pages = [];
73
+ const visibleCount = 5;
74
+ const sideCount = 2; // numbers to show on each side of current
75
+ let start = Math.max(2, current - 2);
76
+ let end = Math.min(pageCount - 1, current + 2);
77
+ // Adjust if near the start
78
+ if (current <= 3) {
79
+ start = 2;
80
+ end = 6;
81
+ }
82
+ // Adjust if near the end
83
+ if (current >= pageCount - 2) {
84
+ start = pageCount - 4;
85
+ end = pageCount - 1;
86
+ }
87
+ start = Math.max(2, start);
88
+ end = Math.min(pageCount - 1, end);
89
+ // Always show first page
90
+ pages.push(1);
91
+ // Show left ellipsis if needed
92
+ if (start > 2) {
93
+ pages.push("left-ellipsis");
94
+ }
95
+ // Show middle pages
96
+ for (let index = start; index <= end; index++) {
97
+ pages.push(index);
98
+ }
99
+ // Show right ellipsis if needed
100
+ if (end < pageCount - 1) {
101
+ pages.push("right-ellipsis");
102
+ }
103
+ // Always show last page if more than 1
104
+ if (pageCount > 1) {
105
+ pages.push(pageCount);
106
+ }
107
+ return (_jsxs(PaginationContainer, { children: [_jsx(ChevronButton, { onClick: () => handleChange(current - 1), disabled: current === 1, "aria-label": "Previous Page", children: _jsx(ChevronIcon, { left: true }) }), pages.map((number_, index) => {
108
+ if (number_ === "left-ellipsis" || number_ === "right-ellipsis") {
109
+ return (_jsx("span", { style: {
110
+ color: "#7F7F7FB0",
111
+ fontWeight: 600,
112
+ fontSize: 16,
113
+ margin: "0 8px",
114
+ height: "40px",
115
+ display: "flex",
116
+ alignItems: "center",
117
+ justifyContent: "center",
118
+ paddingBottom: 10,
119
+ }, children: "..." }, number_ + index));
120
+ }
121
+ return (_jsx(PaginationNumber, { active: number_ === current, onClick: () => typeof number_ === "number" && handleChange(number_), "aria-label": `Page ${number_}`, children: number_ }, number_));
122
+ }), _jsx(ChevronButton, { onClick: () => handleChange(current + 1), disabled: current === pageCount, "aria-label": "Next Page", "$right": true, children: _jsx(ChevronIcon, {}) })] }));
123
+ }
124
+ if (paginationStyle === PaginationStyle.END_FOCUSED) {
125
+ // Show 1 ... last 5 pages
126
+ const pages = [];
127
+ // Always show first page
128
+ pages.push(1);
129
+ // If more than 6 pages, show ellipsis
130
+ if (pageCount > 6) {
131
+ pages.push("left-ellipsis");
132
+ }
133
+ // Show last 5 pages
134
+ const start = Math.max(2, pageCount - 4);
135
+ for (let index = start; index <= pageCount; index++) {
136
+ pages.push(index);
137
+ }
138
+ return (_jsxs(PaginationContainer, { children: [_jsx(ChevronButton, { onClick: () => handleChange(current - 1), disabled: current === 1, "aria-label": "Previous Page", children: _jsx(ChevronIcon, { left: true }) }), pages.map((number_, index) => {
139
+ if (number_ === "left-ellipsis") {
140
+ return (_jsx("span", { style: {
141
+ color: "#7F7F7F",
142
+ fontWeight: 600,
143
+ fontSize: 18,
144
+ margin: "0 8px",
145
+ display: "flex",
146
+ alignItems: "center",
147
+ justifyContent: "center",
148
+ height: "40px",
149
+ paddingBottom: 10,
150
+ }, children: "..." }, number_ + index));
151
+ }
152
+ return (_jsx(PaginationNumber, { active: number_ === current, onClick: () => typeof number_ === "number" && handleChange(number_), "aria-label": `Page ${number_}`, children: number_ }, number_));
153
+ }), _jsx(ChevronButton, { onClick: () => handleChange(current + 1), disabled: current === pageCount, "aria-label": "Next Page", "$right": true, children: _jsx(ChevronIcon, {}) })] }));
154
+ }
155
+ // Fallback for other styles (not implemented yet)
156
+ return null;
157
+ };
158
+ export default CustomPagination;
@@ -0,0 +1,7 @@
1
+ import React from "react";
2
+ interface PaginationNumberProperties extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
+ active?: boolean;
4
+ children: React.ReactNode;
5
+ }
6
+ export declare const PaginationNumber: React.FC<PaginationNumberProperties>;
7
+ export {};
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import styled from "styled-components";
3
+ import Typography from "../../Typography";
4
+ const NumberButton = styled.button `
5
+ background: ${({ $active, theme }) => $active ? theme.colors.primary.default.backgroundColor : "transparent"};
6
+ color: ${({ $active, theme }) => $active ? "#fff" : theme.colors.onsurface["copy-light"] || "#6C6C6C"};
7
+ border: none;
8
+ border-radius: 4px;
9
+ min-width: 24px;
10
+ height: 24px;
11
+ padding: 4px 7px;
12
+ font-size: 16px;
13
+ font-weight: 600;
14
+ margin: 0 4px;
15
+ cursor: pointer;
16
+ transition: background 0.2s, color 0.2s;
17
+ display: flex;
18
+ align-items: center;
19
+ justify-content: center;
20
+ font-family: inherit;
21
+ white-space: nowrap;
22
+
23
+ &:hover {
24
+ background: ${({ $active, theme }) => $active
25
+ ? theme.colors.primary.default.backgroundColor
26
+ : theme.colors.primary.default.backgroundColor + "22"};
27
+ color: #fff;
28
+ }
29
+ `;
30
+ export const PaginationNumber = ({ active, children, ...properties }) => (_jsx(NumberButton, { "$active": active, "aria-current": active ? "page" : undefined, ...properties, children: _jsx(Typography, { variant: "digits3", color: active ? "white" : "#6C6C6C", children: children }) }));
@@ -0,0 +1,14 @@
1
+ import { TableProps } from "antd";
2
+ import { type GenesisTheme } from "@gobolt/genesis/styles/theme/genesis-theme.types";
3
+ export interface StyledTableProps<T = any> extends TableProps<T> {
4
+ theme?: GenesisTheme;
5
+ $isMainContentCell?: boolean;
6
+ }
7
+ export declare const getGenesisClass: ({ colors, borderRadius, sizing, typography, components }: {
8
+ colors: any;
9
+ borderRadius: any;
10
+ sizing: any;
11
+ typography: any;
12
+ components: any;
13
+ }, $isMainContentCell: any) => string;
14
+ export declare const Table: any;
@@ -0,0 +1,64 @@
1
+ import styled from "@gobolt/genesis/utils/styled";
2
+ import { Table as AntTable } from "antd";
3
+ export const getGenesisClass = ({ colors, borderRadius, sizing, typography, components }, $isMainContentCell) => {
4
+ // Log the hovered color and the entire tableCell object
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
17
+ ? colors.onsurface.copy
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
38
+ ? colors.onsurface.copy
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
+ `;
59
+ };
60
+ export const Table = styled(AntTable) `
61
+ ${({ theme, $isMainContentCell }) => {
62
+ return getGenesisClass(theme, $isMainContentCell);
63
+ }}
64
+ `;
@@ -0,0 +1,26 @@
1
+ import type { ColumnsType } from "antd/es/table";
2
+ import type { SelectionType } from "./Table";
3
+ export type UseTableConfig = {
4
+ columns: ColumnsType<any>;
5
+ filters?: Record<string, any>;
6
+ fetchUrl?: string;
7
+ fetchOptions?: RequestInit;
8
+ selectionType?: SelectionType;
9
+ simulateDelay?: number;
10
+ disableRowSelection?: (record: any) => unknown;
11
+ disableAutoFetch?: boolean;
12
+ dataSource?: any[];
13
+ };
14
+ export declare const useTable: <T extends Record<string, any>>(useTableConfig: any) => {
15
+ isLoading: boolean;
16
+ rowSelection: {
17
+ type: SelectionType;
18
+ onChange: (selectedRowKeys: React.Key[], selectedRows: T[]) => void;
19
+ getCheckboxProps: (record: any) => unknown;
20
+ };
21
+ selectedRows: T[];
22
+ updateDataSource: (newDataSource: T[]) => void;
23
+ dataSource: T[];
24
+ columns: ColumnsType<T>;
25
+ error: Error | null;
26
+ };
@@ -0,0 +1,141 @@
1
+ import { useState, useEffect, useCallback } from "react";
2
+ // Function to sort data by field and order
3
+ const sortData = (data, sorter) => {
4
+ // Handle case when no sorting is applied
5
+ if (!sorter || (Array.isArray(sorter) && sorter.length === 0)) {
6
+ return [...data];
7
+ }
8
+ // Handle multiple sorters
9
+ if (Array.isArray(sorter)) {
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;
21
+ }
22
+ return 0;
23
+ });
24
+ }
25
+ // Handle single sorter
26
+ if (sorter.field) {
27
+ const field = sorter.field;
28
+ return [...data].sort((a, b) => {
29
+ const aValue = a[field];
30
+ const bValue = b[field];
31
+ if (sorter.order === "ascend") {
32
+ if (aValue < bValue)
33
+ return -1;
34
+ if (aValue > bValue)
35
+ return 1;
36
+ return 0;
37
+ }
38
+ if (sorter.order === "descend") {
39
+ if (aValue < bValue)
40
+ return 1;
41
+ if (aValue > bValue)
42
+ return -1;
43
+ return 0;
44
+ }
45
+ return 0;
46
+ });
47
+ }
48
+ return [...data];
49
+ };
50
+ /*
51
+ Example of disableRowSelection function which can be passed to the useTable hook
52
+ const disableRowSelection = (record: any) => ({
53
+ disabled: record.status === "completed", // Column configuration not to be checked
54
+ name: record.status.toString(),
55
+ });
56
+ */
57
+ const defaultRowSelection = (record) => ({
58
+ disabled: false, // Add your disable logic here
59
+ name: record.id,
60
+ });
61
+ export const useTable = (useTableConfig) => {
62
+ const [isLoading, setLoading] = useState(true);
63
+ const { columns, filters = null, fetchUrl = "/table/data", fetchOptions = {
64
+ method: "POST",
65
+ headers: {
66
+ "Content-Type": "application/json",
67
+ },
68
+ body: JSON.stringify(filters),
69
+ }, selectionType = "checkbox", simulateDelay = 0, disableRowSelection = defaultRowSelection, disableAutoFetch = false, dataSource: initialDataSource = [], } = useTableConfig;
70
+ // State to hold the original data and the current data
71
+ const [originalData, setOriginalData] = useState(initialDataSource);
72
+ const [data, setData] = useState({
73
+ dataSource: initialDataSource,
74
+ columns,
75
+ error: null,
76
+ });
77
+ const [selectedRows, setSelectedRows] = useState([]);
78
+ // Load initial data
79
+ useEffect(() => {
80
+ // If auto-fetch is disabled and we have initial data, skip fetching
81
+ if (disableAutoFetch && initialDataSource.length > 0) {
82
+ setLoading(false);
83
+ return;
84
+ }
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
+ };
110
+ if (simulateDelay > 0) {
111
+ setTimeout(fetchData, simulateDelay);
112
+ }
113
+ else {
114
+ fetchData();
115
+ }
116
+ }, [fetchOptions, disableAutoFetch, initialDataSource]);
117
+ const handleRowSelection = useCallback((selectedRowKeys, selectedRows) => {
118
+ console.log("Row Selected:", selectedRowKeys, selectedRows);
119
+ setSelectedRows(selectedRows);
120
+ }, []);
121
+ // Function to manually update data source (for external data fetching)
122
+ const updateDataSource = useCallback((newDataSource) => {
123
+ setOriginalData(newDataSource);
124
+ setData((prev) => ({
125
+ ...prev,
126
+ dataSource: newDataSource,
127
+ }));
128
+ }, []);
129
+ const rowSelection = {
130
+ type: selectionType,
131
+ onChange: handleRowSelection,
132
+ getCheckboxProps: disableRowSelection,
133
+ };
134
+ return {
135
+ ...data,
136
+ isLoading,
137
+ rowSelection,
138
+ selectedRows,
139
+ updateDataSource,
140
+ };
141
+ };
@@ -0,0 +1,17 @@
1
+ import React, { CSSProperties } from "react";
2
+ import { TYPE, TYPOGRAPHY_VARIANT, STATE } from "@gobolt/genesis/constants";
3
+ type HeadingLevel = 1 | 2 | 3 | 4 | 5;
4
+ export interface TypographyProps {
5
+ children: React.ReactNode;
6
+ variant?: keyof typeof TYPOGRAPHY_VARIANT;
7
+ themeType?: keyof typeof TYPE;
8
+ state?: keyof typeof STATE;
9
+ color?: string;
10
+ level?: HeadingLevel;
11
+ isText?: boolean;
12
+ isFullWidth?: boolean;
13
+ style?: CSSProperties;
14
+ isDisabled?: boolean;
15
+ }
16
+ declare const Typography: ({ children, themeType, variant, state, color, isText, isFullWidth, style, isDisabled, ...rest }: TypographyProps) => import("react/jsx-runtime").JSX.Element;
17
+ export default Typography;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as S from "./styles";
3
+ import { useGenesis } from "@gobolt/genesis/providers";
4
+ import { TYPE, TYPOGRAPHY_VARIANT, STATE, } from "@gobolt/genesis/constants";
5
+ const Typography = ({ children, themeType = TYPE.secondary, variant = TYPOGRAPHY_VARIANT.body1, state = STATE.active, color, isText = false, isFullWidth, style, isDisabled, ...rest }) => {
6
+ const { breakpoint } = useGenesis();
7
+ if (variant.startsWith("display") || variant.startsWith("heading")) {
8
+ const level = variant.split("heading")[1] || variant.split("display")[1];
9
+ return (_jsx(S.Headline, { state: state, "$themeType": themeType, variant: variant, breakpoint: breakpoint, color: color, level: Number.parseInt(level), "$isFullWidth": isFullWidth, style: style, disabled: isDisabled, ...rest, children: children }));
10
+ }
11
+ if (isText) {
12
+ return (_jsx(S.Text, { state: state, "$themeType": themeType, variant: variant, breakpoint: breakpoint, color: color, "$isFullWidth": isFullWidth, style: style, disabled: isDisabled, ...rest, children: children }));
13
+ }
14
+ return (_jsx(S.Paragraph, { state: state, "$themeType": themeType, variant: variant, breakpoint: breakpoint, color: color, "$isFullWidth": isFullWidth, style: style, disabled: isDisabled, ...rest, children: children }));
15
+ };
16
+ export default Typography;
@@ -0,0 +1,2 @@
1
+ export { default } from "./Typography";
2
+ export type { TypographyProps } from "./Typography";
@@ -0,0 +1 @@
1
+ export { default } from "./Typography";
@@ -0,0 +1,3 @@
1
+ export declare const Headline: any;
2
+ export declare const Paragraph: any;
3
+ export declare const Text: any;
@@ -0,0 +1,54 @@
1
+ import styled from "@gobolt/genesis/utils/styled";
2
+ import { Typography as AntTypography } from "antd";
3
+ const getVariant = (typography, variant, breakpoint) => {
4
+ return `
5
+ font-size: ${typography[breakpoint][variant].fontSize}px !important;
6
+ line-height: ${typography[breakpoint][variant].lineHeight};
7
+ letter-spacing: ${typography[breakpoint][variant].letterSpacing}px;
8
+ font-weight: ${typography[breakpoint][variant].fontWeight};
9
+ `;
10
+ };
11
+ const getColor = (color, colors, $themeType) => {
12
+ if (color) {
13
+ return color;
14
+ }
15
+ return colors[$themeType].active.color;
16
+ };
17
+ const getFontFamily = (variant) => {
18
+ return `
19
+ ${variant.includes("digits")
20
+ ? "'Roboto Mono', sans-serif"
21
+ : "'Inter', sans-serif"} !important;
22
+ `;
23
+ };
24
+ const getGenesisTypographyClass = ({ colors, typography }, $themeType, variant, state, breakpoint, color, $isFullWidth) => `
25
+ &.ant-typography {
26
+ font-family: ${getFontFamily(variant)};
27
+ color: ${getColor(color, colors, $themeType)} !important;
28
+ ${getVariant(typography, variant, breakpoint)}
29
+ margin-bottom: 0 !important;
30
+ width: ${$isFullWidth ? "100%" : "auto"};
31
+ line-height: 1;
32
+
33
+ &:disabled {
34
+ color: ${colors.status.disabled.default} !important;
35
+ userSelect: none;
36
+ cursor: not-allowed;
37
+ }
38
+ }
39
+ `;
40
+ export const Headline = styled(AntTypography.Title) `
41
+ ${({ theme, $themeType, variant, state, breakpoint, color, $isFullWidth, }) => {
42
+ return getGenesisTypographyClass(theme, $themeType, variant, state, breakpoint, color, $isFullWidth);
43
+ }}
44
+ `;
45
+ export const Paragraph = styled(AntTypography.Paragraph) `
46
+ ${({ theme, $themeType, variant, state, breakpoint, color, $isFullWidth, }) => {
47
+ return getGenesisTypographyClass(theme, $themeType, variant, state, breakpoint, color, $isFullWidth);
48
+ }}
49
+ `;
50
+ export const Text = styled(AntTypography.Text) `
51
+ ${({ theme, $themeType, variant, state, breakpoint, color, $isFullWidth, }) => {
52
+ return getGenesisTypographyClass(theme, $themeType, variant, state, breakpoint, color, $isFullWidth);
53
+ }}
54
+ `;