@gpa-gemstone/react-table 1.2.23 → 1.2.25
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/lib/Table.d.ts +14 -0
- package/lib/Table.js +10 -7
- package/package.json +1 -1
package/lib/Table.d.ts
CHANGED
|
@@ -43,6 +43,13 @@ export interface TableProps<T> {
|
|
|
43
43
|
tbodyStyle?: React.CSSProperties;
|
|
44
44
|
tbodyClass?: string;
|
|
45
45
|
selected?(data: T): boolean;
|
|
46
|
+
onDragStart?: ((data: {
|
|
47
|
+
colKey: string;
|
|
48
|
+
colField?: keyof T;
|
|
49
|
+
row: T;
|
|
50
|
+
data: T[keyof T] | null;
|
|
51
|
+
index: number;
|
|
52
|
+
}, e: any) => void);
|
|
46
53
|
rowStyle?: React.CSSProperties;
|
|
47
54
|
keySelector?: (data: T) => string;
|
|
48
55
|
/**
|
|
@@ -65,6 +72,13 @@ interface IRowProps<T> {
|
|
|
65
72
|
data: T[keyof T] | null;
|
|
66
73
|
index: number;
|
|
67
74
|
}, e: React.MouseEvent<HTMLTableHeaderCellElement, MouseEvent>) => void;
|
|
75
|
+
DragStart?: ((data: {
|
|
76
|
+
colKey: string;
|
|
77
|
+
colField?: keyof T;
|
|
78
|
+
row: T;
|
|
79
|
+
data: T[keyof T] | null;
|
|
80
|
+
index: number;
|
|
81
|
+
}, e: any) => void);
|
|
68
82
|
Selected?: ((data: T) => boolean);
|
|
69
83
|
KeySelector?: (data: T) => string;
|
|
70
84
|
}
|
package/lib/Table.js
CHANGED
|
@@ -39,7 +39,7 @@ var React = require("react");
|
|
|
39
39
|
function Table(props) {
|
|
40
40
|
return (React.createElement("table", { className: props.tableClass !== undefined ? props.tableClass : '', style: props.tableStyle },
|
|
41
41
|
React.createElement(Header, { Class: props.theadClass, Style: props.theadStyle, Cols: props.cols, SortKey: props.sortKey, Ascending: props.ascending, Click: function (d, e) { return handleSort(d, e); } }),
|
|
42
|
-
React.createElement(Rows, { Data: props.data, Cols: props.cols, RowStyle: props.rowStyle, BodyStyle: props.tbodyStyle, BodyClass: props.tbodyClass, Click: function (data, e) { return (props.onClick === undefined ? null : props.onClick(data, e)); }, Selected: props.selected, KeySelector: props.keySelector }),
|
|
42
|
+
React.createElement(Rows, { DragStart: props.onDragStart, Data: props.data, Cols: props.cols, RowStyle: props.rowStyle, BodyStyle: props.tbodyStyle, BodyClass: props.tbodyClass, Click: function (data, e) { return (props.onClick === undefined ? null : props.onClick(data, e)); }, Selected: props.selected, KeySelector: props.keySelector }),
|
|
43
43
|
props.lastRow !== undefined ? React.createElement("tr", { style: (props.rowStyle !== undefined) ? __assign({}, props.rowStyle) : {}, key: -1 }, props.lastRow) : null));
|
|
44
44
|
function handleSort(data, event) {
|
|
45
45
|
if (data.colKey !== null)
|
|
@@ -52,7 +52,7 @@ function Rows(props) {
|
|
|
52
52
|
return null;
|
|
53
53
|
var rows = props.Data.map(function (item, rowIndex) {
|
|
54
54
|
var cells = props.Cols.map(function (colData) {
|
|
55
|
-
return React.createElement(Cell, { key: colData.key, Style: colData.rowStyle, DataKey: colData.key, DataField: colData.field, Object: item, RowIndex: rowIndex, Content: colData.content, Click: function (data, e) { return props.Click(data, e); } });
|
|
55
|
+
return React.createElement(Cell, { key: colData.key, Style: colData.rowStyle, DataKey: colData.key, DataField: colData.field, Object: item, RowIndex: rowIndex, Content: colData.content, Click: function (data, e) { return props.Click(data, e); }, DragStart: props.DragStart });
|
|
56
56
|
});
|
|
57
57
|
var style = (props.RowStyle !== undefined) ? __assign({}, props.RowStyle) : {};
|
|
58
58
|
if (style.cursor === undefined)
|
|
@@ -71,9 +71,12 @@ function Rows(props) {
|
|
|
71
71
|
exports.Rows = Rows;
|
|
72
72
|
function Cell(props) {
|
|
73
73
|
var css = (props.Style !== undefined) ? __assign({}, props.Style) : {};
|
|
74
|
+
if (props.DragStart !== undefined)
|
|
75
|
+
css.cursor = "grab";
|
|
74
76
|
var getFieldValue = function () { return props.DataField !== undefined ? props.Object[props.DataField] : null; };
|
|
75
77
|
var getFieldContent = function () { return props.Content !== undefined ? props.Content(props.Object, props.DataKey, props.DataField, css, props.RowIndex) : getFieldValue(); };
|
|
76
|
-
return (React.createElement("td", { style: css, onClick: function (e) { return props.Click({ colKey: props.DataKey, colField: props.DataField, row: props.Object, data: getFieldValue(), index: props.RowIndex }, e); }
|
|
78
|
+
return (React.createElement("td", { style: css, onClick: function (e) { return props.Click({ colKey: props.DataKey, colField: props.DataField, row: props.Object, data: getFieldValue(), index: props.RowIndex }, e); }, draggable: props.DragStart !== undefined, onDragStart: function (e) { if (props.DragStart !== undefined)
|
|
79
|
+
props.DragStart({ colKey: props.DataKey, colField: props.DataField, row: props.Object, data: getFieldValue(), index: props.RowIndex }, e); } }, getFieldContent()));
|
|
77
80
|
}
|
|
78
81
|
function Header(props) {
|
|
79
82
|
return (React.createElement("thead", { className: props.Class, style: props.Style },
|
|
@@ -89,9 +92,8 @@ function HeaderCell(props) {
|
|
|
89
92
|
style.position = 'relative';
|
|
90
93
|
}
|
|
91
94
|
return (React.createElement("th", { style: style, onClick: function (e) { return props.Click(e); } },
|
|
92
|
-
React.createElement(
|
|
93
|
-
|
|
94
|
-
React.createElement("div", { style: { marginLeft: 25 } }, props.Label)));
|
|
95
|
+
React.createElement(RenderAngleIcon, { SortKey: props.SortKey, Key: props.DataKey, Ascending: props.Ascending }),
|
|
96
|
+
React.createElement("div", { style: { marginLeft: (props.SortKey === props.DataKey ? 25 : 0) } }, props.Label)));
|
|
95
97
|
}
|
|
96
98
|
function RenderAngleIcon(props) {
|
|
97
99
|
var AngleIcon = function (a) { return a.ascending ? gpa_symbols_1.SVGIcons.ArrowDropUp : gpa_symbols_1.SVGIcons.ArrowDropDown; };
|
|
@@ -99,6 +101,7 @@ function RenderAngleIcon(props) {
|
|
|
99
101
|
return null;
|
|
100
102
|
if (props.SortKey !== props.Key)
|
|
101
103
|
return null;
|
|
102
|
-
return React.createElement(
|
|
104
|
+
return React.createElement("div", { style: { position: 'absolute', width: 25 } },
|
|
105
|
+
React.createElement(AngleIcon, { ascending: props.Ascending }));
|
|
103
106
|
}
|
|
104
107
|
;
|