pace-table-lib 1.0.1 → 1.0.3
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/README.md +181 -4
- package/dist/components/StaticTable/HelperFunctions.d.ts +3 -0
- package/dist/components/StaticTable/StaticTableConst.d.ts +2 -0
- package/dist/components/StaticTable/StaticTableTypeDec.types.d.ts +12 -0
- package/dist/pace-table-lib.es.js +3376 -3273
- package/dist/pace-table-lib.umd.js +15 -15
- package/dist/stats.html +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,189 @@
|
|
|
1
|
-
|
|
1
|
+
---
|
|
2
|
+
|
|
3
|
+
# pace-table-lib
|
|
2
4
|
|
|
3
|
-
A lightweight
|
|
5
|
+
A lightweight React component library for rendering **highly-configurable, Excel-like static tables** with fixed headers, custom styles, and flexible measure formatting.
|
|
4
6
|
|
|
5
7
|
---
|
|
6
8
|
|
|
7
|
-
##
|
|
9
|
+
## ✨ Features
|
|
10
|
+
|
|
11
|
+
* **Fixed left columns** (freeze columns/rows for better readability)
|
|
12
|
+
* **Grand total, row total, and column total support**
|
|
13
|
+
* **Custom number formatting** (comma separators, precision, display units, etc.)
|
|
14
|
+
* Flexible styling via a single `tableStyleProps` object
|
|
15
|
+
* Fully typed with **TypeScript**
|
|
8
16
|
|
|
9
|
-
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## 📦 Installation
|
|
10
20
|
|
|
11
21
|
```bash
|
|
12
22
|
npm install pace-table-lib
|
|
23
|
+
# or
|
|
24
|
+
yarn add pace-table-lib
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 🔑 Basic Usage
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import React from "react";
|
|
33
|
+
import { StaticTable } from "pace-table-lib";
|
|
34
|
+
import { createMeasureFormattingMapping } from "./measureFormatHelper";
|
|
35
|
+
|
|
36
|
+
export default function App() {
|
|
37
|
+
const tableData = /* your JSON from API or file */;
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<StaticTable
|
|
41
|
+
tableData={tableData?.TableData}
|
|
42
|
+
leftFixedCellNameList={tableData?.leftFixedCellNameList ?? [""]}
|
|
43
|
+
tableStyleProps={tableData?.TableStyle?.TableStyle?.Style}
|
|
44
|
+
tableWidth={800}
|
|
45
|
+
tableHeight={600}
|
|
46
|
+
measureFormatConfigs={() => createMeasureFormattingMapping()}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## ⚙️ Props
|
|
55
|
+
|
|
56
|
+
| Prop | Type | Required | Description |
|
|
57
|
+
| ------------------------- | --------------------------- | -------- | ----------------------------------------------------------- |
|
|
58
|
+
| **tableData** | `TableData` | ✅ | Data object describing rows, columns, totals, and measures. |
|
|
59
|
+
| **leftFixedCellNameList** | `string[]` | ❌ | Names of columns to freeze on the left. |
|
|
60
|
+
| **tableStyleProps** | `object` | ❌ | Style configuration (colors, fonts, borders, etc.). |
|
|
61
|
+
| **tableWidth** | `number` | ✅ | Total table width in pixels. |
|
|
62
|
+
| **tableHeight** | `number` | ✅ | Total table height in pixels. |
|
|
63
|
+
| **measureFormatConfigs** | `() => MeasureFormatConfig` | ✅ | Function returning measure formatting rules. |
|
|
64
|
+
|
|
65
|
+
### `MeasureFormatConfig`
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
{
|
|
69
|
+
measureName: string; // e.g., "New Patients"
|
|
70
|
+
numberFormat: string; // e.g., "Comma Separated"
|
|
71
|
+
displayUnit: string; // e.g., "None", "K", "M"
|
|
72
|
+
decimalPrecision: number; // e.g., 2
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Example:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
export const createMeasureFormattingMapping = () => ({
|
|
80
|
+
measureName: "New Patients",
|
|
81
|
+
numberFormat: "Comma Separated",
|
|
82
|
+
displayUnit: "None",
|
|
83
|
+
decimalPrecision: 2
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## 📐 Table Data Structure
|
|
90
|
+
|
|
91
|
+
The component expects a JSON object similar to:
|
|
92
|
+
|
|
93
|
+
```jsonc
|
|
94
|
+
{
|
|
95
|
+
"TableData": {
|
|
96
|
+
"customSortRowwise": ["1L", "2L", "Adj"],
|
|
97
|
+
"grandTotal": 400701,
|
|
98
|
+
"measuresBySlice": [
|
|
99
|
+
{
|
|
100
|
+
"sliceMark": ["1L", "Base"],
|
|
101
|
+
"measures": [0, 0, 81087],
|
|
102
|
+
"rowTotal": 81087
|
|
103
|
+
},
|
|
104
|
+
...
|
|
105
|
+
],
|
|
106
|
+
"columnTotalRow": [
|
|
107
|
+
{ "columnTotal": 148247, "maxValueInColumn": 89526, "minValueInColumn": 0 }
|
|
108
|
+
],
|
|
109
|
+
"dimensionMarks": [["HCC"], ["RCC"], ["SCLC"]],
|
|
110
|
+
"totalNumberOfRows": 9
|
|
111
|
+
},
|
|
112
|
+
"leftFixedCellNameList": ["LOT", "Scenario"],
|
|
113
|
+
"TableStyle": {
|
|
114
|
+
"TableStyle": {
|
|
115
|
+
"Style": { /* font, color, border config */ }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Use your own API or static file to populate this structure.
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## 🖌 Styling
|
|
126
|
+
|
|
127
|
+
Pass the `tableStyleProps` from your data:
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
tableStyleProps={tableData?.TableStyle?.TableStyle?.Style}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
It supports:
|
|
134
|
+
|
|
135
|
+
* **Row/Column header colors**
|
|
136
|
+
* Borders & grid lines
|
|
137
|
+
* Conditional formatting (if enabled in your data)
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## 🧩 TypeScript Support
|
|
142
|
+
|
|
143
|
+
The library ships with full type definitions. Import types as needed:
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
import { TableData, MeasureFormatConfig } from "pace-table-lib";
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## 🛠 Development
|
|
152
|
+
|
|
153
|
+
Clone the repo and run:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npm install
|
|
157
|
+
npm run dev
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## 📄 License
|
|
163
|
+
|
|
164
|
+
MIT © 2025
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
### Quick Example
|
|
169
|
+
|
|
170
|
+
```tsx
|
|
171
|
+
<StaticTable
|
|
172
|
+
tableData={mockData.TableData}
|
|
173
|
+
leftFixedCellNameList={["LOT", "Scenario"]}
|
|
174
|
+
tableStyleProps={mockData.TableStyle.TableStyle.Style}
|
|
175
|
+
tableWidth={1000}
|
|
176
|
+
tableHeight={600}
|
|
177
|
+
measureFormatConfigs={() => ({
|
|
178
|
+
measureName: "New Patients",
|
|
179
|
+
numberFormat: "Comma Separated",
|
|
180
|
+
displayUnit: "None",
|
|
181
|
+
decimalPrecision: 2
|
|
182
|
+
})}
|
|
183
|
+
/>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
This will render a scrollable, Excel-like table with frozen left columns and comma-separated numbers.
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
@@ -9,3 +9,6 @@ export declare function formatValue(value: any, format: string, decimalValues?:
|
|
|
9
9
|
export declare function getFontStyleObj(stylePayload: any): CSSProperties;
|
|
10
10
|
export declare function interpolateColor(minColor: string, maxColor: string, ratio: number): string;
|
|
11
11
|
export declare function computeMatrix<T>(rawDataMatrix: number[][], mode: "All" | "Column-wise" | "Row-wise", transformFn: (v: number, min: number, max: number) => T): T[][];
|
|
12
|
+
export declare function compareVal(a: number, op: string, b: number): boolean;
|
|
13
|
+
export declare function applyConditionalFormatting(style: CSSProperties, conFormat?: any): CSSProperties;
|
|
14
|
+
export declare function applyFormat(obj: any, format: any): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CONDITIONAL_FORMAT_FOR } from "./StaticTableTypeDec.types";
|
|
1
2
|
export declare const TOTAL = "Total";
|
|
2
3
|
export declare const BORDER_STYLE = "1px solid #ccc";
|
|
3
4
|
export declare const MONTHS_SHORT: string[];
|
|
@@ -62,3 +63,4 @@ export declare const VALUE_FORMAT_OBJ: {
|
|
|
62
63
|
readonly COMMA_SHORT: ",";
|
|
63
64
|
readonly COMMA: "Comma Separated";
|
|
64
65
|
};
|
|
66
|
+
export declare const ConFormattingTypeMap: Record<CONDITIONAL_FORMAT_FOR, string>;
|
|
@@ -155,6 +155,7 @@ type TableStyleConfig = {
|
|
|
155
155
|
DataFieldVerticalLineStyle: "solid" | string;
|
|
156
156
|
DataFieldHorizontalLineStyle: "solid" | string;
|
|
157
157
|
NumberFormat: "Comma Separated" | string;
|
|
158
|
+
percentageBy?: "Column-wise" | "Row-wise";
|
|
158
159
|
};
|
|
159
160
|
KPI: {
|
|
160
161
|
KPIBaseFormat: "All" | "Column-wise" | "Row-wise";
|
|
@@ -230,4 +231,15 @@ type TableStyleConfig = {
|
|
|
230
231
|
idOfAppliedStyle: string;
|
|
231
232
|
};
|
|
232
233
|
};
|
|
234
|
+
export declare enum CONDITIONAL_FORMAT_FOR {
|
|
235
|
+
VALUE = 0,
|
|
236
|
+
ROW = 1,
|
|
237
|
+
COLUMN = 2
|
|
238
|
+
}
|
|
239
|
+
export declare enum STYLE_FOR {
|
|
240
|
+
CORNER = 0,
|
|
241
|
+
COLUMN = 1,
|
|
242
|
+
ROW = 2,
|
|
243
|
+
DATA_CELL = 3
|
|
244
|
+
}
|
|
233
245
|
export {};
|