@dloizides/ui-tables 1.28.0 → 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 +12 -0
- package/dist/index.d.mts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +89 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -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';
|
|
@@ -7,6 +7,7 @@ import { Z_INDEX } from '@dloizides/design-tokens';
|
|
|
7
7
|
import { createPortal } from 'react-dom';
|
|
8
8
|
import { Field, controlStyles, DateRangeControl, TypeaheadControl, DEFAULT_TYPEAHEAD_MIN_CHARS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, SelectControl } from '@dloizides/ui-forms';
|
|
9
9
|
export { DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, isUnmatched, suggestOptions } from '@dloizides/ui-forms';
|
|
10
|
+
import { useA11y } from '@dloizides/a11y';
|
|
10
11
|
|
|
11
12
|
// src/StatCard/StatCard.tsx
|
|
12
13
|
|
|
@@ -34,6 +35,7 @@ var TABLE_TEST_IDS = {
|
|
|
34
35
|
/** Suffix of the banner's action: `${tableTestID}-select-banner-action`. */
|
|
35
36
|
selectBannerActionSuffix: "select-banner-action",
|
|
36
37
|
filterBar: "ui-filters",
|
|
38
|
+
pagedLayout: "ui-paged-table-layout",
|
|
37
39
|
results: "ui-results",
|
|
38
40
|
pager: "ui-pager",
|
|
39
41
|
pagerInfo: "ui-pager-info",
|
|
@@ -326,6 +328,23 @@ var chromeStyles = StyleSheet.create({
|
|
|
326
328
|
sizeOption: { minHeight: MIN_TARGET_PX, justifyContent: "center", paddingHorizontal: CONTROL_PAD_H, paddingVertical: MENU_OPT_PAD_V },
|
|
327
329
|
sizeOptionText: { fontSize: CONTROL_FONT, fontVariant: ["tabular-nums"] }
|
|
328
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);
|
|
329
348
|
function cellContent(column, row, textColor, overrides) {
|
|
330
349
|
const content = column.render(row);
|
|
331
350
|
if (typeof content === "string" || typeof content === "number") {
|
|
@@ -581,7 +600,7 @@ function DataTableRow({
|
|
|
581
600
|
accessibilityRole: "summary",
|
|
582
601
|
style: [tableStyles.rowDetail, { borderTopColor: colors.border, backgroundColor: colors.background }, o?.rowDetail],
|
|
583
602
|
testID: rowDetailTestID(tableTestID, rowKey),
|
|
584
|
-
children: renderRowDetail(row)
|
|
603
|
+
children: /* @__PURE__ */ jsx(JoinedFrameContext.Provider, { value: null, children: renderRowDetail(row) })
|
|
585
604
|
}
|
|
586
605
|
)
|
|
587
606
|
] });
|
|
@@ -895,6 +914,7 @@ function DataTable(props) {
|
|
|
895
914
|
const { width } = useWindowDimensions();
|
|
896
915
|
const stacked = width < stackBreakpoint;
|
|
897
916
|
const frame = { backgroundColor: colors.surface, borderColor: colors.border };
|
|
917
|
+
const joined = useContext(JoinedFrameContext);
|
|
898
918
|
const interactive = onRowPress !== void 0;
|
|
899
919
|
const [hoveredKey, setHoveredKey] = useState(void 0);
|
|
900
920
|
const hoverTint = softBrandTint(theme.palette.primary["500"]) ?? colors.background;
|
|
@@ -929,7 +949,7 @@ function DataTable(props) {
|
|
|
929
949
|
[rowTint, zebra, colors.background]
|
|
930
950
|
);
|
|
931
951
|
const rowBg = (row, index, key) => interactive && hoveredKey === key ? hoverTint : rowBackground(row, index);
|
|
932
|
-
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 }) }) });
|
|
933
953
|
if (rows.length === 0) {
|
|
934
954
|
return stateView(loading ? loadingLabel ?? t(TABLE_I18N.loading) : emptyLabel ?? t(TABLE_I18N.empty));
|
|
935
955
|
}
|
|
@@ -972,7 +992,7 @@ function DataTable(props) {
|
|
|
972
992
|
}
|
|
973
993
|
);
|
|
974
994
|
if (stacked) {
|
|
975
|
-
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: [
|
|
976
996
|
banner,
|
|
977
997
|
/* @__PURE__ */ jsx(View, { style: tableStyles.headSentinel, testID: TABLE_TEST_IDS.head, "aria-hidden": true }),
|
|
978
998
|
rows.map((row, i) => {
|
|
@@ -993,7 +1013,7 @@ function DataTable(props) {
|
|
|
993
1013
|
return /* @__PURE__ */ jsxs(
|
|
994
1014
|
View,
|
|
995
1015
|
{
|
|
996
|
-
style: [tableStyles.wrap, frame, o?.wrap],
|
|
1016
|
+
style: [tableStyles.wrap, frame, joined?.wrap, o?.wrap],
|
|
997
1017
|
testID,
|
|
998
1018
|
"aria-busy": loading,
|
|
999
1019
|
...keyboardNavigation ? { role: "grid" } : null,
|
|
@@ -1029,8 +1049,9 @@ function FilterBar({
|
|
|
1029
1049
|
}) {
|
|
1030
1050
|
const { theme, t } = useUi();
|
|
1031
1051
|
const { colors } = theme;
|
|
1052
|
+
const joined = useContext(JoinedFrameContext);
|
|
1032
1053
|
const word = resultsLabel ?? t(TABLE_I18N.results);
|
|
1033
|
-
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: [
|
|
1034
1055
|
children,
|
|
1035
1056
|
/* @__PURE__ */ jsx(View, { style: [chromeStyles.filtersSpacer, o?.filtersSpacer] }),
|
|
1036
1057
|
typeof resultsCount === "number" && // Live region: announce the new count when filters change the result set (WCAG 4.1.3).
|
|
@@ -1422,6 +1443,47 @@ function Pager({
|
|
|
1422
1443
|
)
|
|
1423
1444
|
] });
|
|
1424
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
|
+
}
|
|
1425
1487
|
var FIELD_GAP = 4;
|
|
1426
1488
|
var SWITCH_ROW_GAP = 8;
|
|
1427
1489
|
var ACTION_PAD_H = 14;
|
|
@@ -1583,21 +1645,27 @@ function TextField({ field, barTestID, value, onChange, onSubmit }) {
|
|
|
1583
1645
|
const { theme } = useUi();
|
|
1584
1646
|
const { colors } = theme;
|
|
1585
1647
|
const isNumber = field.kind === "number";
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1648
|
+
const { a11yProps, hintNode } = useA11y({
|
|
1649
|
+
label: field.label,
|
|
1650
|
+
hint: field.accessibilityHint,
|
|
1651
|
+
testID: `${field.testID ?? fieldTestID(barTestID, field.key)}-input`
|
|
1652
|
+
});
|
|
1653
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1654
|
+
/* @__PURE__ */ jsx(
|
|
1655
|
+
TextInput,
|
|
1656
|
+
{
|
|
1657
|
+
...a11yProps,
|
|
1658
|
+
keyboardType: isNumber ? "numeric" : "default",
|
|
1659
|
+
placeholder: field.placeholder,
|
|
1660
|
+
placeholderTextColor: colors.textSecondary,
|
|
1661
|
+
value,
|
|
1662
|
+
onChangeText: onChange,
|
|
1663
|
+
onSubmitEditing: onSubmit,
|
|
1664
|
+
style: [controlStyles.input, { borderColor: colors.border, backgroundColor: colors.surface, color: colors.text }]
|
|
1665
|
+
}
|
|
1666
|
+
),
|
|
1667
|
+
hintNode
|
|
1668
|
+
] });
|
|
1601
1669
|
}
|
|
1602
1670
|
function TypeaheadField({ field, barTestID, value, onChange, onSubmit, optionHint }) {
|
|
1603
1671
|
return /* @__PURE__ */ jsx(
|
|
@@ -2282,6 +2350,6 @@ var MonthStatusGrid = ({
|
|
|
2282
2350
|
] }, row[0]?.id)) });
|
|
2283
2351
|
};
|
|
2284
2352
|
|
|
2285
|
-
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 };
|
|
2286
2354
|
//# sourceMappingURL=index.mjs.map
|
|
2287
2355
|
//# sourceMappingURL=index.mjs.map
|