@agilant/toga-blox 1.0.97 → 1.0.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { CellProps } from "react-table";
|
|
3
|
-
/** Config each column might have */
|
|
4
3
|
export interface SharedColumnConfig {
|
|
5
4
|
key: string;
|
|
6
5
|
type?: string;
|
|
@@ -11,7 +10,6 @@ export interface SharedColumnConfig {
|
|
|
11
10
|
rightImage?: string;
|
|
12
11
|
transform?: (value: any) => any;
|
|
13
12
|
}
|
|
14
|
-
/** Minimally typed shape for returned React Table columns */
|
|
15
13
|
export interface TableColumn {
|
|
16
14
|
Header: string | (() => JSX.Element);
|
|
17
15
|
accessor: string;
|
|
@@ -20,10 +18,6 @@ export interface TableColumn {
|
|
|
20
18
|
}, string | React.ReactElement>) => JSX.Element;
|
|
21
19
|
sticky?: "left" | "right";
|
|
22
20
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Callbacks for each app to provide their own "implementation details":
|
|
25
|
-
* - e.g. how to render icons, how to handle images, etc.
|
|
26
|
-
*/
|
|
27
21
|
export interface Renderers {
|
|
28
22
|
renderIcon?: (iconName: string, style?: "solid" | "regular") => JSX.Element;
|
|
29
23
|
renderImage?: (props: {
|
|
@@ -37,11 +31,12 @@ export interface Renderers {
|
|
|
37
31
|
renderCurrency?: (value: string) => string;
|
|
38
32
|
}
|
|
39
33
|
/**
|
|
40
|
-
*
|
|
41
|
-
|
|
34
|
+
* The main library function that shapes columns
|
|
35
|
+
*/
|
|
36
|
+
declare function formatTableData(columnTitles: string[], accessors: string[], columnConfigs: any[], renderers?: Renderers): TableColumn[];
|
|
37
|
+
/**
|
|
38
|
+
* Generate "col1", "col2", etc.
|
|
42
39
|
*/
|
|
43
|
-
declare function formatTableData(columnTitles: string[], accessors: string[], columnConfigs: SharedColumnConfig[], renderers?: Renderers): TableColumn[];
|
|
44
|
-
/** Simple helper to generate the default "col1", "col2", ... accessors */
|
|
45
40
|
declare function generateAccessors(columnTitles: string[]): string[];
|
|
46
41
|
export { formatTableData, generateAccessors };
|
|
47
42
|
declare const _default: {
|
|
@@ -1,7 +1,33 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
function transformBackendConfig(backendConfig) {
|
|
3
|
+
const finalConfig = {
|
|
4
|
+
key: backendConfig.key,
|
|
5
|
+
type: backendConfig.type ?? "DEFAULT",
|
|
6
|
+
linkClasses: backendConfig.linkClasses ?? "",
|
|
7
|
+
transform: backendConfig.transform,
|
|
8
|
+
};
|
|
9
|
+
if (backendConfig.hasStatus) {
|
|
10
|
+
finalConfig.type = "STATUS";
|
|
11
|
+
}
|
|
12
|
+
if (backendConfig.hasCurrency) {
|
|
13
|
+
finalConfig.type = "CURRENCY";
|
|
14
|
+
}
|
|
15
|
+
if (backendConfig.hasLeftIcon) {
|
|
16
|
+
finalConfig.leftIcon = "check";
|
|
17
|
+
}
|
|
18
|
+
if (backendConfig.hasRightIcon) {
|
|
19
|
+
finalConfig.rightIcon = "arrowRight";
|
|
20
|
+
}
|
|
21
|
+
if (backendConfig.hasLeftImage) {
|
|
22
|
+
finalConfig.leftImage = "https://example.com/placeholder.png";
|
|
23
|
+
}
|
|
24
|
+
if (backendConfig.hasRightImage) {
|
|
25
|
+
finalConfig.rightImage = "https://example.com/placeholder.png";
|
|
26
|
+
}
|
|
27
|
+
return finalConfig;
|
|
28
|
+
}
|
|
2
29
|
/**
|
|
3
|
-
*
|
|
4
|
-
* This version delegates certain rendering details to the `renderers`.
|
|
30
|
+
* The main library function that shapes columns
|
|
5
31
|
*/
|
|
6
32
|
function formatTableData(columnTitles, accessors, columnConfigs, renderers = {}) {
|
|
7
33
|
function renderCellContent(config) {
|
|
@@ -33,7 +59,6 @@ function formatTableData(columnTitles, accessors, columnConfigs, renderers = {})
|
|
|
33
59
|
}) }));
|
|
34
60
|
return renderContent(config, value, image, "right");
|
|
35
61
|
}
|
|
36
|
-
// 2. Check type (CURRENCY, STATUS, etc.)
|
|
37
62
|
switch (config.type) {
|
|
38
63
|
case "STATUS":
|
|
39
64
|
if (renderers.renderStatus && typeof value === "string") {
|
|
@@ -46,35 +71,32 @@ function formatTableData(columnTitles, accessors, columnConfigs, renderers = {})
|
|
|
46
71
|
return renderContent(config, formatted);
|
|
47
72
|
}
|
|
48
73
|
break;
|
|
49
|
-
// Add other type cases (BOOLEAN, NUMBER, DATE, etc.) as you see fit
|
|
50
74
|
}
|
|
51
|
-
// 3. If we get here, just render raw text
|
|
52
75
|
return (_jsx("div", { style: { display: "flex", alignItems: "center" }, children: typeof value === "string" ? _jsx("p", { children: value }) : value }));
|
|
53
76
|
};
|
|
54
77
|
}
|
|
55
78
|
function renderContent(config, value, content, position) {
|
|
56
79
|
return (_jsx("div", { style: { display: "flex", alignItems: "center" }, className: "flex w-full", children: config.linkClasses ? (_jsxs("a", { href: "#", className: `flex ${config.linkClasses}`, onClick: (e) => e.stopPropagation(), children: [position === "left" && content, typeof value === "string" ? _jsx("p", { children: value }) : value, position === "right" && content] })) : (_jsxs(_Fragment, { children: [position === "left" && content, typeof value === "string" ? _jsx("p", { children: value }) : value, position === "right" && content] })) }));
|
|
57
80
|
}
|
|
58
|
-
// Map each title to a column definition
|
|
59
81
|
const columns = columnTitles.map((title, i) => {
|
|
60
82
|
const accessor = accessors[i];
|
|
61
83
|
const key = `col${i + 1}`;
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
84
|
+
const rawBackendConfig = columnConfigs.find((c) => c.key === key) || {
|
|
85
|
+
key,
|
|
86
|
+
type: "DEFAULT",
|
|
87
|
+
};
|
|
88
|
+
const config = transformBackendConfig(rawBackendConfig);
|
|
67
89
|
return {
|
|
68
90
|
Header: title,
|
|
69
91
|
accessor,
|
|
70
92
|
Cell: ({ value }) => renderCellContent(config)({ value }),
|
|
71
93
|
};
|
|
72
94
|
});
|
|
73
|
-
// Return the final array of columns.
|
|
74
|
-
// (Apps can push a custom "sticky" col onto this if they want.)
|
|
75
95
|
return columns;
|
|
76
96
|
}
|
|
77
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* Generate "col1", "col2", etc.
|
|
99
|
+
*/
|
|
78
100
|
function generateAccessors(columnTitles) {
|
|
79
101
|
return columnTitles.map((_, index) => `col${index + 1}`);
|
|
80
102
|
}
|