@gpa-gemstone/react-table 1.2.50 → 1.2.52

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,20 +1,18 @@
1
1
  import * as React from 'react';
2
- import { IColumnProps } from './Column';
3
- interface IAdjustableColProps<T> extends IColumnProps<T> {
4
- /**
5
- * The minimum Width used for this Collumn - default is 100px
6
- */
7
- MinWidth?: number;
2
+ import { IColumnProps, IDataWrapperProps, IHeaderWrapperProps } from './Column';
3
+ export default function AdjustableColumn<T>(props: React.PropsWithChildren<IColumnProps<T>>): JSX.Element;
4
+ interface IAdjustableHeaderWrapperProps extends IHeaderWrapperProps {
5
+ adjustment: number;
6
+ startAdjustment: React.MouseEventHandler<HTMLDivElement>;
7
+ setMinWidth: (w: number) => void;
8
+ minWidth?: number;
9
+ setMaxWidth: (w: number) => void;
10
+ maxWidth?: number;
11
+ extraWidth: number;
8
12
  }
9
- export default function AdjustableCol<T>(props: React.PropsWithChildren<IAdjustableColProps<T>>): JSX.Element;
10
- interface IHeaderWrapperProps<T> extends IAdjustableColProps<T> {
11
- setWidth: (w: number, m: number) => void;
12
- width?: number;
13
- onSort: (key: string, event: any, field?: keyof T) => void;
14
- sorted: boolean;
15
- asc: boolean;
16
- startAdjustment: (e: any) => void;
17
- fixedLayout: boolean;
13
+ export declare function AdjustableColumnHeaderWrapper(props: React.PropsWithChildren<IAdjustableHeaderWrapperProps>): JSX.Element | null;
14
+ interface IAdjustableDataWrapperProps extends IDataWrapperProps {
15
+ adjustment?: number;
18
16
  }
19
- export declare function AdjColumnHeaderWrapper<T>(props: React.PropsWithChildren<IHeaderWrapperProps<T>>): JSX.Element;
17
+ export declare function AdjustableColumnDataWrapper(props: React.PropsWithChildren<IAdjustableDataWrapperProps>): JSX.Element | null;
20
18
  export {};
@@ -1,4 +1,8 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = AdjustableColumn;
4
+ exports.AdjustableColumnHeaderWrapper = AdjustableColumnHeaderWrapper;
5
+ exports.AdjustableColumnDataWrapper = AdjustableColumnDataWrapper;
2
6
  // ******************************************************************************************************
3
7
  // AdjustableColumn.tsx - Gbtc
4
8
  //
@@ -19,68 +23,115 @@
19
23
  // ----------------------------------------------------------------------------------------------------
20
24
  // 11/19/2023 - C. Lackner
21
25
  // Generated original version of source code.
26
+ // 05/31/2024 - C. Lackner
27
+ // Refactored to fix sizing issues.
22
28
  //
23
29
  // ******************************************************************************************************
24
- var __assign = (this && this.__assign) || function () {
25
- __assign = Object.assign || function(t) {
26
- for (var s, i = 1, n = arguments.length; i < n; i++) {
27
- s = arguments[i];
28
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29
- t[p] = s[p];
30
- }
31
- return t;
32
- };
33
- return __assign.apply(this, arguments);
34
- };
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.default = AdjustableCol;
37
- exports.AdjColumnHeaderWrapper = AdjColumnHeaderWrapper;
38
- var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
39
- var helper_functions_1 = require("@gpa-gemstone/helper-functions");
40
- var React = require("react");
41
- function AdjustableCol(props) {
30
+ const gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
31
+ const helper_functions_1 = require("@gpa-gemstone/helper-functions");
32
+ const React = require("react");
33
+ function AdjustableColumn(props) {
42
34
  return React.createElement(React.Fragment, null, props.children);
43
35
  }
44
- function AdjColumnHeaderWrapper(props) {
45
- var _a, _b;
46
- var thref = React.useRef(null);
47
- var _c = React.useState(false), showBorder = _c[0], setShowBorder = _c[1];
48
- var onHover = React.useCallback(function () { setShowBorder(true); }, []);
49
- var onLeave = React.useCallback(function () { setShowBorder(false); }, []);
50
- var style = (props.RowStyle !== undefined) ? __assign({}, props.HeaderStyle) : {};
51
- if (props.width !== undefined && props.fixedLayout) {
52
- style.width = props.width;
53
- style.minWidth = props.width;
54
- style.maxWidth = props.width;
36
+ function AdjustableColumnHeaderWrapper(props) {
37
+ var _a, _b, _c, _d, _e, _f, _g;
38
+ const thref = React.useRef(null);
39
+ const [mode, setMode] = React.useState('minWidth');
40
+ //const [width, setWidth] = React.useState<number>();
41
+ const [minWidth, setMinWidth] = React.useState();
42
+ const [maxWidth, setMaxWidth] = React.useState();
43
+ const [showBorder, setShowBorder] = React.useState(false);
44
+ const onHover = React.useCallback(() => { setShowBorder(true); }, []);
45
+ const onLeave = React.useCallback(() => { setShowBorder(false); }, []);
46
+ const style = (props.style !== undefined) ? Object.assign({}, props.style) : {};
47
+ style.overflowX = (_a = style.overflowX) !== null && _a !== void 0 ? _a : 'hidden';
48
+ style.display = (_b = style.display) !== null && _b !== void 0 ? _b : 'inline-block';
49
+ style.position = (_c = style.position) !== null && _c !== void 0 ? _c : 'relative';
50
+ style.borderTop = (_d = style.borderTop) !== null && _d !== void 0 ? _d : 'none';
51
+ style.minWidth = (_e = style.minWidth) !== null && _e !== void 0 ? _e : 100;
52
+ const isAuto = style.width == 'auto';
53
+ const isUndefined = style.width === undefined;
54
+ if ((style.width == undefined || style.width == 'auto') && props.width !== undefined && mode === 'width') {
55
+ style.width = (props.width) + props.extraWidth;
55
56
  }
56
- if (style.cursor === undefined && ((_a = props.AllowSort) !== null && _a !== void 0 ? _a : true)) {
57
- style.cursor = 'pointer';
57
+ if (mode === 'minWidth') {
58
+ style.width = style.minWidth;
58
59
  }
59
- if (style.position === undefined) {
60
- style.position = 'relative';
60
+ if (mode === 'maxWidth') {
61
+ style.width = style.maxWidth;
61
62
  }
62
- if (style.borderTop === undefined) {
63
- style.borderTop = 'none';
63
+ if (mode === 'width' && props.adjustment !== undefined && props.adjustment !== 0 && style.width !== undefined) {
64
+ style.width = `calc(${formatwidth(style.width).toString()} ${props.adjustment < 0 ? '-' : '+'} ${Math.abs(props.adjustment).toString()}px)`;
64
65
  }
65
- React.useLayoutEffect(function () {
66
- var _a, _b;
67
- if (thref.current == null || props.width !== undefined)
68
- return;
69
- var w = (_a = (0, helper_functions_1.GetNodeSize)(thref.current)) === null || _a === void 0 ? void 0 : _a.width;
70
- if (w === undefined)
66
+ if (style.cursor === undefined && ((_f = props.allowSort) !== null && _f !== void 0 ? _f : true)) {
67
+ style.cursor = 'pointer';
68
+ }
69
+ React.useLayoutEffect(() => {
70
+ var _a, _b, _c;
71
+ if (thref.current == null)
71
72
  return;
72
- props.setWidth(w, (_b = props.MinWidth) !== null && _b !== void 0 ? _b : 100);
73
+ if (mode == 'minWidth') {
74
+ const w = (_a = (0, helper_functions_1.GetNodeSize)(thref.current)) === null || _a === void 0 ? void 0 : _a.width;
75
+ if (w === undefined)
76
+ return;
77
+ if (w !== minWidth) {
78
+ setMinWidth(w);
79
+ }
80
+ if (maxWidth === undefined && style.maxWidth !== undefined) {
81
+ setMode('maxWidth');
82
+ }
83
+ else if (props.width === undefined) {
84
+ setMode('width');
85
+ }
86
+ }
87
+ if (mode == 'maxWidth') {
88
+ const w = (_b = (0, helper_functions_1.GetNodeSize)(thref.current)) === null || _b === void 0 ? void 0 : _b.width;
89
+ if (w === undefined)
90
+ return;
91
+ if (w !== maxWidth) {
92
+ setMaxWidth(w);
93
+ }
94
+ if (props.width === undefined) {
95
+ setMode('width');
96
+ }
97
+ else if (props.minWidth === undefined && style.minWidth !== undefined) {
98
+ setMode('minWidth');
99
+ }
100
+ }
101
+ if (mode == 'width') {
102
+ const w = (_c = (0, helper_functions_1.GetNodeSize)(thref.current)) === null || _c === void 0 ? void 0 : _c.width;
103
+ if (w === undefined)
104
+ return;
105
+ if (props.width === undefined || (w !== (props.width + props.extraWidth))) {
106
+ props.setWidth(w, isAuto, isUndefined);
107
+ }
108
+ if (maxWidth === undefined && style.maxWidth !== undefined) {
109
+ setMode('maxWidth');
110
+ }
111
+ else if (minWidth === undefined && style.minWidth !== undefined) {
112
+ setMode('minWidth');
113
+ }
114
+ }
73
115
  });
74
- var onClick = React.useCallback(function (e) {
116
+ React.useEffect(() => {
117
+ if (minWidth !== props.minWidth)
118
+ props.setMinWidth(minWidth);
119
+ }, [minWidth]);
120
+ React.useEffect(() => {
121
+ if (maxWidth !== props.maxWidth)
122
+ props.setMaxWidth(maxWidth);
123
+ }, [maxWidth]);
124
+ const onClick = React.useCallback((e) => {
75
125
  var _a;
76
- if ((_a = props.AllowSort) !== null && _a !== void 0 ? _a : true)
77
- props.onSort(props.Key, e, props.Field);
78
- e.stopPropagation();
79
- }, [props.onSort]);
80
- var onClickBorder = React.useCallback(function (e) {
126
+ if ((_a = props.allowSort) !== null && _a !== void 0 ? _a : true)
127
+ props.onSort(e);
128
+ }, [props.onSort, props.allowSort]);
129
+ const onClickBorder = React.useCallback((e) => {
81
130
  props.startAdjustment(e);
82
131
  }, [props.startAdjustment]);
83
- return React.createElement("th", { ref: thref, style: style, onClick: onClick, onDrag: function (e) { e.stopPropagation(); } },
132
+ if (props.width != undefined && !props.enabled)
133
+ return null;
134
+ return React.createElement("th", { ref: thref, style: style, onClick: onClick, onDrag: (e) => { e.stopPropagation(); } },
84
135
  React.createElement("div", { style: {
85
136
  width: 5,
86
137
  height: '100%',
@@ -91,9 +142,47 @@ function AdjColumnHeaderWrapper(props) {
91
142
  background: '#e9ecef',
92
143
  cursor: 'col-resize'
93
144
  }, onMouseEnter: onHover, onMouseLeave: onLeave, onMouseDown: onClickBorder }),
94
- props.sorted && props.asc ? React.createElement("div", { style: { position: 'absolute', width: 25 } }, gpa_symbols_1.SVGIcons.ArrowDropDown) : null,
95
- props.sorted && !props.asc ? React.createElement("div", { style: { position: 'absolute', width: 25 } }, gpa_symbols_1.SVGIcons.ArrowDropUp) : null,
145
+ props.sorted ? React.createElement("div", { style: { position: 'absolute', width: 25 } }, props.asc ? React.createElement(gpa_symbols_1.ReactIcons.ArrowDropUp, null) : React.createElement(gpa_symbols_1.ReactIcons.ArrowDropDown, null)) : null,
96
146
  React.createElement("div", { style: {
97
147
  marginLeft: (props.sorted ? 25 : 0),
98
- } }, (_b = props.children) !== null && _b !== void 0 ? _b : props.Key));
148
+ } }, (_g = props.children) !== null && _g !== void 0 ? _g : props.colKey));
149
+ }
150
+ function AdjustableColumnDataWrapper(props) {
151
+ var _a, _b;
152
+ const tdref = React.useRef(null);
153
+ const style = (props.style !== undefined) ? Object.assign({}, props.style) : {};
154
+ style.overflowX = (_a = style.overflowX) !== null && _a !== void 0 ? _a : 'hidden';
155
+ style.display = (_b = style.display) !== null && _b !== void 0 ? _b : 'inline-block';
156
+ const isAuto = style.width == 'auto';
157
+ const isUndefined = style.width === undefined;
158
+ if ((style.width == undefined || style.width == 'auto') && props.width !== undefined) {
159
+ style.width = (props.width) + props.extraWidth;
160
+ }
161
+ if (props.dragStart !== undefined)
162
+ style.cursor = "grab";
163
+ React.useLayoutEffect(() => {
164
+ var _a;
165
+ if (tdref.current == null)
166
+ return;
167
+ const w = (_a = (0, helper_functions_1.GetNodeSize)(tdref.current)) === null || _a === void 0 ? void 0 : _a.width;
168
+ if (style.width === undefined && props.width === undefined) {
169
+ props.setWidth(w, isAuto, isUndefined);
170
+ return;
171
+ }
172
+ if (props.adjustment !== undefined && props.adjustment !== 0)
173
+ return;
174
+ if (w === undefined || (props.width !== undefined && w == (props.width + props.extraWidth)))
175
+ return;
176
+ props.setWidth(w, isAuto, isUndefined);
177
+ });
178
+ if (props.adjustment !== undefined && props.adjustment !== 0 && style.width !== undefined)
179
+ style.width = `calc(${formatwidth(style.width)} ${props.adjustment < 0 ? '-' : '+'} ${Math.abs(props.adjustment).toString()}px)`;
180
+ if (props.width != undefined && !props.enabled)
181
+ return null;
182
+ return (React.createElement("td", { ref: tdref, style: style, onClick: props.onClick, draggable: props.dragStart !== undefined, onDragStart: props.dragStart }, props.children));
183
+ }
184
+ function formatwidth(style) {
185
+ if (style.toString().endsWith('%') || style.toString().endsWith('px'))
186
+ return style;
187
+ return style.toString() + "px";
99
188
  }
@@ -12,16 +12,16 @@ export interface IColumnProps<T> {
12
12
  * Optional - the Field to be used
13
13
  */
14
14
  Field?: keyof T;
15
- /**
16
- * The Default style for the td element
17
- */
18
- RowStyle?: React.CSSProperties;
19
15
  /**
20
16
  * The Default style for the th element
21
17
  */
22
18
  HeaderStyle?: React.CSSProperties;
23
19
  /**
24
- * Determines the Content to be displaye
20
+ * The Default style for the td element
21
+ */
22
+ RowStyle?: React.CSSProperties;
23
+ /**
24
+ * Determines the Content to be displayed
25
25
  * @param d the data to be turned into content
26
26
  * @returns the content displayed
27
27
  */
@@ -34,34 +34,26 @@ export interface IColumnProps<T> {
34
34
  }) => React.ReactNode;
35
35
  }
36
36
  export default function Column<T>(props: React.PropsWithChildren<IColumnProps<T>>): JSX.Element;
37
- interface IHeaderWrapperProps<T> extends IColumnProps<T> {
38
- setWidth: (w: number) => void;
39
- width?: number;
40
- onSort: (key: string, event: any, field?: keyof T) => void;
37
+ export interface IHeaderWrapperProps {
38
+ setWidth: (w: number, a: boolean, u: boolean) => void;
39
+ onSort: React.MouseEventHandler<HTMLTableCellElement>;
41
40
  sorted: boolean;
42
41
  asc: boolean;
43
- fixedLayout: boolean;
42
+ style: React.CSSProperties;
43
+ allowSort?: boolean;
44
+ colKey: string;
45
+ width?: number;
46
+ enabled: boolean;
47
+ extraWidth: number;
44
48
  }
45
- export declare function ColumnHeaderWrapper<T>(props: React.PropsWithChildren<IHeaderWrapperProps<T>>): JSX.Element;
46
- interface IDataWrapperProps<T> extends IColumnProps<T> {
49
+ export declare function ColumnHeaderWrapper(props: React.PropsWithChildren<IHeaderWrapperProps>): JSX.Element | null;
50
+ export interface IDataWrapperProps {
51
+ setWidth: (w: number, a: boolean, u: boolean) => void;
47
52
  width?: number;
48
- item: T;
49
- index: number;
50
- dragStart: (data: {
51
- colKey: string;
52
- colField?: keyof T;
53
- row: T;
54
- data: T[keyof T] | null;
55
- index: number;
56
- }, e: any) => void;
57
- onClick?: (data: {
58
- colKey: string;
59
- colField?: keyof T;
60
- row: T;
61
- data: T[keyof T] | null;
62
- index: number;
63
- }, e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
64
- fixedLayout: boolean;
53
+ enabled: boolean;
54
+ dragStart?: (e: React.DragEvent) => void;
55
+ onClick?: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
56
+ style: React.CSSProperties;
57
+ extraWidth: number;
65
58
  }
66
- export declare function ColumnDataWrapper<T>(props: IDataWrapperProps<T>): JSX.Element;
67
- export {};
59
+ export declare function ColumnDataWrapper(props: React.PropsWithChildren<IDataWrapperProps>): JSX.Element | null;
@@ -19,106 +19,81 @@
19
19
  // ----------------------------------------------------------------------------------------------------
20
20
  // 08/02/2018 - Billy Ernest
21
21
  // Generated original version of source code.
22
+ // 05/31/2024 - C. Lackner
23
+ // Refactored to fix sizing issues.
22
24
  //
23
25
  // ******************************************************************************************************
24
- var __assign = (this && this.__assign) || function () {
25
- __assign = Object.assign || function(t) {
26
- for (var s, i = 1, n = arguments.length; i < n; i++) {
27
- s = arguments[i];
28
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
29
- t[p] = s[p];
30
- }
31
- return t;
32
- };
33
- return __assign.apply(this, arguments);
34
- };
35
26
  Object.defineProperty(exports, "__esModule", { value: true });
36
27
  exports.default = Column;
37
28
  exports.ColumnHeaderWrapper = ColumnHeaderWrapper;
38
29
  exports.ColumnDataWrapper = ColumnDataWrapper;
39
- var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
40
- var helper_functions_1 = require("@gpa-gemstone/helper-functions");
41
- var React = require("react");
30
+ const gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
31
+ const helper_functions_1 = require("@gpa-gemstone/helper-functions");
32
+ const React = require("react");
42
33
  function Column(props) {
43
34
  return React.createElement(React.Fragment, null, props.children);
44
35
  }
45
36
  function ColumnHeaderWrapper(props) {
46
- var _a, _b;
47
- var thref = React.useRef(null);
48
- var style = (props.RowStyle !== undefined) ? __assign({}, props.HeaderStyle) : {};
49
- if (props.width !== undefined && props.fixedLayout) {
50
- style.width = props.width;
51
- style.minWidth = props.width;
52
- style.maxWidth = props.width;
53
- style.overflowX = 'hidden';
54
- style.display = 'inline-block';
37
+ var _a, _b, _c, _d, _e, _f;
38
+ const thref = React.useRef(null);
39
+ const style = (props.style !== undefined) ? Object.assign({}, props.style) : {};
40
+ style.overflowX = (_a = style.overflowX) !== null && _a !== void 0 ? _a : 'hidden';
41
+ style.display = (_b = style.display) !== null && _b !== void 0 ? _b : 'inline-block';
42
+ style.position = (_c = style.position) !== null && _c !== void 0 ? _c : 'relative';
43
+ style.borderTop = (_d = style.borderTop) !== null && _d !== void 0 ? _d : 'none';
44
+ const isAuto = style.width == 'auto';
45
+ const isUndefined = style.width === undefined;
46
+ if ((style.width == undefined || style.width == 'auto') && props.width !== undefined) {
47
+ style.width = (props.width) + props.extraWidth;
55
48
  }
56
- if (style.cursor === undefined && ((_a = props.AllowSort) !== null && _a !== void 0 ? _a : true)) {
49
+ if (style.cursor === undefined && ((_e = props.allowSort) !== null && _e !== void 0 ? _e : true)) {
57
50
  style.cursor = 'pointer';
58
51
  }
59
- if (style.position === undefined) {
60
- style.position = 'relative';
61
- }
62
- if (style.borderTop === undefined) {
63
- style.borderTop = 'none';
64
- }
65
- React.useLayoutEffect(function () {
52
+ React.useLayoutEffect(() => {
66
53
  var _a;
67
- if (thref.current == null || props.width !== undefined)
54
+ if (thref.current == null)
68
55
  return;
69
- var w = (_a = (0, helper_functions_1.GetNodeSize)(thref.current)) === null || _a === void 0 ? void 0 : _a.width;
70
- if (w === undefined)
56
+ const w = (_a = (0, helper_functions_1.GetNodeSize)(thref.current)) === null || _a === void 0 ? void 0 : _a.width;
57
+ if (props.width !== undefined && (w === undefined || w == (props.width + props.extraWidth)))
71
58
  return;
72
- props.setWidth(w);
59
+ props.setWidth(w, isAuto, isUndefined);
73
60
  });
74
- var onClick = React.useCallback(function (e) {
61
+ const onClick = React.useCallback((e) => {
75
62
  var _a;
76
- if ((_a = props.AllowSort) !== null && _a !== void 0 ? _a : true)
77
- props.onSort(props.Key, e, props.Field);
78
- }, [props.onSort, props.AllowSort]);
79
- return React.createElement("th", { ref: thref, style: style, onClick: onClick, onDrag: function (e) { e.stopPropagation(); } },
80
- props.sorted && !props.asc ? React.createElement("div", { style: { position: 'absolute', width: 25 } }, gpa_symbols_1.SVGIcons.ArrowDropDown) : null,
81
- props.sorted && props.asc ? React.createElement("div", { style: { position: 'absolute', width: 25 } }, gpa_symbols_1.SVGIcons.ArrowDropUp) : null,
63
+ if ((_a = props.allowSort) !== null && _a !== void 0 ? _a : true)
64
+ props.onSort(e);
65
+ }, [props.onSort, props.allowSort]);
66
+ if (props.width != undefined && !props.enabled)
67
+ return null;
68
+ return React.createElement("th", { ref: thref, style: style, onClick: onClick, onDrag: (e) => { e.stopPropagation(); } },
69
+ props.sorted ? React.createElement("div", { style: { position: 'absolute', width: 25 } }, props.asc ? React.createElement(gpa_symbols_1.ReactIcons.ArrowDropUp, null) : React.createElement(gpa_symbols_1.ReactIcons.ArrowDropDown, null)) : null,
82
70
  React.createElement("div", { style: {
83
71
  marginLeft: (props.sorted ? 25 : 0),
84
- } }, (_b = props.children) !== null && _b !== void 0 ? _b : props.Key));
72
+ } }, (_f = props.children) !== null && _f !== void 0 ? _f : props.colKey));
85
73
  }
86
74
  function ColumnDataWrapper(props) {
87
- var css = (props.RowStyle !== undefined) ? __assign({}, props.RowStyle) : {};
88
- if (props.width !== undefined && props.fixedLayout) {
89
- css.width = props.width;
90
- css.minWidth = props.width;
91
- css.maxWidth = props.width;
92
- css.overflowX = 'hidden';
93
- css.display = 'inline-block';
75
+ var _a, _b;
76
+ const tdref = React.useRef(null);
77
+ const style = (props.style !== undefined) ? Object.assign({}, props.style) : {};
78
+ style.overflowX = (_a = style.overflowX) !== null && _a !== void 0 ? _a : 'hidden';
79
+ style.display = (_b = style.display) !== null && _b !== void 0 ? _b : 'inline-block';
80
+ const isAuto = style.width == 'auto';
81
+ const isUndefined = style.width === undefined;
82
+ if ((style.width == undefined || style.width == 'auto') && props.width !== undefined) {
83
+ style.width = (props.width) + props.extraWidth;
94
84
  }
95
85
  if (props.dragStart !== undefined)
96
- css.cursor = "grab";
97
- var getFieldValue = function () { return props.Field !== undefined ? props.item[props.Field] : null; };
98
- var getFieldContent = function () { return props.Content !== undefined ? props.Content({
99
- item: props.item,
100
- key: props.Key,
101
- field: props.Field,
102
- style: css,
103
- index: props.index
104
- }) : getFieldValue(); };
105
- var onClick = React.useCallback(function (e) {
106
- if (props.onClick !== undefined)
107
- props.onClick({
108
- colKey: props.Key,
109
- colField: props.Field,
110
- row: props.item,
111
- data: getFieldValue(),
112
- index: props.index
113
- }, e);
114
- }, [props.Key, props.Field, props.item, props.index, props.onClick]);
115
- return (React.createElement("td", { style: css, onClick: onClick, draggable: props.dragStart !== undefined, onDragStart: function (e) {
116
- props.dragStart({
117
- colKey: props.Key,
118
- colField: props.Field,
119
- row: props.item,
120
- data: getFieldValue(),
121
- index: props.index
122
- }, e);
123
- } }, getFieldContent()));
86
+ style.cursor = "grab";
87
+ React.useLayoutEffect(() => {
88
+ var _a;
89
+ if (tdref.current == null)
90
+ return;
91
+ const w = (_a = (0, helper_functions_1.GetNodeSize)(tdref.current)) === null || _a === void 0 ? void 0 : _a.width;
92
+ if (props.width !== undefined && (w === undefined || w == (props.width + props.extraWidth)))
93
+ return;
94
+ props.setWidth(w, isAuto, isUndefined);
95
+ });
96
+ if (props.width != undefined && !props.enabled)
97
+ return null;
98
+ return (React.createElement("td", { ref: tdref, style: style, onClick: props.onClick, draggable: props.dragStart !== undefined, onDragStart: props.dragStart }, props.children));
124
99
  }
@@ -0,0 +1,107 @@
1
+ import * as React from 'react';
2
+ interface TableProps<T> {
3
+ /**
4
+ * List of T objects used to generate rows
5
+ */
6
+ Data: T[];
7
+ /**
8
+ * Callback when the user clicks on a data entry
9
+ * @param data contains the data including the columnKey
10
+ * @param event the onClick Event to allow propagation as needed
11
+ * @returns
12
+ */
13
+ OnClick?: (data: {
14
+ colKey?: string;
15
+ colField?: keyof T;
16
+ row: T;
17
+ data: T[keyof T] | null;
18
+ index: number;
19
+ }, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
20
+ /**
21
+ * Key of the collumn to sort by
22
+ */
23
+ SortKey: string;
24
+ /**
25
+ * Boolen to indicate whether the sort is ascending or descending
26
+ */
27
+ Ascending: boolean;
28
+ /**
29
+ * Callback when the data should be sorted
30
+ * @param data the information of the collumn including the Key of the collumn
31
+ * @param event The onCLick event to allow Propagation as needed
32
+ */
33
+ OnSort(data: {
34
+ colKey: string;
35
+ colField?: keyof T;
36
+ ascending: boolean;
37
+ }, event: React.MouseEvent<HTMLElement, MouseEvent>): void;
38
+ /**
39
+ * Class of the table component
40
+ */
41
+ TableClass?: string;
42
+ /**
43
+ * style of the table component
44
+ */
45
+ TableStyle?: React.CSSProperties;
46
+ /**
47
+ * style of the thead component
48
+ */
49
+ TheadStyle?: React.CSSProperties;
50
+ /**
51
+ * Class of the thead component
52
+ */
53
+ TheadClass?: string;
54
+ /**
55
+ * style of the tbody component
56
+ */
57
+ TbodyStyle?: React.CSSProperties;
58
+ /**
59
+ * Class of the tbody component
60
+ */
61
+ TbodyClass?: string;
62
+ /**
63
+ * determines if a row should be styled as selected
64
+ * @param data the item to be checked
65
+ * @returns true if the row should be styled as selected
66
+ */
67
+ Selected?: (data: T, index: number) => boolean;
68
+ /**
69
+ *
70
+ * @param data the information of the row including the item of the row
71
+ * @param e the event triggering this
72
+ * @returns
73
+ */
74
+ OnDragStart?: (data: {
75
+ colKey?: string;
76
+ colField?: keyof T;
77
+ row: T;
78
+ data: T[keyof T] | null;
79
+ index: number;
80
+ }, e: React.DragEvent<Element>) => void;
81
+ /**
82
+ * The default style for the tr element
83
+ */
84
+ RowStyle?: React.CSSProperties;
85
+ /**
86
+ * a Function that retrieves a unique key used for React key properties
87
+ * @param data the item to be turned into a key
88
+ * @returns a unique Key
89
+ */
90
+ KeySelector: (data: T, index?: number) => string | number;
91
+ /**
92
+ * Optional Element to display in the last row of the Table
93
+ * use this for displaying warnings when the Table content gets cut off
94
+ */
95
+ LastRow?: string | React.ReactNode;
96
+ /**
97
+ * Optional Element to display on upper Right corner
98
+ */
99
+ LastColumn?: string | React.ReactNode;
100
+ /**
101
+ * Optional Callback that gets called when there is not enough space to display columns
102
+ * @param disabled takes in string of disabled keys
103
+ */
104
+ ReduceWidthCallback?: (disabled: string[]) => void;
105
+ }
106
+ export default function AdjustableTable<T>(props: React.PropsWithChildren<TableProps<T>>): JSX.Element;
107
+ export {};