@gpa-gemstone/react-table 1.2.58 → 1.2.59

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,470 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AdjustableTable = AdjustableTable;
4
- // ******************************************************************************************************
5
- // Table.tsx - Gbtc
6
- //
7
- // Copyright © 2023, Grid Protection Alliance. All Rights Reserved.
8
- //
9
- // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
10
- // the NOTICE file distributed with this work for additional information regarding copyright ownership.
11
- // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
12
- // file except in compliance with the License. You may obtain a copy of the License at:
13
- //
14
- // http://opensource.org/licenses/MIT
15
- //
16
- // Unless agreed to in writing, the subject software distributed under the License is distributed on an
17
- // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
18
- // License for the specific language governing permissions and limitations.
19
- //
20
- // Code Modification History:
21
- // ----------------------------------------------------------------------------------------------------
22
- // 11/18/2023 - C. Lackner
23
- // Generated original version of source code.
24
- // 05/31/2024 - C. Lackner
25
- // Refactored to fix sizing issues.
26
- // 12/04/2024 - G. Santos
27
- // Refactored to fix performance issues.
28
- //
29
- // ******************************************************************************************************
30
- const React = require("react");
31
- const _ = require("lodash");
32
- const Column_1 = require("./Column");
33
- const defaultTableStyle = {
34
- padding: 0,
35
- flex: 1,
36
- tableLayout: 'fixed',
37
- overflow: 'hidden',
38
- display: 'flex',
39
- flexDirection: 'column',
40
- marginBottom: 0,
41
- width: '100%'
42
- };
43
- const defaultHeadStyle = {
44
- fontSize: 'auto',
45
- tableLayout: 'fixed',
46
- display: 'table',
47
- width: '100%'
48
- };
49
- const defaultBodyStyle = {
50
- flex: 1,
51
- display: 'block',
52
- overflow: 'auto'
53
- };
54
- const defaultRowStyle = {
55
- display: 'table',
56
- tableLayout: 'fixed',
57
- width: '100%'
58
- };
59
- const defaultDataHeadStyle = {
60
- display: 'inline-block',
61
- position: 'relative',
62
- borderTop: 'none',
63
- width: 'auto'
64
- };
65
- const defaultDataCellStyle = {
66
- overflowX: 'hidden',
67
- display: 'inline-block',
68
- width: 'auto'
69
- };
70
- const IsColumnProps = (props) => ((props === null || props === void 0 ? void 0 : props['Key']) != null);
71
- function AdjustableTable(props) {
72
- const bodyRef = React.useRef(null);
73
- const colWidthsRef = React.useRef(new Map());
74
- const oldWidthRef = React.useRef(0);
75
- const [currentTableWidth, setCurrentTableWidth] = React.useState(0);
76
- const [scrolled, setScrolled] = React.useState(false);
77
- const [trigger, setTrigger] = React.useState(0);
78
- // Style consts
79
- const tableStyle = React.useMemo(() => (Object.assign(Object.assign({}, defaultTableStyle), props.TableStyle)), [props.TableStyle]);
80
- const headStyle = React.useMemo(() => (Object.assign(Object.assign({}, defaultHeadStyle), props.TheadStyle)), [props.TheadStyle]);
81
- const bodyStyle = React.useMemo(() => (Object.assign(Object.assign({}, defaultBodyStyle), props.TbodyStyle)), [props.TbodyStyle]);
82
- const rowStyle = React.useMemo(() => (Object.assign(Object.assign({}, defaultRowStyle), props.RowStyle)), [props.RowStyle]);
83
- // Send warning if styles are overridden
84
- React.useEffect(() => {
85
- if (props.TableStyle !== undefined)
86
- console.warn('TableStyle properties may be overridden if needed. consider using the defaults');
87
- if (props.TheadStyle !== undefined)
88
- console.warn('TheadStyle properties may be overridden if needed. consider using the defaults');
89
- if (props.TbodyStyle !== undefined)
90
- console.warn('TBodyStyle properties may be overridden if needed. consider using the defaults');
91
- if (props.RowStyle !== undefined)
92
- console.warn('RowStyle properties may be overridden if needed. consider using the defaults');
93
- }, []);
94
- // Measure widths and hide columns
95
- React.useLayoutEffect(() => {
96
- if (currentTableWidth <= 0)
97
- return;
98
- // Helper functions for the calculations
99
- const getWidthfromProps = (p, type) => {
100
- var _a, _b;
101
- // This priotizes rowstyling for width over header, since it was decided that they need to be the same
102
- if (((_a = p === null || p === void 0 ? void 0 : p.RowStyle) === null || _a === void 0 ? void 0 : _a[type]) !== undefined)
103
- return p.RowStyle[type];
104
- if (((_b = p === null || p === void 0 ? void 0 : p.HeaderStyle) === null || _b === void 0 ? void 0 : _b[type]) !== undefined)
105
- return p.HeaderStyle[type];
106
- return undefined;
107
- };
108
- // Construct base map
109
- const newMap = new Map();
110
- React.Children.forEach(props.children, (element) => {
111
- if (React.isValidElement(element) && IsColumnProps(element.props)) {
112
- if (newMap.get(element.props.Key) != null)
113
- console.error("Multiple of the same key detected in table, this will cause issues.");
114
- newMap.set(element.props.Key, { minWidth: 100, maxWidth: 1000, width: 100 });
115
- }
116
- });
117
- // If width is the same and keys are identical, we can skip the operation
118
- if (currentTableWidth === oldWidthRef.current &&
119
- (newMap.size === colWidthsRef.current.size &&
120
- ![...newMap.keys()].some(key => !colWidthsRef.current.has(key))))
121
- return;
122
- // Find and set widths for map
123
- ['minWidth', 'width', 'maxWidth'].forEach(type => {
124
- const widthsContainer = document.createElement("div");
125
- widthsContainer.style.height = '0px';
126
- widthsContainer.style.width = `${currentTableWidth}px`;
127
- // Append columns as divs for measurement
128
- const autoKeys = [];
129
- const measureKeys = [];
130
- React.Children.forEach(props.children, (element) => {
131
- if (React.isValidElement(element) && IsColumnProps(element.props)) {
132
- let widthValue = getWidthfromProps(element.props, type);
133
- if (type === 'width' && widthValue == null)
134
- widthValue = 'auto';
135
- if (widthValue != null) {
136
- if (widthValue === 'auto')
137
- autoKeys.push(element.props.Key);
138
- else {
139
- const widthElement = document.createElement("div");
140
- widthElement.id = element.props.Key + "_measurement";
141
- widthElement.style.height = '0px';
142
- if ((widthValue === null || widthValue === void 0 ? void 0 : widthValue.length) != null)
143
- widthElement.style.width = widthValue;
144
- else
145
- widthElement.style.width = `${widthValue}px`;
146
- widthsContainer.appendChild(widthElement);
147
- measureKeys.push(element.props.Key);
148
- }
149
- }
150
- }
151
- });
152
- document.body.appendChild(widthsContainer);
153
- // Handle Measurements
154
- let autoSpace = currentTableWidth;
155
- measureKeys.forEach(key => {
156
- const element = document.getElementById(key + "_measurement");
157
- if (element != null) {
158
- const widthObj = newMap.get(key);
159
- if (widthObj != null) {
160
- autoSpace -= element.clientWidth;
161
- widthObj[type] = element.clientWidth;
162
- }
163
- else
164
- console.error("Could not find width object for Key: " + key);
165
- }
166
- else
167
- console.error("Could not find measurement div with Key: " + key);
168
- });
169
- document.body.removeChild(widthsContainer);
170
- // Handle Autos (width type only)
171
- if (type === 'width' && autoKeys.length > 0) {
172
- const spacePerElement = Math.floor(autoSpace / autoKeys.length);
173
- autoKeys.forEach(key => {
174
- const widthObj = newMap.get(key);
175
- if (widthObj != null)
176
- widthObj[type] = spacePerElement;
177
- else
178
- console.error("Could not find width object for Key: " + key);
179
- });
180
- }
181
- let remainingSpace = currentTableWidth;
182
- [...newMap.keys()].forEach(key => {
183
- const widthObj = newMap.get(key);
184
- if (widthObj != null) {
185
- if (widthObj.minWidth <= remainingSpace) {
186
- // This follows behavior consistent with MDN documentation on how these width types should behave
187
- if (widthObj.minWidth > widthObj.width)
188
- widthObj.width = widthObj.minWidth;
189
- if (widthObj.minWidth > widthObj.maxWidth)
190
- widthObj.maxWidth = widthObj.minWidth;
191
- if (widthObj.width > widthObj.maxWidth)
192
- widthObj.width = widthObj.maxWidth;
193
- // Constrain Width to remainingSpace
194
- if (widthObj.width > remainingSpace)
195
- widthObj.width = remainingSpace;
196
- remainingSpace -= widthObj.width;
197
- }
198
- else {
199
- widthObj.minWidth = 0;
200
- widthObj.width = 0;
201
- widthObj.maxWidth = 0;
202
- }
203
- }
204
- else
205
- console.error("Could not find width object for Key: " + key);
206
- });
207
- });
208
- colWidthsRef.current = newMap;
209
- oldWidthRef.current = currentTableWidth;
210
- setTrigger(c => c + 1);
211
- }, [props.children, currentTableWidth]);
212
- const setTableWidth = React.useCallback(_.debounce(() => {
213
- var _a, _b, _c, _d;
214
- if (bodyRef.current == null)
215
- return;
216
- // Note: certain body classes may break this check if they set overflow to scroll
217
- let newScroll = false;
218
- if (((_a = props.TbodyStyle) === null || _a === void 0 ? void 0 : _a.overflowY) === 'scroll' || ((_b = props.TbodyStyle) === null || _b === void 0 ? void 0 : _b.overflow) === 'scroll')
219
- newScroll = true;
220
- else
221
- newScroll = bodyRef.current.clientHeight < bodyRef.current.scrollHeight;
222
- setScrolled(newScroll);
223
- setCurrentTableWidth(((_d = (_c = bodyRef.current) === null || _c === void 0 ? void 0 : _c.clientWidth) !== null && _d !== void 0 ? _d : 17) - (newScroll ? 0 : 17));
224
- }, 100), []);
225
- React.useEffect(() => {
226
- let resizeObserver;
227
- const intervalHandle = setInterval(() => {
228
- if ((bodyRef === null || bodyRef === void 0 ? void 0 : bodyRef.current) == null)
229
- return;
230
- resizeObserver = new ResizeObserver(() => {
231
- setTableWidth();
232
- });
233
- resizeObserver.observe(bodyRef.current);
234
- clearInterval(intervalHandle);
235
- }, 10);
236
- return () => {
237
- clearInterval(intervalHandle);
238
- if (resizeObserver != null && resizeObserver.disconnect != null)
239
- resizeObserver.disconnect();
240
- };
241
- }, []);
242
- const handleSort = React.useCallback((data, event) => {
243
- if (data.colKey !== null)
244
- props.OnSort(data, event);
245
- }, [props.OnSort]);
246
- return (React.createElement("table", { className: props.TableClass !== undefined ? props.TableClass : 'table table-hover', style: tableStyle },
247
- React.createElement(Header, { Class: props.TheadClass, Style: headStyle, SortKey: props.SortKey, Ascending: props.Ascending, LastColumn: props.LastColumn, OnSort: handleSort, ColWidths: colWidthsRef, Trigger: trigger, TriggerRerender: () => setTrigger(c => c + 1) }, props.children),
248
- React.createElement(Rows, { DragStart: props.OnDragStart, Data: props.Data, RowStyle: rowStyle, BodyStyle: bodyStyle, BodyClass: props.TbodyClass, OnClick: props.OnClick, Selected: props.Selected, KeySelector: props.KeySelector, BodyRef: bodyRef, BodyScrolled: scrolled, ColWidths: colWidthsRef, Trigger: trigger }, props.children),
249
- props.LastRow !== undefined ? (React.createElement("tfoot", { style: props.TfootStyle, className: props.TfootClass },
250
- React.createElement("tr", { style: props.RowStyle !== undefined ? Object.assign({}, props.RowStyle) : {} }, props.LastRow))) : null));
251
- }
252
- function Rows(props) {
253
- const bodyStyle = React.useMemo(() => (Object.assign(Object.assign({}, props.BodyStyle), { paddingRight: (props.BodyScrolled ? 0 : 17), display: "block" })), [props.BodyStyle, props.BodyScrolled]);
254
- const onClick = React.useCallback((e, item, index) => {
255
- if (props.OnClick !== undefined)
256
- props.OnClick({
257
- colKey: undefined,
258
- colField: undefined,
259
- row: item,
260
- data: null,
261
- index: index,
262
- }, e);
263
- }, [props.OnClick]);
264
- return (React.createElement("tbody", { style: bodyStyle, className: props.BodyClass, ref: props.BodyRef }, props.Data.map((d, i) => {
265
- const style = props.RowStyle !== undefined ? Object.assign({}, props.RowStyle) : {};
266
- if (style.cursor === undefined && (props.OnClick !== undefined || props.DragStart !== undefined))
267
- style.cursor = 'pointer';
268
- if (props.Selected !== undefined && props.Selected(d, i))
269
- style.backgroundColor = 'yellow';
270
- const key = props.KeySelector(d, i);
271
- return (React.createElement("tr", { key: key, style: style, onClick: (e) => onClick(e, d, i) }, React.Children.map(props.children, (element) => {
272
- var _a, _b, _c, _d, _e, _f;
273
- if (!React.isValidElement(element))
274
- return null;
275
- if (!IsColumnProps(element.props))
276
- return null;
277
- const colWidth = props.ColWidths.current.get(element.props.Key);
278
- if (colWidth == null || colWidth.width === 0)
279
- return null;
280
- let cursor = undefined;
281
- if (((_b = (_a = element.props) === null || _a === void 0 ? void 0 : _a.RowStyle) === null || _b === void 0 ? void 0 : _b.cursor) != null)
282
- cursor = element.props.RowStyle.cursor;
283
- else if ((props === null || props === void 0 ? void 0 : props.OnClick) != null)
284
- cursor = 'pointer';
285
- else if ((props === null || props === void 0 ? void 0 : props.DragStart) != null)
286
- cursor = 'grab';
287
- const style = Object.assign(Object.assign(Object.assign({}, defaultDataCellStyle), ((_c = element.props) === null || _c === void 0 ? void 0 : _c.RowStyle)), { width: colWidth.width, cursor: cursor });
288
- return (React.createElement(Column_1.ColumnDataWrapper, { key: element.key, onClick: (props.OnClick != null) ? (e) => {
289
- var _a, _b;
290
- return props.OnClick({
291
- colKey: element.props.Key,
292
- colField: (_a = element.props) === null || _a === void 0 ? void 0 : _a.Field,
293
- row: d,
294
- data: d[(_b = element.props) === null || _b === void 0 ? void 0 : _b.Field],
295
- index: i,
296
- }, e);
297
- } : undefined, dragStart: (props.DragStart != null) ? (e) => {
298
- var _a, _b;
299
- return props.DragStart({
300
- colKey: element.props.Key,
301
- colField: (_a = element.props) === null || _a === void 0 ? void 0 : _a.Field,
302
- row: d,
303
- data: d[(_b = element.props) === null || _b === void 0 ? void 0 : _b.Field],
304
- index: i,
305
- }, e);
306
- } : undefined, style: style }, ((_d = element.props) === null || _d === void 0 ? void 0 : _d.Content) != null
307
- ? element.props.Content({
308
- item: d,
309
- key: element.props.Key,
310
- field: (_e = element.props) === null || _e === void 0 ? void 0 : _e.Field,
311
- style: style,
312
- index: i,
313
- })
314
- : ((_f = element.props) === null || _f === void 0 ? void 0 : _f.Field) != null
315
- ? d[element.props.Field]
316
- : null));
317
- })));
318
- })));
319
- }
320
- function Header(props) {
321
- const headStyle = React.useMemo(() => (Object.assign(Object.assign({}, defaultHeadStyle), props.Style)), [props.Style]);
322
- // Consts for adjustable columns
323
- const [mouseDown, setMouseDown] = React.useState(0);
324
- const [currentKeys, setCurrentKeys] = React.useState(undefined);
325
- const [deltaW, setDeltaW] = React.useState(0);
326
- const [tentativeLimits, setTentativeLimits] = React.useState({ min: -Infinity, max: Infinity });
327
- const getLeftKey = React.useCallback((key, colWidthsRef) => {
328
- var _a;
329
- // Filtering down to shown adjustables only
330
- const keys = React.Children.map((_a = props.children) !== null && _a !== void 0 ? _a : [], (element) => {
331
- var _a;
332
- if (!React.isValidElement(element)) {
333
- return null;
334
- }
335
- const keyWidth = (_a = colWidthsRef.current.get(key)) === null || _a === void 0 ? void 0 : _a.width;
336
- if (keyWidth == null || keyWidth <= 0) {
337
- return null;
338
- }
339
- if (element.type === Column_1.AdjustableColumn) {
340
- return element.props.Key;
341
- }
342
- return null;
343
- }).filter((item) => item !== null);
344
- const index = keys.indexOf(key);
345
- if (index <= 0)
346
- return undefined;
347
- return keys[index - 1];
348
- }, [props.children]);
349
- const calculateDeltaLimits = React.useCallback((mapKeys, colWidthsRef) => {
350
- if (mapKeys === undefined)
351
- return ({ min: -Infinity, max: Infinity });
352
- const widthObjLeft = colWidthsRef.current.get(mapKeys[0]);
353
- const widthObjRight = colWidthsRef.current.get(mapKeys[1]);
354
- if (widthObjLeft == null || widthObjRight == null)
355
- return ({ min: -Infinity, max: Infinity });
356
- const limitByShrinkLeft = widthObjLeft.width - widthObjLeft.minWidth;
357
- const limitByGrowthLeft = widthObjLeft.maxWidth - widthObjLeft.width;
358
- const limitByShrinkRight = widthObjRight.width - widthObjRight.minWidth;
359
- const limitByGrowthRight = widthObjRight.maxWidth - widthObjRight.width;
360
- // Recall that a left movement is a negative deltaW
361
- const minDeltaW = -(limitByShrinkLeft < limitByGrowthRight ? limitByShrinkLeft : limitByGrowthRight);
362
- const maxDeltaW = limitByShrinkRight < limitByGrowthLeft ? limitByShrinkRight : limitByGrowthLeft;
363
- return ({ min: minDeltaW, max: maxDeltaW });
364
- }, []);
365
- const getDeltaSign = React.useCallback((index) => {
366
- // Recall that a left movement is a negative deltaW
367
- if (index === 0)
368
- return 1;
369
- else if (index === 1)
370
- return -1;
371
- else
372
- return 0;
373
- }, []);
374
- const finishAdjustment = React.useCallback((adjustment, adjustKeys, colWidthsRef) => {
375
- const deltaLimits = calculateDeltaLimits(adjustKeys, colWidthsRef);
376
- let delta;
377
- if (adjustment > deltaLimits.max)
378
- delta = deltaLimits.max;
379
- else if (adjustment < deltaLimits.min)
380
- delta = deltaLimits.min;
381
- else
382
- delta = adjustment;
383
- if (Math.abs(delta) > 5) {
384
- const leftWidthObj = colWidthsRef.current.get(adjustKeys[0]);
385
- const rightWidthObj = colWidthsRef.current.get(adjustKeys[1]);
386
- if (leftWidthObj == null || rightWidthObj == null) {
387
- console.error(`Unable to finalize adjustment on keys ${adjustKeys[0]}, ${adjustKeys[1]}`);
388
- }
389
- else {
390
- leftWidthObj.width += (getDeltaSign(0) * delta);
391
- rightWidthObj.width += (getDeltaSign(1) * delta);
392
- }
393
- }
394
- setMouseDown(0);
395
- setTentativeLimits({ min: -Infinity, max: Infinity });
396
- setCurrentKeys(undefined);
397
- setDeltaW(0);
398
- }, [calculateDeltaLimits, getDeltaSign]);
399
- const onMove = React.useCallback((e) => {
400
- if (currentKeys === undefined)
401
- return;
402
- const w = e.screenX - mouseDown;
403
- setDeltaW(w);
404
- }, [mouseDown, currentKeys]);
405
- return (React.createElement("thead", { className: props.Class, style: headStyle, onMouseMove: (e) => {
406
- onMove(e.nativeEvent);
407
- e.stopPropagation();
408
- }, onMouseUp: (e) => {
409
- e.stopPropagation();
410
- if (currentKeys == null)
411
- return;
412
- finishAdjustment(deltaW, currentKeys, props.ColWidths);
413
- props.TriggerRerender();
414
- }, onMouseLeave: (e) => {
415
- e.stopPropagation();
416
- if (currentKeys == null)
417
- return;
418
- finishAdjustment(deltaW, currentKeys, props.ColWidths);
419
- props.TriggerRerender();
420
- } },
421
- React.createElement("tr", { style: { width: '100%', display: 'table' } },
422
- React.Children.map(props.children, (element) => {
423
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
424
- if (!React.isValidElement(element))
425
- return null;
426
- if (!IsColumnProps(element.props))
427
- return null;
428
- const colWidth = props.ColWidths.current.get(element.props.Key);
429
- if (colWidth == null || colWidth.width === 0)
430
- return null;
431
- // Handling temporary width changes due to being in mid-adjustments
432
- let currentWidth = colWidth.width;
433
- const keyIndex = (_a = currentKeys === null || currentKeys === void 0 ? void 0 : currentKeys.indexOf(element.props.Key)) !== null && _a !== void 0 ? _a : -1;
434
- if (keyIndex > -1) {
435
- let delta;
436
- if (deltaW > tentativeLimits.max)
437
- delta = tentativeLimits.max;
438
- else if (deltaW < tentativeLimits.min)
439
- delta = tentativeLimits.min;
440
- else
441
- delta = deltaW;
442
- currentWidth += (getDeltaSign(keyIndex) * delta);
443
- }
444
- let cursor = undefined;
445
- if (((_c = (_b = element.props) === null || _b === void 0 ? void 0 : _b.HeaderStyle) === null || _c === void 0 ? void 0 : _c.cursor) != null)
446
- cursor = element.props.HeaderStyle.cursor;
447
- else if (((_e = (_d = element.props) === null || _d === void 0 ? void 0 : _d.AllowSort) !== null && _e !== void 0 ? _e : true))
448
- cursor = 'pointer';
449
- const style = Object.assign(Object.assign(Object.assign({}, defaultDataHeadStyle), (_f = element.props) === null || _f === void 0 ? void 0 : _f.HeaderStyle), { width: currentWidth, cursor: cursor });
450
- let startAdjustment;
451
- if (element.type === Column_1.AdjustableColumn)
452
- startAdjustment = (e) => {
453
- const leftKey = getLeftKey(element.props.Key, props.ColWidths);
454
- if (leftKey != null) {
455
- const newCurrentKeys = [leftKey, element.props.Key];
456
- setCurrentKeys(newCurrentKeys);
457
- setMouseDown(e.screenX);
458
- setTentativeLimits(calculateDeltaLimits(newCurrentKeys, props.ColWidths));
459
- setDeltaW(0);
460
- }
461
- };
462
- return (React.createElement(Column_1.ColumnHeaderWrapper, { onSort: (e) => {
463
- var _a;
464
- return props.OnSort({ colKey: element.props.Key, colField: (_a = element.props) === null || _a === void 0 ? void 0 : _a.Field, ascending: props.Ascending }, e);
465
- }, sorted: props.SortKey === element.props.Key && ((_h = (_g = element.props) === null || _g === void 0 ? void 0 : _g.AllowSort) !== null && _h !== void 0 ? _h : true), asc: props.Ascending, colKey: element.props.Key, key: element.props.Key, allowSort: (_j = element.props) === null || _j === void 0 ? void 0 : _j.AllowSort, startAdjustment: startAdjustment, style: style },
466
- ' ', (_k = element.props.children) !== null && _k !== void 0 ? _k : element.props.Key,
467
- ' '));
468
- }),
469
- React.createElement("th", { style: { width: 17, padding: 0, maxWidth: 17 } }, props.LastColumn))));
470
- }
@@ -1,148 +0,0 @@
1
- export interface ITable<T> {
2
- /**
3
- * List of T objects used to generate rows
4
- */
5
- Data: T[];
6
- /**
7
- * Callback when the user clicks on a data entry
8
- * @param data contains the data including the columnKey
9
- * @param event the onClick Event to allow propagation as needed
10
- * @returns
11
- */
12
- OnClick?: (data: {
13
- colKey?: string;
14
- colField?: keyof T;
15
- row: T;
16
- data: T[keyof T] | null;
17
- index: number;
18
- }, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
19
- /**
20
- * Key of the collumn to sort by
21
- */
22
- SortKey: string;
23
- /**
24
- * Boolen to indicate whether the sort is ascending or descending
25
- */
26
- Ascending: boolean;
27
- /**
28
- * Callback when the data should be sorted
29
- * @param data the information of the collumn including the Key of the collumn
30
- * @param event The onCLick event to allow Propagation as needed
31
- */
32
- OnSort(data: {
33
- colKey: string;
34
- colField?: keyof T;
35
- ascending: boolean;
36
- }, event: React.MouseEvent<HTMLElement, MouseEvent>): void;
37
- /**
38
- * Class of the table component
39
- */
40
- TableClass?: string;
41
- /**
42
- * style of the table component
43
- */
44
- TableStyle?: React.CSSProperties;
45
- /**
46
- * style of the thead component
47
- */
48
- TheadStyle?: React.CSSProperties;
49
- /**
50
- * Class of the thead component
51
- */
52
- TheadClass?: string;
53
- /**
54
- * style of the tbody component
55
- * Note: Display style overwritten to "block"
56
- */
57
- TbodyStyle?: React.CSSProperties;
58
- /**
59
- * Class of the tbody component
60
- */
61
- TbodyClass?: string;
62
- /**
63
- * style of the tfoot component
64
- */
65
- TfootStyle?: React.CSSProperties;
66
- /**
67
- * Class of the tfoot component
68
- */
69
- TfootClass?: string;
70
- /**
71
- * determines if a row should be styled as selected
72
- * @param data the item to be checked
73
- * @returns true if the row should be styled as selected
74
- */
75
- Selected?: (data: T, index: number) => boolean;
76
- /**
77
- *
78
- * @param data the information of the row including the item of the row
79
- * @param e the event triggering this
80
- * @returns
81
- */
82
- OnDragStart?: (data: {
83
- colKey?: string;
84
- colField?: keyof T;
85
- row: T;
86
- data: T[keyof T] | null;
87
- index: number;
88
- }, e: React.DragEvent<Element>) => void;
89
- /**
90
- * The default style for the tr element
91
- */
92
- RowStyle?: React.CSSProperties;
93
- /**
94
- * a Function that retrieves a unique key used for React key properties
95
- * @param data the item to be turned into a key
96
- * @returns a unique Key
97
- */
98
- KeySelector: (data: T, index?: number) => string | number;
99
- /**
100
- * Optional Element to display in the last row of the Table
101
- * use this for displaying warnings when the Table content gets cut off.
102
- * Data appears in the tfoot element
103
- */
104
- LastRow?: string | React.ReactNode;
105
- /**
106
- * Optional Element to display on upper Right corner
107
- */
108
- LastColumn?: string | React.ReactNode;
109
- /**
110
- * Optional Callback that gets called when there is not enough space to display columns
111
- * @param disabled takes in string of disabled keys
112
- */
113
- ReduceWidthCallback?: (disabled: string[]) => void;
114
- }
115
- export interface IColumn<T> {
116
- /**
117
- * a unique Key for this Collumn
118
- */
119
- Key: string;
120
- /**
121
- * Flag indicating whether sorting by this Collumn is allowed
122
- */
123
- AllowSort?: boolean;
124
- /**
125
- * Optional - the Field to be used
126
- */
127
- Field?: keyof T;
128
- /**
129
- * The Default style for the th element
130
- */
131
- HeaderStyle?: React.CSSProperties;
132
- /**
133
- * The Default style for the td element
134
- */
135
- RowStyle?: React.CSSProperties;
136
- /**
137
- * Determines the Content to be displayed
138
- * @param d the data to be turned into content
139
- * @returns the content displayed
140
- */
141
- Content?: (d: {
142
- item: T;
143
- key: string;
144
- field: keyof T | undefined;
145
- index: number;
146
- style?: React.CSSProperties;
147
- }) => React.ReactNode;
148
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
- // ******************************************************************************************************
3
- // Types.ts - Gbtc
4
- //
5
- // Copyright © 2021, Grid Protection Alliance. All Rights Reserved.
6
- //
7
- // Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
8
- // the NOTICE file distributed with this work for additional information regarding copyright ownership.
9
- // The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
10
- // file except in compliance with the License. You may obtain a copy of the License at:
11
- //
12
- // http://opensource.org/licenses/MIT
13
- //
14
- // Unless agreed to in writing, the subject software distributed under the License is distributed on an
15
- // "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
16
- // License for the specific language governing permissions and limitations.
17
- //
18
- // Code Modification History:
19
- // ----------------------------------------------------------------------------------------------------
20
- // 12/06/2024 - G. Santos
21
- // Migrated props to namespace.
22
- //
23
- // ******************************************************************************************************
24
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,37 +0,0 @@
1
- import * as React from 'react';
2
- export interface DynamicTableProps<T extends object> {
3
- /**
4
- * List of T objects used to generate rows
5
- */
6
- data: T[];
7
- onClick: (data: {
8
- colKey: string;
9
- colField?: keyof T;
10
- row: T;
11
- data: T[keyof T] | null;
12
- index: number;
13
- }, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
14
- /**
15
- * Key of the collumn to sort by
16
- */
17
- sortKey: string;
18
- /**
19
- * Boolen to indicate whether the sort is ascending or descending
20
- */
21
- ascending: boolean;
22
- onSort(data: {
23
- colKey: string;
24
- colField?: keyof T;
25
- ascending: boolean;
26
- }): void;
27
- tableClass?: string;
28
- tableStyle?: React.CSSProperties;
29
- theadStyle?: React.CSSProperties;
30
- theadClass?: string;
31
- tbodyStyle?: React.CSSProperties;
32
- tbodyClass?: string;
33
- selected?(data: T): boolean;
34
- rowStyle?: React.CSSProperties;
35
- keySelector?: (data: T) => string;
36
- }
37
- export declare function DynamicTable<T extends object>(props: DynamicTableProps<T>): JSX.Element | null;