@jirawatpyk/aura-react 4.4.1
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/LICENSE +30 -0
- package/README.md +68 -0
- package/dist/aura.bundle.js +4087 -0
- package/dist/cjs/index.cjs +4069 -0
- package/dist/esm/Button.js +29 -0
- package/dist/esm/Checkbox.js +49 -0
- package/dist/esm/Combobox.js +257 -0
- package/dist/esm/DataTable.js +826 -0
- package/dist/esm/DatePicker.js +575 -0
- package/dist/esm/Dialog.js +90 -0
- package/dist/esm/DropdownMenu.js +38 -0
- package/dist/esm/FileUpload.js +173 -0
- package/dist/esm/Icon.js +35 -0
- package/dist/esm/IconButton.js +18 -0
- package/dist/esm/Menu.js +98 -0
- package/dist/esm/Stat.js +45 -0
- package/dist/esm/StatusPill.js +32 -0
- package/dist/esm/Surface.js +22 -0
- package/dist/esm/ThemeStyle.js +13 -0
- package/dist/esm/TimePicker.js +302 -0
- package/dist/esm/extra.js +328 -0
- package/dist/esm/feedback.js +192 -0
- package/dist/esm/forms.js +181 -0
- package/dist/esm/index.js +89 -0
- package/dist/esm/internal.js +84 -0
- package/dist/esm/layout.js +198 -0
- package/dist/esm/layout2.js +114 -0
- package/dist/esm/locale.js +204 -0
- package/dist/esm/overlay.js +46 -0
- package/dist/esm/theme.js +186 -0
- package/dist/index.d.ts +825 -0
- package/dist/styles.css +967 -0
- package/package.json +78 -0
- package/scripts/aura-theme.mjs +24 -0
- package/src/theme.js +147 -0
|
@@ -0,0 +1,826 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { useStrings, useAuraLocale } from "./locale.js";
|
|
4
|
+
import { cx, omit, useMaybeControlled, compare, useIsoLayoutEffect, useMergedRef } from "./internal.js";
|
|
5
|
+
import { Icon } from "./Icon.js";
|
|
6
|
+
import { IconButton } from "./IconButton.js";
|
|
7
|
+
import { Checkbox } from "./Checkbox.js";
|
|
8
|
+
import { Menu } from "./Menu.js";
|
|
9
|
+
import { StatusPill, toneFor, TONE_ORDER } from "./StatusPill.js";
|
|
10
|
+
const h = React.createElement;
|
|
11
|
+
var BP = { sm: 640, md: 768, lg: 1024, xl: 1280 };
|
|
12
|
+
var DEFAULT_COLUMNS = [
|
|
13
|
+
{ key: "id", label: "ID", width: 96, mono: true },
|
|
14
|
+
{ key: "name", label: "NAME", width: 160 },
|
|
15
|
+
{ key: "status", label: "STATUS", width: 112, pill: true },
|
|
16
|
+
{ key: "owner", label: "OWNER" }
|
|
17
|
+
];
|
|
18
|
+
var SKELETON_WIDTHS = ["72%", "56%", "84%", "44%", "64%"];
|
|
19
|
+
var ROW_H = 48, OVERSCAN = 8, FLEX_MIN = 160;
|
|
20
|
+
const DataTable = React.forwardRef(function DataTable2(props, ref) {
|
|
21
|
+
var t = useStrings();
|
|
22
|
+
var columns = props.columns || DEFAULT_COLUMNS;
|
|
23
|
+
var byKey = {};
|
|
24
|
+
columns.forEach(function(c) {
|
|
25
|
+
byKey[c.key] = c;
|
|
26
|
+
});
|
|
27
|
+
var rows = props.rows || [];
|
|
28
|
+
var rowKey = props.rowKey || columns[0].key;
|
|
29
|
+
var loading = !!props.loading;
|
|
30
|
+
var selectable = !!props.selectable;
|
|
31
|
+
var reorderable = props.reorderable !== false && !!props.columnControls;
|
|
32
|
+
var controls = !!props.columnControls;
|
|
33
|
+
var sortState = useMaybeControlled(props.sort, props.defaultSort || null, props.onSortChange);
|
|
34
|
+
var sort = sortState[0], setSort = sortState[1];
|
|
35
|
+
var selState = useMaybeControlled(props.selected, props.defaultSelected || [], props.onSelectionChange);
|
|
36
|
+
var selected = selState[0], setSelected = selState[1];
|
|
37
|
+
var pageState = useMaybeControlled(props.page, props.defaultPage || 1, props.onPageChange);
|
|
38
|
+
var orderState = useMaybeControlled(props.columnOrder, columns.map(function(c) {
|
|
39
|
+
return c.key;
|
|
40
|
+
}), props.onColumnOrderChange);
|
|
41
|
+
var hiddenState = useMaybeControlled(props.hiddenColumns, columns.filter(function(c) {
|
|
42
|
+
return c.hidden;
|
|
43
|
+
}).map(function(c) {
|
|
44
|
+
return c.key;
|
|
45
|
+
}), props.onHiddenColumnsChange);
|
|
46
|
+
var pinState = useMaybeControlled(props.pinnedColumns, columns.filter(function(c) {
|
|
47
|
+
return c.pinned;
|
|
48
|
+
}).map(function(c) {
|
|
49
|
+
return c.key;
|
|
50
|
+
}), props.onPinnedColumnsChange);
|
|
51
|
+
var widthState = React.useState({});
|
|
52
|
+
var widths = widthState[0], setWidths = widthState[1];
|
|
53
|
+
var activeState = React.useState({ r: 1, c: 0 });
|
|
54
|
+
var scrollState = React.useState(0);
|
|
55
|
+
var scrollTop = scrollState[0], setScrollTop = scrollState[1];
|
|
56
|
+
var scrolledX = React.useState(false);
|
|
57
|
+
var menuState = React.useState(null);
|
|
58
|
+
var menu = menuState[0], setMenu = menuState[1];
|
|
59
|
+
var dragState = React.useState(null);
|
|
60
|
+
var drag = dragState[0], setDrag = dragState[1];
|
|
61
|
+
var gridRef = React.useRef(null);
|
|
62
|
+
var wrapRef = React.useRef(null), wrapMerged = useMergedRef(ref, wrapRef);
|
|
63
|
+
var boxWidth = React.useState(null);
|
|
64
|
+
var measure = !!props.stackBelow || columns.some(function(c) {
|
|
65
|
+
return c.hideBelow != null;
|
|
66
|
+
});
|
|
67
|
+
React.useEffect(function() {
|
|
68
|
+
if (!measure || !wrapRef.current || typeof ResizeObserver === "undefined") return;
|
|
69
|
+
var ro = new ResizeObserver(function(en) {
|
|
70
|
+
boxWidth[1](en[0].contentRect.width);
|
|
71
|
+
});
|
|
72
|
+
ro.observe(wrapRef.current);
|
|
73
|
+
return function() {
|
|
74
|
+
ro.disconnect();
|
|
75
|
+
};
|
|
76
|
+
}, [measure]);
|
|
77
|
+
var stacked = !!props.stackBelow && boxWidth[0] != null && boxWidth[0] < props.stackBelow;
|
|
78
|
+
function tooNarrow(c) {
|
|
79
|
+
if (c.hideBelow == null || boxWidth[0] == null || stacked) return false;
|
|
80
|
+
var px = typeof c.hideBelow === "number" ? c.hideBelow : BP[c.hideBelow];
|
|
81
|
+
return px != null && boxWidth[0] < px;
|
|
82
|
+
}
|
|
83
|
+
var scrollRef = React.useRef(null);
|
|
84
|
+
var pending = React.useRef(null);
|
|
85
|
+
var resizing = React.useRef(false);
|
|
86
|
+
useIsoLayoutEffect(function() {
|
|
87
|
+
if (stacked || !gridRef.current) return;
|
|
88
|
+
var els = gridRef.current.querySelectorAll('.aura-table__td button, .aura-table__td a[href], .aura-table__td input, .aura-table__td select, .aura-table__td textarea, .aura-table__td [tabindex="0"]');
|
|
89
|
+
for (var i2 = 0; i2 < els.length; i2++) if (els[i2].tabIndex !== -1) els[i2].tabIndex = -1;
|
|
90
|
+
});
|
|
91
|
+
function widthOf(c) {
|
|
92
|
+
return widths[c.key] != null ? widths[c.key] : c.width;
|
|
93
|
+
}
|
|
94
|
+
var order = orderState[0].filter(function(k) {
|
|
95
|
+
return byKey[k];
|
|
96
|
+
});
|
|
97
|
+
columns.forEach(function(c) {
|
|
98
|
+
if (order.indexOf(c.key) < 0) order.push(c.key);
|
|
99
|
+
});
|
|
100
|
+
var hidden = hiddenState[0], pinnedKeys = pinState[0];
|
|
101
|
+
var shown = order.filter(function(k) {
|
|
102
|
+
return hidden.indexOf(k) < 0;
|
|
103
|
+
}).map(function(k) {
|
|
104
|
+
return byKey[k];
|
|
105
|
+
}).filter(function(c) {
|
|
106
|
+
return !tooNarrow(c);
|
|
107
|
+
});
|
|
108
|
+
function isPinned(c) {
|
|
109
|
+
return pinnedKeys.indexOf(c.key) >= 0 && c.width != null;
|
|
110
|
+
}
|
|
111
|
+
var vis = shown.filter(isPinned).concat(shown.filter(function(c) {
|
|
112
|
+
return !isPinned(c);
|
|
113
|
+
}));
|
|
114
|
+
var nPinned = vis.filter(isPinned).length;
|
|
115
|
+
var hasFlex = vis.some(function(c) {
|
|
116
|
+
return widthOf(c) == null;
|
|
117
|
+
});
|
|
118
|
+
var fixedSum = 0;
|
|
119
|
+
vis.forEach(function(c) {
|
|
120
|
+
fixedSum += widthOf(c) != null ? widthOf(c) : FLEX_MIN;
|
|
121
|
+
});
|
|
122
|
+
var pinOffsets = {}, acc = 0;
|
|
123
|
+
vis.forEach(function(c) {
|
|
124
|
+
if (isPinned(c)) {
|
|
125
|
+
pinOffsets[c.key] = acc;
|
|
126
|
+
acc += widthOf(c);
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
var selW = selectable ? " + var(--aura-table-select-width)" : "";
|
|
130
|
+
var gutterR = controls ? "var(--aura-space-12)" : "var(--aura-space-6)";
|
|
131
|
+
var rowMinWidth = "calc(" + fixedSum + "px + var(--aura-space-6) + " + gutterR + selW + ")";
|
|
132
|
+
function cellStyle(c, i2) {
|
|
133
|
+
var w = widthOf(c), s;
|
|
134
|
+
if (w == null) s = { flex: "1 1 0", minWidth: (c.minWidth || FLEX_MIN) + "px" };
|
|
135
|
+
else if (!hasFlex && i2 === vis.length - 1) s = { flex: "1 0 auto", width: w + "px" };
|
|
136
|
+
else s = { width: w + "px", flex: "none" };
|
|
137
|
+
if (isPinned(c)) s.left = "calc(var(--aura-space-6)" + selW + " + " + pinOffsets[c.key] + "px)";
|
|
138
|
+
return s;
|
|
139
|
+
}
|
|
140
|
+
var view = React.useMemo(function() {
|
|
141
|
+
if (!sort || !sort.key || !byKey[sort.key]) return rows;
|
|
142
|
+
var col = byKey[sort.key];
|
|
143
|
+
var val = col.sortValue || (col.pill ? function(r) {
|
|
144
|
+
return TONE_ORDER[col.tones && col.tones[r[col.key]] || toneFor(r[col.key])];
|
|
145
|
+
} : function(r) {
|
|
146
|
+
return r[col.key];
|
|
147
|
+
});
|
|
148
|
+
var dir = sort.dir === "desc" ? -1 : 1;
|
|
149
|
+
return rows.map(function(r, i2) {
|
|
150
|
+
return [r, i2];
|
|
151
|
+
}).sort(function(a, b) {
|
|
152
|
+
return compare(val(a[0]), val(b[0])) * dir || a[1] - b[1];
|
|
153
|
+
}).map(function(p) {
|
|
154
|
+
return p[0];
|
|
155
|
+
});
|
|
156
|
+
}, [rows, sort && sort.key, sort && sort.dir]);
|
|
157
|
+
function nextSort(key) {
|
|
158
|
+
if (!sort || sort.key !== key) return { key, dir: "asc" };
|
|
159
|
+
if (sort.dir === "asc") return { key, dir: "desc" };
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
var pageSize = props.pageSize || 0;
|
|
163
|
+
var pageCount = pageSize ? Math.max(1, Math.ceil(view.length / pageSize)) : 1;
|
|
164
|
+
var page = Math.min(Math.max(1, pageState[0] || 1), pageCount);
|
|
165
|
+
var first = pageSize ? (page - 1) * pageSize : 0;
|
|
166
|
+
var pageRows = pageSize ? view.slice(first, first + pageSize) : view;
|
|
167
|
+
function goPage(p, focus) {
|
|
168
|
+
var next = Math.min(Math.max(1, p), pageCount);
|
|
169
|
+
if (next === page) return false;
|
|
170
|
+
if (focus) pending.current = focus;
|
|
171
|
+
pageState[1](next);
|
|
172
|
+
if (scrollRef.current) scrollRef.current.scrollTop = 0;
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
var height = props.height || 0;
|
|
176
|
+
var virtual = !!height && !loading && pageRows.length > 0;
|
|
177
|
+
var bodyH = Math.max(ROW_H, height - ROW_H);
|
|
178
|
+
var start = 0, end = pageRows.length;
|
|
179
|
+
if (virtual) {
|
|
180
|
+
start = Math.max(0, Math.floor(scrollTop / ROW_H) - OVERSCAN);
|
|
181
|
+
end = Math.min(pageRows.length, Math.ceil((scrollTop + bodyH) / ROW_H) + OVERSCAN);
|
|
182
|
+
}
|
|
183
|
+
var visibleRows = Math.max(1, Math.floor(bodyH / ROW_H));
|
|
184
|
+
var nCols = vis.length + (selectable ? 1 : 0);
|
|
185
|
+
var nRows = loading ? 0 : pageRows.length;
|
|
186
|
+
var active = activeState[0];
|
|
187
|
+
var ar = Math.min(active.r, nRows), ac = Math.min(active.c, nCols - 1);
|
|
188
|
+
var activeRendered = ar === 0 || ar - 1 >= start && ar - 1 < end;
|
|
189
|
+
function colAt(ci) {
|
|
190
|
+
return selectable ? ci === 0 ? null : vis[ci - 1] : vis[ci];
|
|
191
|
+
}
|
|
192
|
+
function tabFor(r, c) {
|
|
193
|
+
if (!activeRendered) return r === 0 && c === ac ? 0 : -1;
|
|
194
|
+
return r === ar && c === ac ? 0 : -1;
|
|
195
|
+
}
|
|
196
|
+
React.useEffect(function() {
|
|
197
|
+
var p = pending.current;
|
|
198
|
+
if (!p || !gridRef.current) return;
|
|
199
|
+
var c = p.c;
|
|
200
|
+
if (p.key) {
|
|
201
|
+
var at = -1;
|
|
202
|
+
vis.forEach(function(x, i2) {
|
|
203
|
+
if (x.key === p.key) at = i2;
|
|
204
|
+
});
|
|
205
|
+
c = at >= 0 ? at + (selectable ? 1 : 0) : Math.min(p.c || 0, nCols - 1);
|
|
206
|
+
}
|
|
207
|
+
var el = gridRef.current.querySelector('[data-rc="' + p.r + ":" + c + '"]');
|
|
208
|
+
if (el) {
|
|
209
|
+
pending.current = null;
|
|
210
|
+
el.focus();
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
function focusCell(r, c) {
|
|
214
|
+
r = Math.max(0, Math.min(r, nRows));
|
|
215
|
+
c = Math.max(0, Math.min(c, nCols - 1));
|
|
216
|
+
activeState[1]({ r, c });
|
|
217
|
+
pending.current = { r, c };
|
|
218
|
+
if (virtual && r > 0) {
|
|
219
|
+
var sc = scrollRef.current, top = (r - 1) * ROW_H;
|
|
220
|
+
if (top < sc.scrollTop) sc.scrollTop = top;
|
|
221
|
+
else if (top + ROW_H > sc.scrollTop + bodyH) sc.scrollTop = top + ROW_H - bodyH;
|
|
222
|
+
setScrollTop(sc.scrollTop);
|
|
223
|
+
}
|
|
224
|
+
var el = gridRef.current && gridRef.current.querySelector('[data-rc="' + r + ":" + c + '"]');
|
|
225
|
+
if (el) {
|
|
226
|
+
pending.current = null;
|
|
227
|
+
el.focus();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
var pageKeys = pageRows.map(function(r) {
|
|
231
|
+
return r[rowKey];
|
|
232
|
+
});
|
|
233
|
+
var selSet = {};
|
|
234
|
+
selected.forEach(function(k) {
|
|
235
|
+
selSet[k] = true;
|
|
236
|
+
});
|
|
237
|
+
var nSel = pageKeys.filter(function(k) {
|
|
238
|
+
return selSet[k];
|
|
239
|
+
}).length;
|
|
240
|
+
var all = nSel > 0 && nSel === pageKeys.length;
|
|
241
|
+
function toggle(k, on) {
|
|
242
|
+
setSelected(on ? selected.concat([k]) : selected.filter(function(x) {
|
|
243
|
+
return x !== k;
|
|
244
|
+
}));
|
|
245
|
+
}
|
|
246
|
+
function toggleAll() {
|
|
247
|
+
setSelected(all ? selected.filter(function(k) {
|
|
248
|
+
return pageKeys.indexOf(k) < 0;
|
|
249
|
+
}) : selected.concat(pageKeys.filter(function(k) {
|
|
250
|
+
return !selSet[k];
|
|
251
|
+
})));
|
|
252
|
+
}
|
|
253
|
+
function canResize(c) {
|
|
254
|
+
return props.resizable && c.resizable !== false && c.width != null;
|
|
255
|
+
}
|
|
256
|
+
function clampW(c, w) {
|
|
257
|
+
return Math.round(Math.min(c.maxWidth || 480, Math.max(c.minWidth || 64, w)));
|
|
258
|
+
}
|
|
259
|
+
function setW(c, w, done) {
|
|
260
|
+
var nw = clampW(c, w);
|
|
261
|
+
setWidths(function(prev) {
|
|
262
|
+
var o = Object.assign({}, prev);
|
|
263
|
+
o[c.key] = nw;
|
|
264
|
+
return o;
|
|
265
|
+
});
|
|
266
|
+
if (done && props.onColumnResize) props.onColumnResize(c.key, nw);
|
|
267
|
+
}
|
|
268
|
+
function startResize(c, e) {
|
|
269
|
+
e.preventDefault();
|
|
270
|
+
e.stopPropagation();
|
|
271
|
+
resizing.current = true;
|
|
272
|
+
var x0 = e.clientX, w0 = widthOf(c), last = w0;
|
|
273
|
+
var el = e.currentTarget;
|
|
274
|
+
el.classList.add("is-dragging");
|
|
275
|
+
document.body.style.cursor = "col-resize";
|
|
276
|
+
function move(ev) {
|
|
277
|
+
last = clampW(c, w0 + ev.clientX - x0);
|
|
278
|
+
setW(c, last);
|
|
279
|
+
}
|
|
280
|
+
function up() {
|
|
281
|
+
window.removeEventListener("pointermove", move);
|
|
282
|
+
window.removeEventListener("pointerup", up);
|
|
283
|
+
el.classList.remove("is-dragging");
|
|
284
|
+
document.body.style.cursor = "";
|
|
285
|
+
setTimeout(function() {
|
|
286
|
+
resizing.current = false;
|
|
287
|
+
}, 0);
|
|
288
|
+
if (props.onColumnResize) props.onColumnResize(c.key, last);
|
|
289
|
+
}
|
|
290
|
+
window.addEventListener("pointermove", move);
|
|
291
|
+
window.addEventListener("pointerup", up);
|
|
292
|
+
}
|
|
293
|
+
function moveCol(key, delta) {
|
|
294
|
+
var c = byKey[key], group = vis.filter(function(x) {
|
|
295
|
+
return isPinned(x) === isPinned(c);
|
|
296
|
+
});
|
|
297
|
+
var gi = group.indexOf(c), target = group[gi + delta];
|
|
298
|
+
if (!target) return false;
|
|
299
|
+
var o = order.slice(), from2 = o.indexOf(key), to2 = o.indexOf(target.key);
|
|
300
|
+
o.splice(from2, 1);
|
|
301
|
+
o.splice(to2, 0, key);
|
|
302
|
+
orderState[1](o);
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
function dropCol(key, targetKey, after) {
|
|
306
|
+
if (key === targetKey) return;
|
|
307
|
+
var a = byKey[key], b = byKey[targetKey];
|
|
308
|
+
if (isPinned(a) !== isPinned(b)) return;
|
|
309
|
+
var o = order.slice();
|
|
310
|
+
o.splice(o.indexOf(key), 1);
|
|
311
|
+
var to2 = o.indexOf(targetKey) + (after ? 1 : 0);
|
|
312
|
+
o.splice(to2, 0, key);
|
|
313
|
+
orderState[1](o);
|
|
314
|
+
}
|
|
315
|
+
function togglePin(key) {
|
|
316
|
+
pinState[1](pinnedKeys.indexOf(key) >= 0 ? pinnedKeys.filter(function(k) {
|
|
317
|
+
return k !== key;
|
|
318
|
+
}) : pinnedKeys.concat([key]));
|
|
319
|
+
}
|
|
320
|
+
function setHidden(key, hide) {
|
|
321
|
+
if (hide && shown.length <= 1) return;
|
|
322
|
+
hiddenState[1](hide ? hidden.concat([key]) : hidden.filter(function(k) {
|
|
323
|
+
return k !== key;
|
|
324
|
+
}));
|
|
325
|
+
}
|
|
326
|
+
function resetColumns() {
|
|
327
|
+
orderState[1](columns.map(function(c) {
|
|
328
|
+
return c.key;
|
|
329
|
+
}));
|
|
330
|
+
hiddenState[1](columns.filter(function(c) {
|
|
331
|
+
return c.hidden;
|
|
332
|
+
}).map(function(c) {
|
|
333
|
+
return c.key;
|
|
334
|
+
}));
|
|
335
|
+
pinState[1](columns.filter(function(c) {
|
|
336
|
+
return c.pinned;
|
|
337
|
+
}).map(function(c) {
|
|
338
|
+
return c.key;
|
|
339
|
+
}));
|
|
340
|
+
setWidths({});
|
|
341
|
+
}
|
|
342
|
+
function columnMenuItems(c) {
|
|
343
|
+
var group = vis.filter(function(x) {
|
|
344
|
+
return isPinned(x) === isPinned(c);
|
|
345
|
+
}), gi = group.indexOf(c);
|
|
346
|
+
var items = [];
|
|
347
|
+
if (c.sortable) items.push(
|
|
348
|
+
{ label: t.sortAsc, icon: "arrow-up", onSelect: function() {
|
|
349
|
+
setSort({ key: c.key, dir: "asc" });
|
|
350
|
+
goPage(1);
|
|
351
|
+
} },
|
|
352
|
+
{ label: t.sortDesc, icon: "arrow-down", onSelect: function() {
|
|
353
|
+
setSort({ key: c.key, dir: "desc" });
|
|
354
|
+
goPage(1);
|
|
355
|
+
} },
|
|
356
|
+
{ separator: true }
|
|
357
|
+
);
|
|
358
|
+
if (c.width != null) items.push({ label: isPinned(c) ? t.unpin : t.pin, icon: isPinned(c) ? "pin-off" : "pin", onSelect: function() {
|
|
359
|
+
togglePin(c.key);
|
|
360
|
+
} });
|
|
361
|
+
if (reorderable) items.push(
|
|
362
|
+
{ label: t.moveLeft, icon: "arrow-left", disabled: gi <= 0, onSelect: function() {
|
|
363
|
+
moveCol(c.key, -1);
|
|
364
|
+
} },
|
|
365
|
+
{ label: t.moveRight, icon: "arrow-right", disabled: gi >= group.length - 1, onSelect: function() {
|
|
366
|
+
moveCol(c.key, 1);
|
|
367
|
+
} }
|
|
368
|
+
);
|
|
369
|
+
items.push({ separator: true }, { label: t.hideColumn, icon: "eye-off", disabled: shown.length <= 1, onSelect: function() {
|
|
370
|
+
setHidden(c.key, true);
|
|
371
|
+
} });
|
|
372
|
+
return items;
|
|
373
|
+
}
|
|
374
|
+
function pickerItems() {
|
|
375
|
+
return order.map(function(k) {
|
|
376
|
+
var c = byKey[k], on = hidden.indexOf(k) < 0;
|
|
377
|
+
return { label: c.label || (c.actions ? t.actions : c.key), checked: on, keepOpen: true, disabled: on && shown.length <= 1, onSelect: function() {
|
|
378
|
+
setHidden(k, on);
|
|
379
|
+
} };
|
|
380
|
+
}).concat([{ separator: true }, { label: t.resetColumns, icon: "rotate-ccw", onSelect: resetColumns }]);
|
|
381
|
+
}
|
|
382
|
+
function openMenu(kind, key, anchor, rc) {
|
|
383
|
+
setMenu({ kind, key, anchor, rc });
|
|
384
|
+
}
|
|
385
|
+
function closeMenu(restore) {
|
|
386
|
+
var m = menu;
|
|
387
|
+
setMenu(null);
|
|
388
|
+
if (restore && m) {
|
|
389
|
+
if (m.kind === "col") pending.current = { r: 0, key: m.key, c: m.rc ? m.rc.c : 0 };
|
|
390
|
+
else if (m.anchor) m.anchor.focus();
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
function onGridKey(e) {
|
|
394
|
+
if (!gridRef.current || !gridRef.current.contains(e.target)) return;
|
|
395
|
+
var rc = e.target.getAttribute && e.target.getAttribute("data-rc");
|
|
396
|
+
if (!rc) {
|
|
397
|
+
var cell = e.key === "Escape" && e.target.closest && e.target.closest("[data-rc]");
|
|
398
|
+
if (cell) {
|
|
399
|
+
e.preventDefault();
|
|
400
|
+
cell.focus();
|
|
401
|
+
}
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
var p = rc.split(":"), r = +p[0], c = +p[1], k = e.key, col = colAt(c);
|
|
405
|
+
var row = r > 0 ? pageRows[r - 1] : null;
|
|
406
|
+
var handled = true;
|
|
407
|
+
if (r === 0 && col && e.altKey && (k === "ArrowLeft" || k === "ArrowRight") && canResize(col)) setW(col, widthOf(col) + (k === "ArrowLeft" ? -1 : 1) * (e.shiftKey ? 48 : 16), true);
|
|
408
|
+
else if (r === 0 && col && e.ctrlKey && e.shiftKey && (k === "ArrowLeft" || k === "ArrowRight") && reorderable) {
|
|
409
|
+
if (moveCol(col.key, k === "ArrowLeft" ? -1 : 1)) pending.current = { r: 0, key: col.key, c };
|
|
410
|
+
} else if (r === 0 && col && (e.altKey && k === "ArrowDown" || k === "ContextMenu" || e.shiftKey && k === "F10") && controls) openMenu("col", col.key, e.target, { r: 0, c });
|
|
411
|
+
else if (k === "ArrowRight") focusCell(r, c + 1);
|
|
412
|
+
else if (k === "ArrowLeft") focusCell(r, c - 1);
|
|
413
|
+
else if (k === "ArrowDown") {
|
|
414
|
+
if (r < nRows) focusCell(r + 1, c);
|
|
415
|
+
else if (pageSize && page < pageCount && goPage(page + 1, { r: 1, c })) activeState[1]({ r: 1, c });
|
|
416
|
+
} else if (k === "ArrowUp") {
|
|
417
|
+
if (r > 1 || r === 1 && !(pageSize && page > 1)) focusCell(r - 1, c);
|
|
418
|
+
else if (r === 1 && goPage(page - 1, { r: pageSize, c })) activeState[1]({ r: pageSize, c });
|
|
419
|
+
} else if (k === "Home") focusCell(e.ctrlKey ? 1 : r, 0);
|
|
420
|
+
else if (k === "End") focusCell(e.ctrlKey ? nRows : r, nCols - 1);
|
|
421
|
+
else if (k === "PageDown") {
|
|
422
|
+
if (pageSize) {
|
|
423
|
+
if (goPage(page + 1, { r: 1, c })) activeState[1]({ r: 1, c });
|
|
424
|
+
} else focusCell(Math.min(nRows, r + visibleRows), c);
|
|
425
|
+
} else if (k === "PageUp") {
|
|
426
|
+
if (pageSize) {
|
|
427
|
+
if (goPage(page - 1, { r: 1, c })) activeState[1]({ r: 1, c });
|
|
428
|
+
} else focusCell(Math.max(1, r - visibleRows), c);
|
|
429
|
+
} else if (k === " " || k === "Enter") {
|
|
430
|
+
if (r === 0 && !col && selectable && nRows) toggleAll();
|
|
431
|
+
else if (r === 0 && col && col.sortable && nRows > 1) {
|
|
432
|
+
setSort(nextSort(col.key));
|
|
433
|
+
goPage(1);
|
|
434
|
+
} else if (r > 0 && k === " " && selectable) toggle(row[rowKey], !selSet[row[rowKey]]);
|
|
435
|
+
else if (r > 0 && (k === "Enter" || k === "F2") && e.target.querySelector("button, a[href], input, select, textarea")) e.target.querySelector("button, a[href], input, select, textarea").focus();
|
|
436
|
+
else if (r > 0 && k === "Enter" && props.onRowActivate) props.onRowActivate(row);
|
|
437
|
+
else handled = false;
|
|
438
|
+
} else handled = false;
|
|
439
|
+
if (handled) {
|
|
440
|
+
e.preventDefault();
|
|
441
|
+
e.stopPropagation();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
var head = [h("span", { key: "__gl", className: "aura-table__gutter", "aria-hidden": true })];
|
|
445
|
+
if (selectable) head.push(h("span", {
|
|
446
|
+
key: "__sel",
|
|
447
|
+
role: "columnheader",
|
|
448
|
+
"aria-colindex": 1,
|
|
449
|
+
className: cx("aura-table__sel", nPinned && "is-pinned"),
|
|
450
|
+
tabIndex: tabFor(0, 0),
|
|
451
|
+
"data-rc": "0:0",
|
|
452
|
+
"aria-label": t.selectRows,
|
|
453
|
+
onFocus: function() {
|
|
454
|
+
activeState[1]({ r: 0, c: 0 });
|
|
455
|
+
}
|
|
456
|
+
}, nRows ? h(Checkbox, {
|
|
457
|
+
checked: all,
|
|
458
|
+
indeterminate: nSel > 0 && !all,
|
|
459
|
+
tabIndex: -1,
|
|
460
|
+
label: all ? t.deselectAllRows : t.selectAllRows,
|
|
461
|
+
onChange: toggleAll
|
|
462
|
+
}) : null));
|
|
463
|
+
vis.forEach(function(c, i2) {
|
|
464
|
+
var ci = i2 + (selectable ? 1 : 0);
|
|
465
|
+
var isSorted = sort && sort.key === c.key;
|
|
466
|
+
var canSort = c.sortable && rows.length > 1 && !loading;
|
|
467
|
+
var ariaSort = isSorted && canSort ? sort.dir === "desc" ? "descending" : "ascending" : canSort ? "none" : void 0;
|
|
468
|
+
var pin = isPinned(c), edge = pin && i2 === nPinned - 1;
|
|
469
|
+
head.push(h(
|
|
470
|
+
"span",
|
|
471
|
+
{
|
|
472
|
+
key: c.key,
|
|
473
|
+
role: "columnheader",
|
|
474
|
+
"aria-sort": ariaSort,
|
|
475
|
+
"aria-colindex": ci + 1,
|
|
476
|
+
style: cellStyle(c, i2),
|
|
477
|
+
tabIndex: tabFor(0, ci),
|
|
478
|
+
"data-rc": "0:" + ci,
|
|
479
|
+
className: cx(
|
|
480
|
+
"aura-table__th",
|
|
481
|
+
pin && "is-pinned",
|
|
482
|
+
edge && "is-pin-edge",
|
|
483
|
+
drag && drag.over === c.key && (drag.after ? "is-drop-after" : "is-drop-before"),
|
|
484
|
+
drag && drag.key === c.key && "is-dragging"
|
|
485
|
+
),
|
|
486
|
+
draggable: reorderable && !loading ? true : void 0,
|
|
487
|
+
onFocus: function(e) {
|
|
488
|
+
if (e.target === e.currentTarget) activeState[1]({ r: 0, c: ci });
|
|
489
|
+
},
|
|
490
|
+
onDragStart: function(e) {
|
|
491
|
+
if (resizing.current) {
|
|
492
|
+
e.preventDefault();
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
e.dataTransfer.effectAllowed = "move";
|
|
496
|
+
try {
|
|
497
|
+
e.dataTransfer.setData("text/plain", c.key);
|
|
498
|
+
} catch (x) {
|
|
499
|
+
}
|
|
500
|
+
setDrag({ key: c.key });
|
|
501
|
+
},
|
|
502
|
+
onDragOver: function(e) {
|
|
503
|
+
if (!drag || drag.key === c.key || isPinned(byKey[drag.key]) !== pin) return;
|
|
504
|
+
e.preventDefault();
|
|
505
|
+
var b = e.currentTarget.getBoundingClientRect(), after = e.clientX > b.left + b.width / 2;
|
|
506
|
+
if (drag.over !== c.key || drag.after !== after) setDrag({ key: drag.key, over: c.key, after });
|
|
507
|
+
},
|
|
508
|
+
onDrop: function(e) {
|
|
509
|
+
e.preventDefault();
|
|
510
|
+
if (drag && drag.over) dropCol(drag.key, drag.over, drag.after);
|
|
511
|
+
setDrag(null);
|
|
512
|
+
},
|
|
513
|
+
onDragEnd: function() {
|
|
514
|
+
setDrag(null);
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
h(
|
|
518
|
+
"span",
|
|
519
|
+
{ className: "aura-table__th-inner" },
|
|
520
|
+
canSort ? h(
|
|
521
|
+
"button",
|
|
522
|
+
{
|
|
523
|
+
type: "button",
|
|
524
|
+
tabIndex: -1,
|
|
525
|
+
className: cx("aura-table__sort", isSorted && "is-active"),
|
|
526
|
+
onClick: function() {
|
|
527
|
+
setSort(nextSort(c.key));
|
|
528
|
+
goPage(1);
|
|
529
|
+
activeState[1]({ r: 0, c: ci });
|
|
530
|
+
}
|
|
531
|
+
},
|
|
532
|
+
c.label,
|
|
533
|
+
h(Icon, { name: isSorted ? sort.dir === "desc" ? "arrow-down" : "arrow-up" : "arrow-up-down", size: 12 })
|
|
534
|
+
) : h("span", { className: cx("aura-table__th-label", !c.label && "aura-sr-only") }, c.label || (c.actions ? t.actions : c.key)),
|
|
535
|
+
pin ? h(Icon, { name: "pin", size: 12, className: "aura-table__pin-icon", label: t.pinned }) : null,
|
|
536
|
+
controls ? h(
|
|
537
|
+
"button",
|
|
538
|
+
{
|
|
539
|
+
type: "button",
|
|
540
|
+
tabIndex: -1,
|
|
541
|
+
className: "aura-table__menu-btn",
|
|
542
|
+
"aria-label": t.columnOptions(c.label),
|
|
543
|
+
"aria-haspopup": "menu",
|
|
544
|
+
"aria-expanded": menu && menu.key === c.key ? true : void 0,
|
|
545
|
+
onClick: function(e) {
|
|
546
|
+
e.stopPropagation();
|
|
547
|
+
openMenu("col", c.key, e.currentTarget, { r: 0, c: ci });
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
h(Icon, { name: "ellipsis" })
|
|
551
|
+
) : null
|
|
552
|
+
),
|
|
553
|
+
canResize(c) ? h("span", {
|
|
554
|
+
className: "aura-table__resize",
|
|
555
|
+
role: "separator",
|
|
556
|
+
"aria-orientation": "vertical",
|
|
557
|
+
"aria-hidden": true,
|
|
558
|
+
onPointerDown: function(e) {
|
|
559
|
+
startResize(c, e);
|
|
560
|
+
},
|
|
561
|
+
onClick: function(e) {
|
|
562
|
+
e.stopPropagation();
|
|
563
|
+
},
|
|
564
|
+
onDoubleClick: function() {
|
|
565
|
+
setW(c, c.width, true);
|
|
566
|
+
}
|
|
567
|
+
}) : null
|
|
568
|
+
));
|
|
569
|
+
});
|
|
570
|
+
head.push(h("span", { key: "__gr", className: cx("aura-table__gutter aura-table__gutter--end", controls && "has-picker"), "aria-hidden": true }));
|
|
571
|
+
function rowCells(r, i2, k, isSel) {
|
|
572
|
+
var ri2 = i2 + 1;
|
|
573
|
+
var cells = [h("span", { key: "__gl", className: "aura-table__gutter", "aria-hidden": true })];
|
|
574
|
+
if (selectable) cells.push(h("span", {
|
|
575
|
+
key: "__sel",
|
|
576
|
+
role: "gridcell",
|
|
577
|
+
"aria-colindex": 1,
|
|
578
|
+
className: cx("aura-table__sel", nPinned && "is-pinned"),
|
|
579
|
+
tabIndex: tabFor(ri2, 0),
|
|
580
|
+
"data-rc": ri2 + ":0",
|
|
581
|
+
"aria-label": t.selectRow(k),
|
|
582
|
+
onFocus: function(e) {
|
|
583
|
+
if (e.target === e.currentTarget) activeState[1]({ r: ri2, c: 0 });
|
|
584
|
+
}
|
|
585
|
+
}, h(Checkbox, { checked: isSel, tabIndex: -1, label: t.selectRow(k), onChange: function(on) {
|
|
586
|
+
toggle(k, on);
|
|
587
|
+
} })));
|
|
588
|
+
vis.forEach(function(c, j) {
|
|
589
|
+
var ci = j + (selectable ? 1 : 0), v = r[c.key], pin = isPinned(c);
|
|
590
|
+
cells.push(h("span", {
|
|
591
|
+
key: c.key,
|
|
592
|
+
role: "gridcell",
|
|
593
|
+
"aria-colindex": ci + 1,
|
|
594
|
+
tabIndex: tabFor(ri2, ci),
|
|
595
|
+
"data-rc": ri2 + ":" + ci,
|
|
596
|
+
className: cx("aura-table__td", c.mono && "aura-table__mono", pin && "is-pinned", pin && j === nPinned - 1 && "is-pin-edge"),
|
|
597
|
+
style: cellStyle(c, j),
|
|
598
|
+
onFocus: function() {
|
|
599
|
+
if (activeState[0].r !== ri2 || activeState[0].c !== ci) activeState[1]({ r: ri2, c: ci });
|
|
600
|
+
}
|
|
601
|
+
}, c.render ? c.render(r) : c.pill ? h(StatusPill, { tone: c.tones && c.tones[v] }, v) : v));
|
|
602
|
+
});
|
|
603
|
+
cells.push(h("span", { key: "__gr", className: cx("aura-table__gutter aura-table__gutter--end", controls && "has-picker"), "aria-hidden": true }));
|
|
604
|
+
return cells;
|
|
605
|
+
}
|
|
606
|
+
var body;
|
|
607
|
+
var rowStyle = { minWidth: rowMinWidth };
|
|
608
|
+
if (loading) {
|
|
609
|
+
var n = pageSize || props.skeletonRows || 5;
|
|
610
|
+
body = [];
|
|
611
|
+
for (var i = 0; i < n; i++) {
|
|
612
|
+
var sk = [h("span", { key: "__gl", className: "aura-table__gutter" })];
|
|
613
|
+
if (selectable) sk.push(h("span", { key: "__sel", className: cx("aura-table__sel", nPinned && "is-pinned") }, h("span", { className: "aura-skel aura-skel--box" })));
|
|
614
|
+
vis.forEach(function(c, j) {
|
|
615
|
+
sk.push(h(
|
|
616
|
+
"span",
|
|
617
|
+
{ key: c.key, className: cx("aura-table__td", isPinned(c) && "is-pinned"), style: cellStyle(c, j) },
|
|
618
|
+
h("span", { className: cx("aura-skel", c.pill && "aura-skel--pill"), style: c.pill ? null : { width: SKELETON_WIDTHS[(i + j) % SKELETON_WIDTHS.length] } })
|
|
619
|
+
));
|
|
620
|
+
});
|
|
621
|
+
sk.push(h("span", { key: "__gr", className: cx("aura-table__gutter aura-table__gutter--end", controls && "has-picker") }));
|
|
622
|
+
body.push(h("div", { key: "sk" + i, className: "aura-table__row aura-table__row--skeleton", "aria-hidden": true, style: rowStyle }, sk));
|
|
623
|
+
}
|
|
624
|
+
} else if (!rows.length) {
|
|
625
|
+
var em = props.empty || {};
|
|
626
|
+
body = h(
|
|
627
|
+
"div",
|
|
628
|
+
{ className: "aura-table__empty", role: "row" },
|
|
629
|
+
h(
|
|
630
|
+
"div",
|
|
631
|
+
{ role: "gridcell" },
|
|
632
|
+
h("span", { className: "aura-table__empty-icon" }, h(Icon, { name: em.icon || "inbox", size: "lg" })),
|
|
633
|
+
h("p", { className: "aura-table__empty-title" }, em.title || t.empty),
|
|
634
|
+
em.description ? h("p", { className: "aura-table__empty-text" }, em.description) : null,
|
|
635
|
+
em.action ? h("div", { className: "aura-table__empty-action" }, em.action) : null
|
|
636
|
+
)
|
|
637
|
+
);
|
|
638
|
+
} else {
|
|
639
|
+
body = [];
|
|
640
|
+
if (virtual && start > 0) body.push(h("div", { key: "__top", style: { height: start * ROW_H + "px" }, "aria-hidden": true }));
|
|
641
|
+
for (var ri = start; ri < end; ri++) {
|
|
642
|
+
(function(r, i2) {
|
|
643
|
+
var k = r[rowKey], isSel = !!selSet[k];
|
|
644
|
+
body.push(h("div", {
|
|
645
|
+
key: k,
|
|
646
|
+
role: "row",
|
|
647
|
+
"aria-rowindex": first + i2 + 2,
|
|
648
|
+
"aria-selected": selectable ? isSel : void 0,
|
|
649
|
+
className: cx("aura-table__row", isSel && "is-selected", props.onRowActivate && "is-actionable"),
|
|
650
|
+
style: rowStyle,
|
|
651
|
+
onClick: function(e) {
|
|
652
|
+
if (e.target.closest && e.target.closest(".aura-check, button, a, input")) return;
|
|
653
|
+
if (props.onRowActivate) props.onRowActivate(r);
|
|
654
|
+
}
|
|
655
|
+
}, rowCells(r, i2, k, isSel)));
|
|
656
|
+
})(pageRows[ri], ri);
|
|
657
|
+
}
|
|
658
|
+
if (virtual && end < pageRows.length) body.push(h("div", { key: "__bot", style: { height: (pageRows.length - end) * ROW_H + "px" }, "aria-hidden": true }));
|
|
659
|
+
}
|
|
660
|
+
var foot = null;
|
|
661
|
+
if (pageSize && (rows.length || loading)) {
|
|
662
|
+
var from = rows.length ? first + 1 : 0, to = Math.min(first + pageSize, view.length);
|
|
663
|
+
foot = h(
|
|
664
|
+
"div",
|
|
665
|
+
{ className: "aura-table__foot" },
|
|
666
|
+
h("span", { "aria-live": "polite" }, loading ? t.loading : t.range(from, to, view.length)),
|
|
667
|
+
h(
|
|
668
|
+
"span",
|
|
669
|
+
{ className: "aura-table__pager" },
|
|
670
|
+
h("span", null, t.page(page, pageCount)),
|
|
671
|
+
h(IconButton, { icon: "chevron-left", label: t.prevPage, disabled: loading || page <= 1, onClick: function() {
|
|
672
|
+
goPage(page - 1);
|
|
673
|
+
} }),
|
|
674
|
+
h(IconButton, { icon: "chevron-right", label: t.nextPage, disabled: loading || page >= pageCount, onClick: function() {
|
|
675
|
+
goPage(page + 1);
|
|
676
|
+
} })
|
|
677
|
+
)
|
|
678
|
+
);
|
|
679
|
+
} else if (height && rows.length && !loading) {
|
|
680
|
+
foot = h(
|
|
681
|
+
"div",
|
|
682
|
+
{ className: "aura-table__foot" },
|
|
683
|
+
h("span", null, t.rowCount(view.length)),
|
|
684
|
+
selectable && selected.length ? h("span", null, t.selectedCount(selected.length)) : h("span", null)
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
if (stacked) {
|
|
688
|
+
var titleCol = vis[0], pillCol = vis.filter(function(c) {
|
|
689
|
+
return c.pill && c !== titleCol;
|
|
690
|
+
})[0];
|
|
691
|
+
var actionCols = vis.filter(function(c) {
|
|
692
|
+
return c.actions && c !== titleCol;
|
|
693
|
+
});
|
|
694
|
+
var rest = vis.filter(function(c) {
|
|
695
|
+
return c !== titleCol && c !== pillCol && !c.actions;
|
|
696
|
+
});
|
|
697
|
+
var cardBody;
|
|
698
|
+
if (loading) {
|
|
699
|
+
cardBody = h("ul", { className: "aura-table__cards", "aria-busy": true }, [0, 1, 2].map(function(i2) {
|
|
700
|
+
return h(
|
|
701
|
+
"li",
|
|
702
|
+
{ key: i2, className: "aura-table__card", "aria-hidden": true },
|
|
703
|
+
h("span", { className: "aura-skel", style: { width: "50%", height: "14px" } }),
|
|
704
|
+
h("span", { className: "aura-skel", style: { width: "80%" } }),
|
|
705
|
+
h("span", { className: "aura-skel", style: { width: "64%" } })
|
|
706
|
+
);
|
|
707
|
+
}));
|
|
708
|
+
} else if (!rows.length) {
|
|
709
|
+
var em2 = props.empty || {};
|
|
710
|
+
cardBody = h("div", { className: "aura-table__empty" }, h(
|
|
711
|
+
"div",
|
|
712
|
+
null,
|
|
713
|
+
h("span", { className: "aura-table__empty-icon" }, h(Icon, { name: em2.icon || "inbox", size: "lg" })),
|
|
714
|
+
h("p", { className: "aura-table__empty-title" }, em2.title || t.empty),
|
|
715
|
+
em2.description ? h("p", { className: "aura-table__empty-text" }, em2.description) : null,
|
|
716
|
+
em2.action ? h("div", { className: "aura-table__empty-action" }, em2.action) : null
|
|
717
|
+
));
|
|
718
|
+
} else {
|
|
719
|
+
var cellVal = function(c, r) {
|
|
720
|
+
var v = r[c.key];
|
|
721
|
+
return c.render ? c.render(r) : c.pill ? h(StatusPill, { tone: c.tones && c.tones[v] }, v) : v;
|
|
722
|
+
};
|
|
723
|
+
cardBody = h("ul", { className: "aura-table__cards", "aria-label": props.label }, pageRows.map(function(r) {
|
|
724
|
+
var k = r[rowKey], isSel = !!selSet[k];
|
|
725
|
+
return h(
|
|
726
|
+
"li",
|
|
727
|
+
{
|
|
728
|
+
key: k,
|
|
729
|
+
className: cx("aura-table__card", isSel && "is-selected", props.onRowActivate && "is-actionable"),
|
|
730
|
+
tabIndex: props.onRowActivate ? 0 : void 0,
|
|
731
|
+
onClick: function(e) {
|
|
732
|
+
if (e.target.closest && e.target.closest(".aura-check, button, a, input")) return;
|
|
733
|
+
if (props.onRowActivate) props.onRowActivate(r);
|
|
734
|
+
},
|
|
735
|
+
onKeyDown: function(e) {
|
|
736
|
+
if (e.target === e.currentTarget && e.key === "Enter" && props.onRowActivate) props.onRowActivate(r);
|
|
737
|
+
}
|
|
738
|
+
},
|
|
739
|
+
h(
|
|
740
|
+
"div",
|
|
741
|
+
{ className: "aura-table__card-head" },
|
|
742
|
+
selectable ? h(Checkbox, { checked: isSel, label: t.selectRow(k), onChange: function(on) {
|
|
743
|
+
toggle(k, on);
|
|
744
|
+
} }) : null,
|
|
745
|
+
h("span", { className: cx("aura-table__card-title", titleCol.mono && "aura-table__mono") }, cellVal(titleCol, r)),
|
|
746
|
+
pillCol ? cellVal(pillCol, r) : null,
|
|
747
|
+
actionCols.map(function(c) {
|
|
748
|
+
return h("span", { key: c.key, className: "aura-table__card-actions" }, cellVal(c, r));
|
|
749
|
+
})
|
|
750
|
+
),
|
|
751
|
+
rest.length ? h("dl", { className: "aura-table__card-fields" }, rest.map(function(c) {
|
|
752
|
+
return h("div", { key: c.key }, h("dt", null, c.label), h("dd", { className: c.mono ? "aura-table__mono" : void 0 }, cellVal(c, r)));
|
|
753
|
+
})) : null
|
|
754
|
+
);
|
|
755
|
+
}));
|
|
756
|
+
}
|
|
757
|
+
return h(
|
|
758
|
+
"div",
|
|
759
|
+
{ ref: wrapMerged, className: cx("aura-table aura-table--stacked", props.className), role: "region", "aria-label": props.label, "aria-busy": loading || void 0 },
|
|
760
|
+
selectable && pageRows.length && !loading ? h(
|
|
761
|
+
"div",
|
|
762
|
+
{ className: "aura-table__stack-bar" },
|
|
763
|
+
h(Checkbox, { checked: all, indeterminate: nSel > 0 && !all, label: all ? t.deselectAllRows : t.selectAllRows, onChange: toggleAll }),
|
|
764
|
+
h("span", null, nSel ? t.selectedCount(nSel) : t.selectAll)
|
|
765
|
+
) : null,
|
|
766
|
+
cardBody,
|
|
767
|
+
foot
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
var scrollStyle = { scrollPaddingLeft: "calc(var(--aura-space-6)" + selW + " + " + acc + "px)", scrollPaddingTop: ROW_H + "px" };
|
|
771
|
+
if (height) scrollStyle.height = height + "px";
|
|
772
|
+
return h(
|
|
773
|
+
"div",
|
|
774
|
+
{ ref: wrapMerged, className: cx("aura-table", scrolledX[0] && "is-scrolled-x", props.className) },
|
|
775
|
+
h(
|
|
776
|
+
"div",
|
|
777
|
+
{
|
|
778
|
+
ref: function(el) {
|
|
779
|
+
scrollRef.current = el;
|
|
780
|
+
gridRef.current = el;
|
|
781
|
+
},
|
|
782
|
+
className: "aura-table__scroll",
|
|
783
|
+
style: scrollStyle,
|
|
784
|
+
role: "grid",
|
|
785
|
+
"aria-label": props.label,
|
|
786
|
+
"aria-busy": loading || void 0,
|
|
787
|
+
"aria-rowcount": loading ? -1 : view.length + 1,
|
|
788
|
+
"aria-colcount": nCols,
|
|
789
|
+
"aria-multiselectable": selectable || void 0,
|
|
790
|
+
onKeyDown: onGridKey,
|
|
791
|
+
onScroll: function(e) {
|
|
792
|
+
var t2 = e.currentTarget;
|
|
793
|
+
if (virtual && Math.abs(t2.scrollTop - scrollTop) >= ROW_H / 2) setScrollTop(t2.scrollTop);
|
|
794
|
+
else if (virtual && (t2.scrollTop === 0 || t2.scrollTop + t2.clientHeight >= t2.scrollHeight - 1)) setScrollTop(t2.scrollTop);
|
|
795
|
+
var sx = t2.scrollLeft > 0;
|
|
796
|
+
if (sx !== scrolledX[0]) scrolledX[1](sx);
|
|
797
|
+
}
|
|
798
|
+
},
|
|
799
|
+
h("div", { className: "aura-table__head", role: "row", "aria-rowindex": 1, style: rowStyle }, head),
|
|
800
|
+
body
|
|
801
|
+
),
|
|
802
|
+
loading ? h("span", { className: "aura-sr-only", role: "status" }, t.loadingRows) : null,
|
|
803
|
+
controls ? h(
|
|
804
|
+
"div",
|
|
805
|
+
{ className: "aura-table__picker" },
|
|
806
|
+
h(IconButton, {
|
|
807
|
+
icon: "columns-3",
|
|
808
|
+
label: t.showHideColumns,
|
|
809
|
+
"aria-haspopup": "menu",
|
|
810
|
+
onClick: function(e) {
|
|
811
|
+
openMenu("picker", null, e.currentTarget);
|
|
812
|
+
}
|
|
813
|
+
})
|
|
814
|
+
) : null,
|
|
815
|
+
foot,
|
|
816
|
+
menu ? h(Menu, {
|
|
817
|
+
anchor: menu.anchor,
|
|
818
|
+
onClose: closeMenu,
|
|
819
|
+
label: menu.kind === "picker" ? t.columns : t.column(byKey[menu.key] && byKey[menu.key].label),
|
|
820
|
+
items: menu.kind === "picker" ? pickerItems() : byKey[menu.key] ? columnMenuItems(byKey[menu.key]) : []
|
|
821
|
+
}) : null
|
|
822
|
+
);
|
|
823
|
+
});
|
|
824
|
+
export {
|
|
825
|
+
DataTable
|
|
826
|
+
};
|