@dloizides/ui-tables 1.28.1 → 1.29.0
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/CHANGELOG.md +6 -0
- package/dist/index.d.mts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +67 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React2, { memo, createContext, useState, useMemo, useCallback, useEffect, useRef,
|
|
1
|
+
import React2, { memo, createContext, useContext, useState, useMemo, useCallback, useEffect, useRef, useLayoutEffect } from 'react';
|
|
2
2
|
import { StyleSheet, View, Text, Platform, useWindowDimensions, Pressable, Switch, TextInput } from 'react-native';
|
|
3
3
|
import { useUi } from '@dloizides/ui-feedback';
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
@@ -35,6 +35,7 @@ var TABLE_TEST_IDS = {
|
|
|
35
35
|
/** Suffix of the banner's action: `${tableTestID}-select-banner-action`. */
|
|
36
36
|
selectBannerActionSuffix: "select-banner-action",
|
|
37
37
|
filterBar: "ui-filters",
|
|
38
|
+
pagedLayout: "ui-paged-table-layout",
|
|
38
39
|
results: "ui-results",
|
|
39
40
|
pager: "ui-pager",
|
|
40
41
|
pagerInfo: "ui-pager-info",
|
|
@@ -327,6 +328,23 @@ var chromeStyles = StyleSheet.create({
|
|
|
327
328
|
sizeOption: { minHeight: MIN_TARGET_PX, justifyContent: "center", paddingHorizontal: CONTROL_PAD_H, paddingVertical: MENU_OPT_PAD_V },
|
|
328
329
|
sizeOptionText: { fontSize: CONTROL_FONT, fontVariant: ["tabular-nums"] }
|
|
329
330
|
});
|
|
331
|
+
|
|
332
|
+
// src/DataTable/joinedFrameContext.ts
|
|
333
|
+
var SQUARE = 0;
|
|
334
|
+
var INNER_RADIUS = BORDER_RADIUS - BORDER_WIDTH;
|
|
335
|
+
var NO_OUTER_BORDER = { borderTopWidth: 0, borderRightWidth: 0, borderBottomWidth: 0, borderLeftWidth: 0 };
|
|
336
|
+
function cornerRadii(top, bottom) {
|
|
337
|
+
return { borderTopLeftRadius: top, borderTopRightRadius: top, borderBottomLeftRadius: bottom, borderBottomRightRadius: bottom };
|
|
338
|
+
}
|
|
339
|
+
var AT_FRAME_TOP = { ...NO_OUTER_BORDER, ...cornerRadii(INNER_RADIUS, SQUARE) };
|
|
340
|
+
var AT_FRAME_BOTTOM = { ...NO_OUTER_BORDER, ...cornerRadii(SQUARE, INNER_RADIUS) };
|
|
341
|
+
var JOINED_FRAME_STYLES = {
|
|
342
|
+
toolbar: { wrap: AT_FRAME_BOTTOM },
|
|
343
|
+
spaced: null,
|
|
344
|
+
footer: { wrap: AT_FRAME_TOP },
|
|
345
|
+
panel: { wrap: AT_FRAME_BOTTOM, filters: AT_FRAME_TOP }
|
|
346
|
+
};
|
|
347
|
+
var JoinedFrameContext = createContext(null);
|
|
330
348
|
function cellContent(column, row, textColor, overrides) {
|
|
331
349
|
const content = column.render(row);
|
|
332
350
|
if (typeof content === "string" || typeof content === "number") {
|
|
@@ -582,7 +600,7 @@ function DataTableRow({
|
|
|
582
600
|
accessibilityRole: "summary",
|
|
583
601
|
style: [tableStyles.rowDetail, { borderTopColor: colors.border, backgroundColor: colors.background }, o?.rowDetail],
|
|
584
602
|
testID: rowDetailTestID(tableTestID, rowKey),
|
|
585
|
-
children: renderRowDetail(row)
|
|
603
|
+
children: /* @__PURE__ */ jsx(JoinedFrameContext.Provider, { value: null, children: renderRowDetail(row) })
|
|
586
604
|
}
|
|
587
605
|
)
|
|
588
606
|
] });
|
|
@@ -896,6 +914,7 @@ function DataTable(props) {
|
|
|
896
914
|
const { width } = useWindowDimensions();
|
|
897
915
|
const stacked = width < stackBreakpoint;
|
|
898
916
|
const frame = { backgroundColor: colors.surface, borderColor: colors.border };
|
|
917
|
+
const joined = useContext(JoinedFrameContext);
|
|
899
918
|
const interactive = onRowPress !== void 0;
|
|
900
919
|
const [hoveredKey, setHoveredKey] = useState(void 0);
|
|
901
920
|
const hoverTint = softBrandTint(theme.palette.primary["500"]) ?? colors.background;
|
|
@@ -930,7 +949,7 @@ function DataTable(props) {
|
|
|
930
949
|
[rowTint, zebra, colors.background]
|
|
931
950
|
);
|
|
932
951
|
const rowBg = (row, index, key) => interactive && hoveredKey === key ? hoverTint : rowBackground(row, index);
|
|
933
|
-
const stateView = (label) => /* @__PURE__ */ jsx(View, { style: [tableStyles.wrap, frame, o?.wrap], testID, children: /* @__PURE__ */ jsx(View, { style: [tableStyles.state, o?.state], children: /* @__PURE__ */ jsx(Text, { style: [tableStyles.stateText, { color: colors.textSecondary }, o?.stateText], children: label }) }) });
|
|
952
|
+
const stateView = (label) => /* @__PURE__ */ jsx(View, { style: [tableStyles.wrap, frame, joined?.wrap, o?.wrap], testID, children: /* @__PURE__ */ jsx(View, { style: [tableStyles.state, o?.state], children: /* @__PURE__ */ jsx(Text, { style: [tableStyles.stateText, { color: colors.textSecondary }, o?.stateText], children: label }) }) });
|
|
934
953
|
if (rows.length === 0) {
|
|
935
954
|
return stateView(loading ? loadingLabel ?? t(TABLE_I18N.loading) : emptyLabel ?? t(TABLE_I18N.empty));
|
|
936
955
|
}
|
|
@@ -973,7 +992,7 @@ function DataTable(props) {
|
|
|
973
992
|
}
|
|
974
993
|
);
|
|
975
994
|
if (stacked) {
|
|
976
|
-
return /* @__PURE__ */ jsxs(View, { style: [tableStyles.wrap, frame, o?.wrap], testID, "aria-busy": loading, children: [
|
|
995
|
+
return /* @__PURE__ */ jsxs(View, { style: [tableStyles.wrap, frame, joined?.wrap, o?.wrap], testID, "aria-busy": loading, children: [
|
|
977
996
|
banner,
|
|
978
997
|
/* @__PURE__ */ jsx(View, { style: tableStyles.headSentinel, testID: TABLE_TEST_IDS.head, "aria-hidden": true }),
|
|
979
998
|
rows.map((row, i) => {
|
|
@@ -994,7 +1013,7 @@ function DataTable(props) {
|
|
|
994
1013
|
return /* @__PURE__ */ jsxs(
|
|
995
1014
|
View,
|
|
996
1015
|
{
|
|
997
|
-
style: [tableStyles.wrap, frame, o?.wrap],
|
|
1016
|
+
style: [tableStyles.wrap, frame, joined?.wrap, o?.wrap],
|
|
998
1017
|
testID,
|
|
999
1018
|
"aria-busy": loading,
|
|
1000
1019
|
...keyboardNavigation ? { role: "grid" } : null,
|
|
@@ -1030,8 +1049,9 @@ function FilterBar({
|
|
|
1030
1049
|
}) {
|
|
1031
1050
|
const { theme, t } = useUi();
|
|
1032
1051
|
const { colors } = theme;
|
|
1052
|
+
const joined = useContext(JoinedFrameContext);
|
|
1033
1053
|
const word = resultsLabel ?? t(TABLE_I18N.results);
|
|
1034
|
-
return /* @__PURE__ */ jsxs(View, { style: [chromeStyles.filters, { backgroundColor: colors.surface, borderColor: colors.border }, o?.filters], testID, children: [
|
|
1054
|
+
return /* @__PURE__ */ jsxs(View, { style: [chromeStyles.filters, { backgroundColor: colors.surface, borderColor: colors.border }, joined?.filters, o?.filters], testID, children: [
|
|
1035
1055
|
children,
|
|
1036
1056
|
/* @__PURE__ */ jsx(View, { style: [chromeStyles.filtersSpacer, o?.filtersSpacer] }),
|
|
1037
1057
|
typeof resultsCount === "number" && // Live region: announce the new count when filters change the result set (WCAG 4.1.3).
|
|
@@ -1423,6 +1443,47 @@ function Pager({
|
|
|
1423
1443
|
)
|
|
1424
1444
|
] });
|
|
1425
1445
|
}
|
|
1446
|
+
var LAYOUT_GAP = 12;
|
|
1447
|
+
var PAGER_SLOT_PAD_V = 8;
|
|
1448
|
+
var PAGER_IN_FRAME = { paddingHorizontal: ROW_PAD_H, paddingVertical: PAGER_SLOT_PAD_V };
|
|
1449
|
+
var FRAME = { borderWidth: BORDER_WIDTH, borderRadius: BORDER_RADIUS };
|
|
1450
|
+
var SLOT_STYLES = {
|
|
1451
|
+
toolbar: { filters: { marginBottom: LAYOUT_GAP }, pager: { ...PAGER_IN_FRAME, borderBottomWidth: BORDER_WIDTH } },
|
|
1452
|
+
spaced: { filters: {}, pager: { marginTop: LAYOUT_GAP, marginBottom: LAYOUT_GAP } },
|
|
1453
|
+
footer: { filters: { marginBottom: LAYOUT_GAP }, pager: { ...PAGER_IN_FRAME, borderTopWidth: BORDER_WIDTH } },
|
|
1454
|
+
panel: { filters: { borderBottomWidth: BORDER_WIDTH }, pager: { ...PAGER_IN_FRAME, borderBottomWidth: BORDER_WIDTH } }
|
|
1455
|
+
};
|
|
1456
|
+
function PagedTableLayout({
|
|
1457
|
+
filters,
|
|
1458
|
+
pager,
|
|
1459
|
+
table,
|
|
1460
|
+
layout = "toolbar",
|
|
1461
|
+
testID = TABLE_TEST_IDS.pagedLayout
|
|
1462
|
+
}) {
|
|
1463
|
+
const { colors } = useUi().theme;
|
|
1464
|
+
const slots = SLOT_STYLES[layout];
|
|
1465
|
+
const line = { borderColor: colors.border };
|
|
1466
|
+
const hasFilters = filters !== void 0 && filters !== null && filters !== false;
|
|
1467
|
+
const filtersInFrame = layout === "panel";
|
|
1468
|
+
const isJoined = layout !== "spaced";
|
|
1469
|
+
const filtersSlot = hasFilters ? /* @__PURE__ */ jsx(View, { style: [slots.filters, line], testID: `${testID}-filters`, children: filters }) : null;
|
|
1470
|
+
const pagerSlot = /* @__PURE__ */ jsx(View, { style: [slots.pager, line], testID: `${testID}-pager`, children: pager });
|
|
1471
|
+
const tableSlot = /* @__PURE__ */ jsx(View, { testID: `${testID}-table`, children: table });
|
|
1472
|
+
const pagerAndTable = layout === "footer" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1473
|
+
tableSlot,
|
|
1474
|
+
pagerSlot
|
|
1475
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1476
|
+
pagerSlot,
|
|
1477
|
+
tableSlot
|
|
1478
|
+
] });
|
|
1479
|
+
return /* @__PURE__ */ jsx(JoinedFrameContext.Provider, { value: JOINED_FRAME_STYLES[layout], children: /* @__PURE__ */ jsxs(View, { testID, children: [
|
|
1480
|
+
filtersInFrame ? null : filtersSlot,
|
|
1481
|
+
isJoined ? /* @__PURE__ */ jsxs(View, { style: [FRAME, line, { backgroundColor: colors.surface }], testID: `${testID}-frame`, children: [
|
|
1482
|
+
filtersInFrame ? filtersSlot : null,
|
|
1483
|
+
pagerAndTable
|
|
1484
|
+
] }) : pagerAndTable
|
|
1485
|
+
] }) });
|
|
1486
|
+
}
|
|
1426
1487
|
var FIELD_GAP = 4;
|
|
1427
1488
|
var SWITCH_ROW_GAP = 8;
|
|
1428
1489
|
var ACTION_PAD_H = 14;
|
|
@@ -2289,6 +2350,6 @@ var MonthStatusGrid = ({
|
|
|
2289
2350
|
] }, row[0]?.id)) });
|
|
2290
2351
|
};
|
|
2291
2352
|
|
|
2292
|
-
export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, Filters, LedgerLayout, MONTH_STATUS_GRID_TEST_ID, MonthGridColumns, MonthStatusGrid, Pager, RelativeTime, STATUS_LEDGER_TEST_ID, SortDirection, StatCard, StatTone, StatusLedger, StatusPill, StatusTone, TABLE_I18N, TABLE_TEST_IDS, applyTestID, clearTestID, distinctValues, fieldTestID, filterLedgerRows, fitMonthGridColumns, formatRelativeTime, isAttentionTone, ledgerSectionTestID, ledgerSortDirectionTestID, monthCellTestID, resolveStatToneColor, rowDetailTestID, rowFadeTestID, rowSelectTestID, rowTestID, selectAllTestID, sortLedgerRows, splitNeedsLook, toEpochMs, useFilterDraft, usePagedRows };
|
|
2353
|
+
export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, Filters, LedgerLayout, MONTH_STATUS_GRID_TEST_ID, MonthGridColumns, MonthStatusGrid, PagedTableLayout, Pager, RelativeTime, STATUS_LEDGER_TEST_ID, SortDirection, StatCard, StatTone, StatusLedger, StatusPill, StatusTone, TABLE_I18N, TABLE_TEST_IDS, applyTestID, clearTestID, distinctValues, fieldTestID, filterLedgerRows, fitMonthGridColumns, formatRelativeTime, isAttentionTone, ledgerSectionTestID, ledgerSortDirectionTestID, monthCellTestID, resolveStatToneColor, rowDetailTestID, rowFadeTestID, rowSelectTestID, rowTestID, selectAllTestID, sortLedgerRows, splitNeedsLook, toEpochMs, useFilterDraft, usePagedRows };
|
|
2293
2354
|
//# sourceMappingURL=index.mjs.map
|
|
2294
2355
|
//# sourceMappingURL=index.mjs.map
|