@addev-be/ui 0.2.6 → 0.2.7
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/assets/icons/arrow-down-1-9.svg +1 -0
- package/assets/icons/arrow-down-big-small.svg +1 -0
- package/assets/icons/arrow-up-9-1.svg +1 -0
- package/assets/icons/arrow-up-big-small.svg +1 -0
- package/assets/icons/chevron-down.svg +1 -0
- package/assets/icons/ellipsis.svg +1 -0
- package/assets/icons/sigma.svg +1 -0
- package/assets/icons/table-footer-slash.svg +5 -0
- package/assets/icons/table-footer.svg +4 -0
- package/assets/icons/table.svg +1 -0
- package/assets/icons/tally.svg +1 -0
- package/assets/icons/x-bar.svg +4 -0
- package/dist/Icons.d.ts +13 -1
- package/dist/Icons.js +25 -1
- package/dist/components/data/AdvancedRequestDataGrid/index.js +3 -3
- package/dist/components/data/DataGrid/DataGridColumnsModal/hooks.js +2 -1
- package/dist/components/data/DataGrid/DataGridFilterMenu/index.js +85 -7
- package/dist/components/data/DataGrid/DataGridFilterMenu/styles.d.ts +3 -9
- package/dist/components/data/DataGrid/DataGridFilterMenu/styles.js +10 -37
- package/dist/components/data/DataGrid/DataGridFooter.d.ts +1 -1
- package/dist/components/data/DataGrid/DataGridFooter.js +35 -12
- package/dist/components/data/DataGrid/DataGridHeader.js +1 -1
- package/dist/components/data/DataGrid/DataGridHeaderCell.js +6 -22
- package/dist/components/data/DataGrid/helpers/columns.d.ts +1 -1
- package/dist/components/data/DataGrid/helpers/columns.js +71 -16
- package/dist/components/data/DataGrid/hooks/useDataGrid.d.ts +1 -1
- package/dist/components/data/DataGrid/hooks/useDataGrid.js +60 -30
- package/dist/components/data/DataGrid/hooks/useDataGridCopy.d.ts +2 -2
- package/dist/components/data/DataGrid/hooks/useDataGridCopy.js +41 -39
- package/dist/components/data/DataGrid/index.d.ts +4 -2
- package/dist/components/data/DataGrid/index.js +22 -12
- package/dist/components/data/DataGrid/styles.d.ts +8 -4
- package/dist/components/data/DataGrid/styles.js +27 -17
- package/dist/components/data/DataGrid/types.d.ts +8 -1
- package/dist/components/data/SqlRequestDataGrid/helpers/columns.d.ts +1 -1
- package/dist/components/data/SqlRequestDataGrid/helpers/columns.js +24 -11
- package/dist/components/data/SqlRequestDataGrid/index.js +105 -33
- package/dist/components/ui/ContextMenu/index.d.ts +11 -0
- package/dist/components/ui/ContextMenu/index.js +58 -0
- package/dist/components/ui/ContextMenu/styles.d.ts +18 -0
- package/dist/components/ui/ContextMenu/styles.js +56 -0
- package/dist/services/advancedRequests.d.ts +1 -1
- package/dist/services/sqlRequests.d.ts +9 -4
- package/dist/services/sqlRequests.js +1 -0
- package/package.json +1 -1
- package/src/Icons.tsx +24 -0
- package/src/components/data/AdvancedRequestDataGrid/index.tsx +3 -5
- package/src/components/data/DataGrid/DataGridColumnsModal/hooks.tsx +2 -1
- package/src/components/data/DataGrid/DataGridFilterMenu/index.tsx +173 -9
- package/src/components/data/DataGrid/DataGridFilterMenu/styles.ts +13 -64
- package/src/components/data/DataGrid/DataGridFooter.tsx +20 -22
- package/src/components/data/DataGrid/DataGridHeader.tsx +5 -5
- package/src/components/data/DataGrid/DataGridHeaderCell.tsx +3 -38
- package/src/components/data/DataGrid/helpers/columns.tsx +98 -7
- package/src/components/data/DataGrid/hooks/useDataGrid.tsx +58 -17
- package/src/components/data/DataGrid/hooks/useDataGridCopy.ts +35 -30
- package/src/components/data/DataGrid/index.tsx +21 -14
- package/src/components/data/DataGrid/styles.ts +28 -7
- package/src/components/data/DataGrid/types.ts +20 -1
- package/src/components/data/SqlRequestDataGrid/helpers/columns.tsx +38 -3
- package/src/components/data/SqlRequestDataGrid/index.tsx +116 -21
- package/src/components/ui/ContextMenu/index.tsx +73 -0
- package/src/components/ui/ContextMenu/styles.ts +115 -0
- package/src/services/advancedRequests.ts +1 -1
- package/src/services/sqlRequests.ts +16 -5
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -19,12 +19,18 @@ var jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
19
19
|
var numbers_1 = require("../../../../helpers/numbers");
|
|
20
20
|
var filters_1 = require("./filters");
|
|
21
21
|
var moment_1 = __importDefault(require("moment"));
|
|
22
|
+
var lodash_1 = require("lodash");
|
|
22
23
|
var isColumnVisible = function (obj) { return (obj === null || obj === void 0 ? void 0 : obj.order) !== -1; };
|
|
23
24
|
exports.isColumnVisible = isColumnVisible;
|
|
25
|
+
var buildExcelFormat = function (decimals, suffix) {
|
|
26
|
+
if (decimals === void 0) { decimals = 2; }
|
|
27
|
+
if (suffix === void 0) { suffix = ''; }
|
|
28
|
+
return "#0".concat(decimals > 0 ? ".".concat((0, lodash_1.repeat)('0', decimals)) : '').concat(suffix);
|
|
29
|
+
};
|
|
24
30
|
var textColumn = function (key, title, options) {
|
|
25
31
|
var _a;
|
|
26
32
|
return (_a = {},
|
|
27
|
-
_a[key] = __assign({ name: title, render: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, filter: (0, filters_1.textFilter)(key) }, options),
|
|
33
|
+
_a[key] = __assign({ name: title, render: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, footer: function (_, filteredRows) { return "".concat(filteredRows.length, " \u00E9l\u00E9ments"); }, filter: (0, filters_1.textFilter)(key) }, options),
|
|
28
34
|
_a);
|
|
29
35
|
};
|
|
30
36
|
exports.textColumn = textColumn;
|
|
@@ -36,7 +42,7 @@ var mailColumn = function (key, title, options) {
|
|
|
36
42
|
return ((0, jsx_runtime_1.jsx)("a", {
|
|
37
43
|
// className="text-blue-500 hover:text-blue-700"
|
|
38
44
|
href: "mailto:".concat(row[key]), children: (_a = row[key]) !== null && _a !== void 0 ? _a : '' }));
|
|
39
|
-
}, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, filter: (0, filters_1.textFilter)(key) }, options),
|
|
45
|
+
}, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, footer: function (_, filteredRows) { return "".concat(filteredRows.length, " \u00E9l\u00E9ments"); }, filter: (0, filters_1.textFilter)(key) }, options),
|
|
40
46
|
_a);
|
|
41
47
|
};
|
|
42
48
|
exports.mailColumn = mailColumn;
|
|
@@ -48,21 +54,21 @@ var phoneColumn = function (key, title, options) {
|
|
|
48
54
|
return ((0, jsx_runtime_1.jsx)("a", {
|
|
49
55
|
// className="text-blue-500 hover:text-blue-700"
|
|
50
56
|
href: "tel:".concat(row[key]), children: (_a = row[key]) !== null && _a !== void 0 ? _a : '' }));
|
|
51
|
-
}, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, filter: (0, filters_1.textFilter)(key) }, options),
|
|
57
|
+
}, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, footer: function (_, filteredRows) { return "".concat(filteredRows.length, " \u00E9l\u00E9ments"); }, filter: (0, filters_1.textFilter)(key) }, options),
|
|
52
58
|
_a);
|
|
53
59
|
};
|
|
54
60
|
exports.phoneColumn = phoneColumn;
|
|
55
61
|
var dateColumn = function (key, title, options) {
|
|
56
62
|
var _a;
|
|
57
63
|
return (_a = {},
|
|
58
|
-
_a[key] = __assign({ name: title, render: function (row) { var _a; return (_a = (0, moment_1.default)(row[key]).format('DD/MM/YYYY')) !== null && _a !== void 0 ? _a : ''; }, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, filter: (0, filters_1.textFilter)(key) }, options),
|
|
64
|
+
_a[key] = __assign({ name: title, render: function (row) { var _a; return (_a = (0, moment_1.default)(row[key]).format('DD/MM/YYYY')) !== null && _a !== void 0 ? _a : ''; }, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, footer: function (_, filteredRows) { return "".concat(filteredRows.length, " \u00E9l\u00E9ments"); }, filter: (0, filters_1.textFilter)(key) }, options),
|
|
59
65
|
_a);
|
|
60
66
|
};
|
|
61
67
|
exports.dateColumn = dateColumn;
|
|
62
68
|
var monthColumn = function (key, title, options) {
|
|
63
69
|
var _a;
|
|
64
70
|
return (_a = {},
|
|
65
|
-
_a[key] = __assign({ name: title, render: function (row) { return (row[key] ? "".concat(row[key], " mois ") : ''); }, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, filter: (0, filters_1.textFilter)(key) }, options),
|
|
71
|
+
_a[key] = __assign({ name: title, render: function (row) { return (row[key] ? "".concat(row[key], " mois ") : ''); }, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, footer: function (_, filteredRows) { return "".concat(filteredRows.length, " \u00E9l\u00E9ments"); }, filter: (0, filters_1.textFilter)(key) }, options),
|
|
66
72
|
_a);
|
|
67
73
|
};
|
|
68
74
|
exports.monthColumn = monthColumn;
|
|
@@ -70,12 +76,22 @@ var numberColumn = function (key, title, decimals, options) {
|
|
|
70
76
|
var _a;
|
|
71
77
|
if (decimals === void 0) { decimals = 2; }
|
|
72
78
|
return (_a = {},
|
|
73
|
-
_a[key] = __assign({ name: title, render: function (row) { var _a; return (_a = (0, numbers_1.formatNumber)(row[key], decimals)) !== null && _a !== void 0 ? _a : ''; }, excelFormatter: function () { return '#'; }, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; },
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
_a[key] = __assign({ name: title, render: function (row) { var _a; return (_a = (0, numbers_1.formatNumber)(row[key], decimals)) !== null && _a !== void 0 ? _a : ''; }, excelFormatter: function () { return '#'; }, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, footer: {
|
|
80
|
+
sum: function (_, filteredRows) {
|
|
81
|
+
return (0, numbers_1.formatNumber)(filteredRows.reduce(function (acc, row) { var _a; return acc + ((_a = row[key]) !== null && _a !== void 0 ? _a : 0); }, 0), decimals);
|
|
82
|
+
},
|
|
83
|
+
average: function (_, filteredRows) {
|
|
84
|
+
return (0, numbers_1.formatNumber)(filteredRows.reduce(function (acc, row) { var _a; return acc + ((_a = row[key]) !== null && _a !== void 0 ? _a : 0); }, 0) /
|
|
85
|
+
(filteredRows.length || 1), decimals);
|
|
86
|
+
},
|
|
87
|
+
count: function (_, filteredRows) { return "".concat(filteredRows.length, " \u00E9l\u00E9ments"); },
|
|
88
|
+
max: function (_, filteredRows) {
|
|
89
|
+
return (0, numbers_1.formatNumber)(Math.max.apply(Math, filteredRows.map(function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : 0; })), decimals);
|
|
90
|
+
},
|
|
91
|
+
min: function (_, filteredRows) {
|
|
92
|
+
return (0, numbers_1.formatNumber)(Math.min.apply(Math, filteredRows.map(function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : 0; })), decimals);
|
|
93
|
+
},
|
|
94
|
+
}, filter: __assign(__assign({}, (0, filters_1.numberFilter)(key)), { renderer: function (value) { var _a; return (_a = (0, numbers_1.formatNumber)(value, decimals)) !== null && _a !== void 0 ? _a : ''; } }) }, options),
|
|
79
95
|
_a);
|
|
80
96
|
};
|
|
81
97
|
exports.numberColumn = numberColumn;
|
|
@@ -83,21 +99,60 @@ var moneyColumn = function (key, title, decimals, options) {
|
|
|
83
99
|
var _a;
|
|
84
100
|
if (decimals === void 0) { decimals = 2; }
|
|
85
101
|
return (_a = {},
|
|
86
|
-
_a[key] = __assign({ name: title, render: function (row) { var _a; return (_a = (0, numbers_1.formatMoney)(row[key], decimals)) !== null && _a !== void 0 ? _a : ''; }, excelFormatter: function () { return '
|
|
102
|
+
_a[key] = __assign({ name: title, render: function (row) { var _a; return (_a = (0, numbers_1.formatMoney)(row[key], decimals)) !== null && _a !== void 0 ? _a : ''; }, excelFormatter: function () { return buildExcelFormat(decimals, ' €'); }, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, filter: __assign(__assign({}, (0, filters_1.numberFilter)(key)), { renderer: function (value) { var _a; return (_a = (0, numbers_1.formatMoney)(value, decimals)) !== null && _a !== void 0 ? _a : ''; } }), footer: {
|
|
103
|
+
sum: function (_, filteredRows) {
|
|
104
|
+
return (0, numbers_1.formatMoney)(filteredRows.reduce(function (acc, row) { var _a; return acc + ((_a = row[key]) !== null && _a !== void 0 ? _a : 0); }, 0), decimals);
|
|
105
|
+
},
|
|
106
|
+
average: function (_, filteredRows) {
|
|
107
|
+
return (0, numbers_1.formatMoney)(filteredRows.reduce(function (acc, row) { var _a; return acc + ((_a = row[key]) !== null && _a !== void 0 ? _a : 0); }, 0) /
|
|
108
|
+
(filteredRows.length || 1), decimals);
|
|
109
|
+
},
|
|
110
|
+
count: function (_, filteredRows) { return "".concat(filteredRows.length, " \u00E9l\u00E9ments"); },
|
|
111
|
+
max: function (_, filteredRows) {
|
|
112
|
+
return (0, numbers_1.formatMoney)(Math.max.apply(Math, filteredRows.map(function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : 0; })), decimals);
|
|
113
|
+
},
|
|
114
|
+
min: function (_, filteredRows) {
|
|
115
|
+
return (0, numbers_1.formatMoney)(Math.min.apply(Math, filteredRows.map(function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : 0; })), decimals);
|
|
116
|
+
},
|
|
117
|
+
} }, options),
|
|
87
118
|
_a);
|
|
88
119
|
};
|
|
89
120
|
exports.moneyColumn = moneyColumn;
|
|
90
|
-
var percentageColumn = function (key, title, options) {
|
|
121
|
+
var percentageColumn = function (key, title, decimals, options) {
|
|
91
122
|
var _a;
|
|
123
|
+
if (decimals === void 0) { decimals = 2; }
|
|
92
124
|
return (_a = {},
|
|
93
|
-
_a[key] = __assign({ name: title, render: function (row) { var _a; return (_a = (0, numbers_1.formatPercentage)(row[key])) !== null && _a !== void 0 ? _a : ''; }, excelFormatter: function () { return
|
|
125
|
+
_a[key] = __assign({ name: title, render: function (row) { var _a; return (_a = (0, numbers_1.formatPercentage)(row[key])) !== null && _a !== void 0 ? _a : ''; }, excelFormatter: function () { return buildExcelFormat(decimals); }, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, filter: (0, filters_1.numberFilter)(key), footer: {
|
|
126
|
+
average: function (_, filteredRows) {
|
|
127
|
+
return (0, numbers_1.formatNumber)(filteredRows.reduce(function (acc, row) { var _a; return acc + ((_a = row[key]) !== null && _a !== void 0 ? _a : 0); }, 0) /
|
|
128
|
+
(filteredRows.length || 1), decimals);
|
|
129
|
+
},
|
|
130
|
+
count: function (_, filteredRows) { return "".concat(filteredRows.length, " \u00E9l\u00E9ments"); },
|
|
131
|
+
max: function (_, filteredRows) {
|
|
132
|
+
return (0, numbers_1.formatNumber)(Math.max.apply(Math, filteredRows.map(function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : 0; })), decimals);
|
|
133
|
+
},
|
|
134
|
+
min: function (_, filteredRows) {
|
|
135
|
+
return (0, numbers_1.formatNumber)(Math.min.apply(Math, filteredRows.map(function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : 0; })), decimals);
|
|
136
|
+
},
|
|
137
|
+
sum: function (_, filteredRows) {
|
|
138
|
+
return (0, numbers_1.formatNumber)(filteredRows.reduce(function (acc, row) { var _a; return acc + ((_a = row[key]) !== null && _a !== void 0 ? _a : 0); }, 0), decimals);
|
|
139
|
+
},
|
|
140
|
+
} }, options),
|
|
94
141
|
_a);
|
|
95
142
|
};
|
|
96
143
|
exports.percentageColumn = percentageColumn;
|
|
97
144
|
var checkboxColumn = function (key, title, options) {
|
|
98
145
|
var _a;
|
|
99
146
|
return (_a = {},
|
|
100
|
-
_a[key] = __assign({ name: title, render: function (row) { return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { type: "checkbox", checked: row[key] }), (0, jsx_runtime_1.jsx)("span", { children: row[key] ? ' Oui' : ' Non' })] })); }, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, filter: (0, filters_1.numberFilter)(key)
|
|
147
|
+
_a[key] = __assign({ name: title, render: function (row) { return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("input", { type: "checkbox", checked: row[key] }), (0, jsx_runtime_1.jsx)("span", { children: row[key] ? ' Oui' : ' Non' })] })); }, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, filter: (0, filters_1.numberFilter)(key), footer: {
|
|
148
|
+
count: function (_, filteredRows) { return "".concat(filteredRows.length, " \u00E9l\u00E9ments"); },
|
|
149
|
+
checked: function (_, filteredRows) {
|
|
150
|
+
return "".concat(filteredRows.filter(function (row) { return !!row[key]; }).length, " coch\u00E9s");
|
|
151
|
+
},
|
|
152
|
+
unchecked: function (_, filteredRows) {
|
|
153
|
+
return "".concat(filteredRows.filter(function (row) { return !row[key]; }).length, " d\u00E9coch\u00E9s");
|
|
154
|
+
},
|
|
155
|
+
} }, options),
|
|
101
156
|
_a);
|
|
102
157
|
};
|
|
103
158
|
exports.checkboxColumn = checkboxColumn;
|
|
@@ -107,7 +162,7 @@ var colorColumn = function (key, title, options) {
|
|
|
107
162
|
_a[key] = __assign({ name: title, render: function (row) {
|
|
108
163
|
var _a;
|
|
109
164
|
return ((0, jsx_runtime_1.jsx)("div", { style: { backgroundColor: row[key] }, children: (_a = row[key]) !== null && _a !== void 0 ? _a : '' }));
|
|
110
|
-
}, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, filter: (0, filters_1.textFilter)(key) }, options),
|
|
165
|
+
}, getter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, sortGetter: function (row) { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; }, filter: (0, filters_1.textFilter)(key), footer: function (rows) { return "".concat(rows.length, " \u00E9l\u00E9ments"); } }, options),
|
|
111
166
|
_a);
|
|
112
167
|
};
|
|
113
168
|
exports.colorColumn = colorColumn;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { DataGridContext, DataGridContextProps, DataGridProps } from '../types';
|
|
2
|
-
export declare const useDataGrid: <R>(props: DataGridProps<R
|
|
2
|
+
export declare const useDataGrid: <R>(props: DataGridProps<R>, override?: Partial<DataGridContextProps<R>>) => [DataGridContextProps<R>, DataGridContext<R>];
|
|
@@ -66,12 +66,13 @@ var helpers_1 = require("../helpers");
|
|
|
66
66
|
var lodash_1 = require("lodash");
|
|
67
67
|
var useDataGridSettings_1 = require("./useDataGridSettings");
|
|
68
68
|
var hooks_1 = require("../../../../hooks");
|
|
69
|
-
var useDataGrid = function (props) {
|
|
70
|
-
var
|
|
71
|
-
var
|
|
69
|
+
var useDataGrid = function (props, override) {
|
|
70
|
+
var _a;
|
|
71
|
+
var rows = props.rows, onFiltersChanged = props.onFiltersChanged, onSortsChanged = props.onSortsChanged, loadCopyRows = props.loadCopyRows, _b = props.rowHeight, rowHeight = _b === void 0 ? styles_1.DEFAULT_ROW_HEIGHT : _b, onVisibleRowsChange = props.onVisibleRowsChange, onSelectionChange = props.onSelectionChange, selectable = props.selectable, initialSorts = props.initialSorts;
|
|
72
|
+
var _c = (0, react_1.useState)(props.columns), columns = _c[0], setColumns = _c[1];
|
|
72
73
|
var visibleColumns = (0, _1.useSortedColumns)(columns);
|
|
73
74
|
/** SETTINGS */
|
|
74
|
-
var
|
|
75
|
+
var _d = (0, useDataGridSettings_1.useDataGridSettings)(props.name), settings = _d.settings, setSettings = _d.setSettings, saveSettings = _d.saveSettings;
|
|
75
76
|
var setColumnWidth = (0, react_1.useCallback)(function (key, width) {
|
|
76
77
|
setSettings(function (prev) {
|
|
77
78
|
var _a;
|
|
@@ -79,7 +80,7 @@ var useDataGrid = function (props) {
|
|
|
79
80
|
});
|
|
80
81
|
}, [setSettings]);
|
|
81
82
|
var gridTemplateColumns = (0, react_1.useMemo)(function () {
|
|
82
|
-
return __spreadArray(__spreadArray([], (selectable ? ['var(--space-
|
|
83
|
+
return __spreadArray(__spreadArray([], (selectable ? ['var(--space-10)'] : []), true), visibleColumns.map(function (_a) {
|
|
83
84
|
var _b;
|
|
84
85
|
var col = _a[1];
|
|
85
86
|
return "".concat((_b = col.width) !== null && _b !== void 0 ? _b : 150, "px");
|
|
@@ -95,14 +96,14 @@ var useDataGrid = function (props) {
|
|
|
95
96
|
? props.rowKey
|
|
96
97
|
: function (row) { return String(row === null || row === void 0 ? void 0 : row[props.rowKey]); };
|
|
97
98
|
}, [props.rowKey]);
|
|
98
|
-
var
|
|
99
|
+
var _e = (0, react_1.useState)([]), selectedKeys = _e[0], setSelectedKeys = _e[1];
|
|
99
100
|
var selectedRows = (0, react_1.useMemo)(function () { return props.rows.filter(function (row) { return selectedKeys.includes(rowKeyGetter(row)); }); }, [props.rows, rowKeyGetter, selectedKeys]);
|
|
100
101
|
(0, react_1.useEffect)(function () {
|
|
101
102
|
onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(selectedKeys);
|
|
102
103
|
}, [onSelectionChange, selectedKeys]);
|
|
103
104
|
/** ROWS FILTERING **/
|
|
104
|
-
var
|
|
105
|
-
var
|
|
105
|
+
var _f = (0, react_1.useState)({}), filters = _f[0], setFilters = _f[1];
|
|
106
|
+
var _g = (0, react_1.useState)(rows !== null && rows !== void 0 ? rows : []), filteredRows = _g[0], setFilteredRows = _g[1];
|
|
106
107
|
(0, react_1.useEffect)(function () {
|
|
107
108
|
onFiltersChanged === null || onFiltersChanged === void 0 ? void 0 : onFiltersChanged(filters);
|
|
108
109
|
}, [filters, onFiltersChanged]);
|
|
@@ -116,10 +117,10 @@ var useDataGrid = function (props) {
|
|
|
116
117
|
setFilteredRows(filteredRows !== null && filteredRows !== void 0 ? filteredRows : []);
|
|
117
118
|
}, [filters, props.filter, rows]);
|
|
118
119
|
/** CELL EDITING */
|
|
119
|
-
var
|
|
120
|
+
var _h = (0, react_1.useState)([-1, -1]), editingCell = _h[0], setEditingCell = _h[1];
|
|
120
121
|
/** ROWS SORTING **/
|
|
121
|
-
var
|
|
122
|
-
var
|
|
122
|
+
var _j = (0, react_1.useState)(initialSorts !== null && initialSorts !== void 0 ? initialSorts : {}), sorts = _j[0], setSorts = _j[1];
|
|
123
|
+
var _k = (0, react_1.useState)(rows), sortedRows = _k[0], setSortedRows = _k[1];
|
|
123
124
|
(0, react_1.useEffect)(function () {
|
|
124
125
|
var sortedRows = __spreadArray([], filteredRows, true);
|
|
125
126
|
if (props.sort !== false) {
|
|
@@ -148,10 +149,10 @@ var useDataGrid = function (props) {
|
|
|
148
149
|
/** VIRTUAL SCROLLING */
|
|
149
150
|
var scrollableRef = (0, react_1.useRef)(null);
|
|
150
151
|
var height = (0, hooks_1.useElementSize)(scrollableRef.current).height;
|
|
151
|
-
var
|
|
152
|
-
var
|
|
152
|
+
var _l = (0, react_1.useState)(0), scrollTop = _l[0], setScrollTop = _l[1];
|
|
153
|
+
var _m =
|
|
153
154
|
// props.showAllRows ? [0, sortedRows.length] :
|
|
154
|
-
[Math.floor(scrollTop / rowHeight), Math.ceil(height / rowHeight)], index =
|
|
155
|
+
[Math.floor(scrollTop / rowHeight), Math.ceil(height / rowHeight)], index = _m[0], length = _m[1];
|
|
155
156
|
var onScroll = (0, react_1.useCallback)(function (e) {
|
|
156
157
|
var target = e.target;
|
|
157
158
|
setScrollTop(target.scrollTop);
|
|
@@ -162,29 +163,56 @@ var useDataGrid = function (props) {
|
|
|
162
163
|
(0, react_1.useEffect)(function () {
|
|
163
164
|
onVisibleRowsChange === null || onVisibleRowsChange === void 0 ? void 0 : onVisibleRowsChange(indexWithTolerance, lengthWithTolerance);
|
|
164
165
|
}, [indexWithTolerance, lengthWithTolerance, onVisibleRowsChange]);
|
|
166
|
+
/** FOOTERS */
|
|
167
|
+
var _o = (0, react_1.useState)((_a = props.initialFooters) !== null && _a !== void 0 ? _a : {}), footers = _o[0], setFooters = _o[1];
|
|
168
|
+
var footerFunctions = (0, react_1.useMemo)(function () {
|
|
169
|
+
return Object.entries(footers).reduce(function (acc, _a) {
|
|
170
|
+
var columnKey = _a[0], footerKey = _a[1];
|
|
171
|
+
var column = columns[columnKey];
|
|
172
|
+
if (!column) {
|
|
173
|
+
return acc;
|
|
174
|
+
}
|
|
175
|
+
if (typeof column.footer === 'function') {
|
|
176
|
+
acc[columnKey] = column.footer;
|
|
177
|
+
}
|
|
178
|
+
else if (typeof column.footer === 'object' &&
|
|
179
|
+
typeof column.footer[footerKey] === 'function') {
|
|
180
|
+
acc[columnKey] = column.footer[footerKey];
|
|
181
|
+
}
|
|
182
|
+
return acc;
|
|
183
|
+
}, {});
|
|
184
|
+
}, [columns, footers]);
|
|
165
185
|
/** COPYING */
|
|
166
|
-
var copyTable = (0, _1.useDataGridCopy)(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
length,
|
|
174
|
-
onScroll,
|
|
186
|
+
var copyTable = (0, _1.useDataGridCopy)({
|
|
187
|
+
rows: rows,
|
|
188
|
+
visibleColumns: visibleColumns,
|
|
189
|
+
footerFunctions: footerFunctions,
|
|
190
|
+
loadCopyRows: loadCopyRows,
|
|
191
|
+
}).copyTable;
|
|
192
|
+
var contextValue = (0, react_1.useMemo)(function () { return (__assign(__assign(__assign({}, props), { columns: columns, visibleColumns: visibleColumns, sortedRows: sortedRows, selectedRows: selectedRows, selectedKeys: selectedKeys, setSelectedKeys: setSelectedKeys, sorts: sorts, setSorts: setSorts, filters: filters, setFilters: setFilters, editingCell: editingCell, setEditingCell: setEditingCell, copyTable: copyTable, setColumnWidth: setColumnWidth, settings: settings, setSettings: setSettings, saveSettings: saveSettings, visibleRows: visibleRows, scrollableRef: scrollableRef, onScroll: onScroll, index: index, length: length, rowKeyGetter: rowKeyGetter, gridTemplateColumns: gridTemplateColumns, footers: footers, setFooters: setFooters, footerFunctions: footerFunctions }), override)); }, [
|
|
175
193
|
props,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
194
|
+
columns,
|
|
195
|
+
visibleColumns,
|
|
196
|
+
sortedRows,
|
|
179
197
|
selectedRows,
|
|
198
|
+
selectedKeys,
|
|
199
|
+
sorts,
|
|
200
|
+
filters,
|
|
201
|
+
editingCell,
|
|
202
|
+
copyTable,
|
|
180
203
|
setColumnWidth,
|
|
181
|
-
setSettings,
|
|
182
204
|
settings,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
visibleColumns,
|
|
205
|
+
setSettings,
|
|
206
|
+
saveSettings,
|
|
186
207
|
visibleRows,
|
|
208
|
+
onScroll,
|
|
209
|
+
index,
|
|
210
|
+
length,
|
|
211
|
+
rowKeyGetter,
|
|
187
212
|
gridTemplateColumns,
|
|
213
|
+
footers,
|
|
214
|
+
footerFunctions,
|
|
215
|
+
override,
|
|
188
216
|
]);
|
|
189
217
|
var context = (0, react_1.useMemo)(function () {
|
|
190
218
|
return (0, react_1.createContext)({
|
|
@@ -214,6 +242,8 @@ var useDataGrid = function (props) {
|
|
|
214
242
|
index: 0,
|
|
215
243
|
length: 0,
|
|
216
244
|
gridTemplateColumns: '',
|
|
245
|
+
footers: {},
|
|
246
|
+
setFooters: function () { },
|
|
217
247
|
});
|
|
218
248
|
}, []);
|
|
219
249
|
return (0, react_1.useMemo)(function () { return [contextValue, context]; }, [context, contextValue]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const useDataGridCopy: <R>(rows
|
|
1
|
+
import { DataGridContextProps } from '../types';
|
|
2
|
+
export declare const useDataGridCopy: <R>({ rows, visibleColumns, loadCopyRows, footerFunctions, }: Pick<DataGridContextProps<R>, "rows" | "visibleColumns" | "loadCopyRows" | "footerFunctions">) => {
|
|
3
3
|
copyTable: (includeHeaders?: boolean, includeFooters?: boolean) => Promise<void>;
|
|
4
4
|
};
|
|
@@ -48,23 +48,26 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
48
48
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
49
|
exports.useDataGridCopy = void 0;
|
|
50
50
|
var react_1 = require("react");
|
|
51
|
-
var useDataGridCopy = function (
|
|
51
|
+
var useDataGridCopy = function (_a) {
|
|
52
|
+
var rows = _a.rows, _b = _a.visibleColumns, visibleColumns = _b === void 0 ? [] : _b, loadCopyRows = _a.loadCopyRows, footerFunctions = _a.footerFunctions;
|
|
52
53
|
var generateHeadersHtml = (0, react_1.useCallback)(function () {
|
|
53
|
-
return "<tr>\n ".concat(
|
|
54
|
-
.map(function (
|
|
54
|
+
return "<tr>\n ".concat(visibleColumns
|
|
55
|
+
.map(function (_a) {
|
|
56
|
+
var col = _a[1];
|
|
55
57
|
return "<th style=\"\n text-align: left;\n font-weight: bold;\n white-space: nowrap;\n \">\n ".concat(col.name, "\n </th>");
|
|
56
58
|
})
|
|
57
59
|
.join('\n'), "\n </tr>");
|
|
58
|
-
}, [
|
|
60
|
+
}, [visibleColumns]);
|
|
59
61
|
var generateFootersHtml = (0, react_1.useCallback)(function (rowsToCopy) {
|
|
60
|
-
|
|
61
|
-
.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
console.log('generate footers html');
|
|
63
|
+
return "<tr>\n ".concat(visibleColumns
|
|
64
|
+
.map(function (_a) {
|
|
65
|
+
var _b, _c;
|
|
66
|
+
var colKey = _a[0];
|
|
67
|
+
return "<td style=\"\n font-weight: bold;\n white-space: nowrap;\n \">\n ".concat((_c = (_b = footerFunctions === null || footerFunctions === void 0 ? void 0 : footerFunctions[colKey]) === null || _b === void 0 ? void 0 : _b.call(footerFunctions, rowsToCopy, rowsToCopy, [])) !== null && _c !== void 0 ? _c : '', "\n </td>");
|
|
65
68
|
})
|
|
66
69
|
.join('\n'), "\n </tr>");
|
|
67
|
-
}, [
|
|
70
|
+
}, [footerFunctions, visibleColumns]);
|
|
68
71
|
var generateCellText = (0, react_1.useCallback)(function (col, value) {
|
|
69
72
|
var _a;
|
|
70
73
|
return col.excelValue ? col.excelValue(value) : (_a = value === null || value === void 0 ? void 0 : value.toString()) !== null && _a !== void 0 ? _a : '';
|
|
@@ -75,33 +78,38 @@ var useDataGridCopy = function (rows, columns, loadCopyRows) {
|
|
|
75
78
|
var generateCopyHtml = (0, react_1.useCallback)(function (rowsToCopy, includeHeaders, includeFooters) {
|
|
76
79
|
return "\n <table>\n ".concat(includeHeaders ? generateHeadersHtml() : '', "\n ").concat((rowsToCopy || [])
|
|
77
80
|
.map(function (row) {
|
|
78
|
-
return "<tr>\n ".concat(
|
|
79
|
-
.map(function (
|
|
81
|
+
return "<tr>\n ".concat(visibleColumns
|
|
82
|
+
.map(function (_a) {
|
|
83
|
+
var col = _a[1];
|
|
80
84
|
var value = col.getter && row ? col.getter(row) : '';
|
|
81
85
|
return generateCellHtml(col, value);
|
|
82
86
|
})
|
|
83
87
|
.join('\n'), "\n </tr>");
|
|
84
88
|
})
|
|
85
89
|
.join('\n'), "\n ").concat(includeFooters ? generateFootersHtml(rowsToCopy) : '', "\n </table>\n ");
|
|
86
|
-
}, [
|
|
90
|
+
}, [visibleColumns, generateCellHtml, generateFootersHtml, generateHeadersHtml]);
|
|
87
91
|
var generateHeadersText = (0, react_1.useCallback)(function () {
|
|
88
|
-
return
|
|
89
|
-
|
|
90
|
-
.
|
|
91
|
-
|
|
92
|
+
return visibleColumns.map(function (_a) {
|
|
93
|
+
var col = _a[1];
|
|
94
|
+
return col.name;
|
|
95
|
+
}).join('\t');
|
|
96
|
+
}, [visibleColumns]);
|
|
92
97
|
var generateFootersText = (0, react_1.useCallback)(function (rowsToCopy) {
|
|
93
|
-
return
|
|
94
|
-
.map(function (
|
|
95
|
-
|
|
98
|
+
return visibleColumns
|
|
99
|
+
.map(function (_a) {
|
|
100
|
+
var _b, _c;
|
|
101
|
+
var colKey = _a[0];
|
|
102
|
+
return (_c = (_b = footerFunctions === null || footerFunctions === void 0 ? void 0 : footerFunctions[colKey]) === null || _b === void 0 ? void 0 : _b.call(footerFunctions, rowsToCopy, [], [])) !== null && _c !== void 0 ? _c : '';
|
|
96
103
|
})
|
|
97
104
|
.join('\t');
|
|
98
|
-
}, [
|
|
105
|
+
}, [footerFunctions, visibleColumns]);
|
|
99
106
|
var generateCopyText = (0, react_1.useCallback)(function (rowsToCopy, includeHeaders, includeFooters) {
|
|
100
107
|
return __spreadArray(__spreadArray([
|
|
101
108
|
includeHeaders ? generateHeadersText() : ''
|
|
102
109
|
], (rowsToCopy || []).map(function (row) {
|
|
103
|
-
return
|
|
104
|
-
.map(function (
|
|
110
|
+
return visibleColumns
|
|
111
|
+
.map(function (_a) {
|
|
112
|
+
var col = _a[1];
|
|
105
113
|
var value = col.getter && row ? col.getter(row) : '';
|
|
106
114
|
return col.excelValue
|
|
107
115
|
? col.excelValue(value)
|
|
@@ -114,29 +122,23 @@ var useDataGridCopy = function (rows, columns, loadCopyRows) {
|
|
|
114
122
|
includeFooters ? generateFootersText(rowsToCopy) : '',
|
|
115
123
|
], false).filter(function (s) { return s != null; })
|
|
116
124
|
.join('\n');
|
|
117
|
-
}, [
|
|
125
|
+
}, [visibleColumns, generateFootersText, generateHeadersText]);
|
|
118
126
|
var copyTable = (0, react_1.useCallback)(function () {
|
|
119
127
|
var args_1 = [];
|
|
120
128
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
121
129
|
args_1[_i] = arguments[_i];
|
|
122
130
|
}
|
|
123
131
|
return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (includeHeaders, includeFooters) {
|
|
124
|
-
var rowsToCopy,
|
|
132
|
+
var rowsToCopy, copyHtml, copyText;
|
|
125
133
|
if (includeHeaders === void 0) { includeHeaders = true; }
|
|
126
134
|
if (includeFooters === void 0) { includeFooters = true; }
|
|
127
|
-
return __generator(this, function (
|
|
128
|
-
switch (
|
|
129
|
-
case 0:
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
return __generator(this, function (_a) {
|
|
136
|
+
switch (_a.label) {
|
|
137
|
+
case 0: return [4 /*yield*/, (loadCopyRows !== null && loadCopyRows !== void 0 ? loadCopyRows : (function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
138
|
+
return [2 /*return*/, rows];
|
|
139
|
+
}); }); }))()];
|
|
132
140
|
case 1:
|
|
133
|
-
|
|
134
|
-
return [3 /*break*/, 3];
|
|
135
|
-
case 2:
|
|
136
|
-
_a = rows;
|
|
137
|
-
_b.label = 3;
|
|
138
|
-
case 3:
|
|
139
|
-
rowsToCopy = _a;
|
|
141
|
+
rowsToCopy = _a.sent();
|
|
140
142
|
copyHtml = generateCopyHtml(rowsToCopy, includeHeaders, includeFooters);
|
|
141
143
|
copyText = generateCopyText(rowsToCopy, includeHeaders, includeFooters);
|
|
142
144
|
return [4 /*yield*/, navigator['clipboard'].write([
|
|
@@ -145,8 +147,8 @@ var useDataGridCopy = function (rows, columns, loadCopyRows) {
|
|
|
145
147
|
'text/html': new Blob([copyHtml], { type: 'text/html' }),
|
|
146
148
|
}),
|
|
147
149
|
])];
|
|
148
|
-
case
|
|
149
|
-
|
|
150
|
+
case 2:
|
|
151
|
+
_a.sent();
|
|
150
152
|
return [2 /*return*/];
|
|
151
153
|
}
|
|
152
154
|
});
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import { DataGridProps } from './types';
|
|
2
|
-
export declare const DataGrid: <R>(props: DataGridProps<R>
|
|
1
|
+
import { DataGridContextProps, DataGridProps } from './types';
|
|
2
|
+
export declare const DataGrid: <R>({ contextOverride, ...props }: DataGridProps<R> & {
|
|
3
|
+
contextOverride?: Partial<DataGridContextProps<R>>;
|
|
4
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -33,6 +33,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
33
33
|
__setModuleDefault(result, mod);
|
|
34
34
|
return result;
|
|
35
35
|
};
|
|
36
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
37
|
+
var t = {};
|
|
38
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
39
|
+
t[p] = s[p];
|
|
40
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
41
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
42
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
43
|
+
t[p[i]] = s[p[i]];
|
|
44
|
+
}
|
|
45
|
+
return t;
|
|
46
|
+
};
|
|
36
47
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
37
48
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
38
49
|
if (ar || !(i in from)) {
|
|
@@ -54,23 +65,22 @@ var react_1 = require("react");
|
|
|
54
65
|
var hooks_1 = require("./hooks");
|
|
55
66
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
56
67
|
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
|
57
|
-
var DataGrid = function (
|
|
68
|
+
var DataGrid = function (_a) {
|
|
69
|
+
var contextOverride = _a.contextOverride, props = __rest(_a, ["contextOverride"]);
|
|
58
70
|
var className = props.className,
|
|
59
71
|
// onRowDoubleClick,
|
|
60
72
|
onVisibleRowsChange = props.onVisibleRowsChange;
|
|
61
|
-
var
|
|
62
|
-
var selectedKeys = contextProps.selectedKeys, setSelectedKeys = contextProps.setSelectedKeys, columns = contextProps.columns, visibleColumns = contextProps.visibleColumns,
|
|
73
|
+
var _b = (0, hooks_1.useDataGrid)(props, contextOverride), contextProps = _b[0], DataGridContext = _b[1];
|
|
74
|
+
var selectedKeys = contextProps.selectedKeys, setSelectedKeys = contextProps.setSelectedKeys, columns = contextProps.columns, visibleColumns = contextProps.visibleColumns, _c = contextProps.rowHeight, rowHeight = _c === void 0 ? 32 : _c, _d = contextProps.headerRowHeight, headerRowHeight = _d === void 0 ? 40 : _d, scrollableRef = contextProps.scrollableRef, onScroll = contextProps.onScroll, rowKeyGetter = contextProps.rowKeyGetter;
|
|
63
75
|
var hasFooter = Object.values(columns).some(function (col) { return col.footer; });
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!selectedKeys.includes(key))
|
|
68
|
-
setSelectedKeys(__spreadArray(__spreadArray([], selectedKeys, true), [key], false));
|
|
76
|
+
var toggleSelection = (0, react_1.useCallback)(function (key) {
|
|
77
|
+
if (selectedKeys.includes(key)) {
|
|
78
|
+
setSelectedKeys(selectedKeys.filter(function (p) { return p !== key; }));
|
|
69
79
|
}
|
|
70
80
|
else {
|
|
71
|
-
setSelectedKeys(
|
|
81
|
+
setSelectedKeys(__spreadArray(__spreadArray([], selectedKeys, true), [key], false));
|
|
72
82
|
}
|
|
73
|
-
}, [
|
|
83
|
+
}, [selectedKeys, setSelectedKeys]);
|
|
74
84
|
var rowTemplate = (0, react_1.useCallback)(function (row, rowIndex) {
|
|
75
85
|
var _a, _b;
|
|
76
86
|
if (!row) {
|
|
@@ -81,7 +91,7 @@ var DataGrid = function (props) {
|
|
|
81
91
|
className: '',
|
|
82
92
|
style: undefined,
|
|
83
93
|
}, className = _c.className, style = _c.style;
|
|
84
|
-
return ((0, jsx_runtime_1.jsxs)(styles.DataGridRow, { children: [!!props.selectable && ((0, jsx_runtime_1.jsx)(styles.SelectionCell, { children: (0, jsx_runtime_1.jsx)("input", { type: "checkbox", value: key, checked: selectedKeys.includes(key),
|
|
94
|
+
return ((0, jsx_runtime_1.jsxs)(styles.DataGridRow, { children: [!!props.selectable && ((0, jsx_runtime_1.jsx)(styles.SelectionCell, { onClick: function () { return toggleSelection(key); }, children: (0, jsx_runtime_1.jsx)("input", { type: "checkbox", value: key, checked: selectedKeys.includes(key), readOnly: true }) }, "__select_checkbox__")), visibleColumns.map(function (_a, index) {
|
|
85
95
|
var key = _a[0], col = _a[1];
|
|
86
96
|
return ((0, jsx_runtime_1.jsx)(DataGridCell_1.DataGridCell, __assign({}, (index === 0 ? { className: className, style: style } : {}), { row: row, rowIndex: rowIndex, column: col, columnIndex: index, context: DataGridContext, columnKey: key }), "loading-".concat(rowIndex, "-").concat(index)));
|
|
87
97
|
})] }, key));
|
|
@@ -90,7 +100,7 @@ var DataGrid = function (props) {
|
|
|
90
100
|
props,
|
|
91
101
|
rowKeyGetter,
|
|
92
102
|
selectedKeys,
|
|
93
|
-
|
|
103
|
+
toggleSelection,
|
|
94
104
|
visibleColumns,
|
|
95
105
|
]);
|
|
96
106
|
return ((0, jsx_runtime_1.jsx)(DataGridContext.Provider, { value: contextProps, children: (0, jsx_runtime_1.jsxs)(styles.DataGridContainer, { ref: scrollableRef, onScroll: onScroll, "$headerRowHeight": headerRowHeight, "$rowHeight": rowHeight, "$rowsCount": contextProps.sortedRows.length, className: className, children: [(0, jsx_runtime_1.jsx)(DataGridHeader_1.DataGridHeader, { context: DataGridContext }), (0, jsx_runtime_1.jsx)(VirtualScroller_1.VirtualScroller, { onRangeChange: onVisibleRowsChange, hasFooter: hasFooter, rowTemplate: rowTemplate, context: DataGridContext }), hasFooter && (0, jsx_runtime_1.jsx)(DataGridFooter_1.DataGridFooter, { context: DataGridContext })] }) }));
|
|
@@ -32,13 +32,17 @@ export declare const DataGridContainer: import("styled-components/dist/types").I
|
|
|
32
32
|
$rowsCount: number;
|
|
33
33
|
$showToolsHeader?: boolean;
|
|
34
34
|
}>> & string;
|
|
35
|
-
|
|
36
|
-
ref?: ((instance: HTMLDivElement | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
37
|
-
}>, {
|
|
35
|
+
type DataGridHeaderOrFooterRowProps = {
|
|
38
36
|
$headerRowHeight?: number;
|
|
39
37
|
$headerColor?: ThemeColor;
|
|
40
38
|
$gridTemplateColumns: string;
|
|
41
|
-
}
|
|
39
|
+
};
|
|
40
|
+
export declare const DataGridHeaderRow: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components/dist/types").Substitute<import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
41
|
+
ref?: ((instance: HTMLDivElement | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
42
|
+
}>, DataGridHeaderOrFooterRowProps>, never>> & string;
|
|
43
|
+
export declare const DataGridFooterRow: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("styled-components/dist/types").Substitute<import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
44
|
+
ref?: ((instance: HTMLDivElement | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
45
|
+
}>, DataGridHeaderOrFooterRowProps>, never>> & string;
|
|
42
46
|
export declare const DataGridRow: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
|
|
43
47
|
export declare const LoadingCell: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<Omit<import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>, "ref"> & {
|
|
44
48
|
ref?: ((instance: HTMLDivElement | null) => void | import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof import("react").DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | import("react").RefObject<HTMLDivElement> | null | undefined;
|