@dloizides/ui-tables 1.11.0 → 1.13.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 +80 -0
- package/README.md +36 -2
- package/dist/index.d.mts +57 -1
- package/dist/index.d.ts +57 -1
- package/dist/index.js +130 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +130 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,52 +1,10 @@
|
|
|
1
|
-
import React4, { memo, useState, useMemo, useCallback, useRef, useLayoutEffect
|
|
1
|
+
import React4, { memo, 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';
|
|
5
5
|
import { createPortal } from 'react-dom';
|
|
6
6
|
|
|
7
7
|
// src/StatCard/StatCard.tsx
|
|
8
|
-
var CARD_PADDING = 16;
|
|
9
|
-
var CARD_BORDER_RADIUS = 12;
|
|
10
|
-
var CARD_BORDER_WIDTH = 1;
|
|
11
|
-
var LABEL_FONT_SIZE = 14;
|
|
12
|
-
var VALUE_FONT_SIZE = 28;
|
|
13
|
-
var VALUE_LINE_HEIGHT = 36;
|
|
14
|
-
var styles = StyleSheet.create({
|
|
15
|
-
card: {
|
|
16
|
-
padding: CARD_PADDING,
|
|
17
|
-
borderRadius: CARD_BORDER_RADIUS,
|
|
18
|
-
borderWidth: CARD_BORDER_WIDTH
|
|
19
|
-
},
|
|
20
|
-
label: {
|
|
21
|
-
fontSize: LABEL_FONT_SIZE,
|
|
22
|
-
fontWeight: "500"
|
|
23
|
-
},
|
|
24
|
-
value: {
|
|
25
|
-
fontSize: VALUE_FONT_SIZE,
|
|
26
|
-
fontWeight: "700",
|
|
27
|
-
lineHeight: VALUE_LINE_HEIGHT
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
var StatCard = memo(({ label, value, testID }) => {
|
|
31
|
-
const { theme, t } = useUi();
|
|
32
|
-
const { colors } = theme;
|
|
33
|
-
const formattedValue = value.toLocaleString();
|
|
34
|
-
return /* @__PURE__ */ jsxs(
|
|
35
|
-
View,
|
|
36
|
-
{
|
|
37
|
-
accessibilityHint: t("analytics.statHint", label),
|
|
38
|
-
accessibilityLabel: t("analytics.statCardLabel", label, formattedValue),
|
|
39
|
-
accessibilityRole: "text",
|
|
40
|
-
style: [styles.card, { backgroundColor: colors.surface, borderColor: colors.border }],
|
|
41
|
-
testID,
|
|
42
|
-
children: [
|
|
43
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.label, { color: colors.textSecondary }], children: label }),
|
|
44
|
-
/* @__PURE__ */ jsx(Text, { style: [styles.value, { color: colors.text }], children: formattedValue })
|
|
45
|
-
]
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
StatCard.displayName = "StatCard";
|
|
50
8
|
|
|
51
9
|
// src/DataTable/constants.ts
|
|
52
10
|
var CARD_STACK_BREAKPOINT = 640;
|
|
@@ -115,8 +73,70 @@ var TABLE_I18N = {
|
|
|
115
73
|
pagerRows: "uiTables.pager.rows",
|
|
116
74
|
pagerRowsOptionHint: "uiTables.pager.rowsOptionHint",
|
|
117
75
|
/** Accessible hint for the dropdown-variant rows-per-page trigger button. */
|
|
118
|
-
pagerRowsTriggerHint: "uiTables.pager.rowsTriggerHint"
|
|
76
|
+
pagerRowsTriggerHint: "uiTables.pager.rowsTriggerHint",
|
|
77
|
+
/**
|
|
78
|
+
* Accessible NAME of the rows-per-page control, e.g. "Rows per page, currently {{p1}}".
|
|
79
|
+
* Without it the control is announced as the bare number ("50"), which says nothing about
|
|
80
|
+
* what it does. Untranslated it degrades to that bare number — never to the raw key.
|
|
81
|
+
*/
|
|
82
|
+
pagerRowsTriggerLabel: "uiTables.pager.rowsTriggerLabel",
|
|
83
|
+
/**
|
|
84
|
+
* Accessible NAME of ONE rows-per-page choice, e.g. "Show {{p1}} rows per page". Used by
|
|
85
|
+
* BOTH the `dropdown` options and the default `pills`. Untranslated it degrades to the
|
|
86
|
+
* bare number — never to the raw key.
|
|
87
|
+
*/
|
|
88
|
+
pagerRowsOptionLabel: "uiTables.pager.rowsOptionLabel",
|
|
89
|
+
/**
|
|
90
|
+
* StatCard's accessible name, e.g. "{{p1}}: {{p2}}". Note the `analytics.` prefix: these
|
|
91
|
+
* two keys predate this map and were only ever inlined in StatCard.tsx, so apps deriving
|
|
92
|
+
* their required-key list from TABLE_I18N could not see them. Registered here UNCHANGED
|
|
93
|
+
* (renaming them would break every app that already defines them).
|
|
94
|
+
*/
|
|
95
|
+
statCardLabel: "analytics.statCardLabel",
|
|
96
|
+
statHint: "analytics.statHint"
|
|
119
97
|
};
|
|
98
|
+
var CARD_PADDING = 16;
|
|
99
|
+
var CARD_BORDER_RADIUS = 12;
|
|
100
|
+
var CARD_BORDER_WIDTH = 1;
|
|
101
|
+
var LABEL_FONT_SIZE = 14;
|
|
102
|
+
var VALUE_FONT_SIZE = 28;
|
|
103
|
+
var VALUE_LINE_HEIGHT = 36;
|
|
104
|
+
var styles = StyleSheet.create({
|
|
105
|
+
card: {
|
|
106
|
+
padding: CARD_PADDING,
|
|
107
|
+
borderRadius: CARD_BORDER_RADIUS,
|
|
108
|
+
borderWidth: CARD_BORDER_WIDTH
|
|
109
|
+
},
|
|
110
|
+
label: {
|
|
111
|
+
fontSize: LABEL_FONT_SIZE,
|
|
112
|
+
fontWeight: "500"
|
|
113
|
+
},
|
|
114
|
+
value: {
|
|
115
|
+
fontSize: VALUE_FONT_SIZE,
|
|
116
|
+
fontWeight: "700",
|
|
117
|
+
lineHeight: VALUE_LINE_HEIGHT
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
var StatCard = memo(({ label, value, testID }) => {
|
|
121
|
+
const { theme, t } = useUi();
|
|
122
|
+
const { colors } = theme;
|
|
123
|
+
const formattedValue = value.toLocaleString();
|
|
124
|
+
return /* @__PURE__ */ jsxs(
|
|
125
|
+
View,
|
|
126
|
+
{
|
|
127
|
+
accessibilityHint: t(TABLE_I18N.statHint, label),
|
|
128
|
+
accessibilityLabel: t(TABLE_I18N.statCardLabel, label, formattedValue),
|
|
129
|
+
accessibilityRole: "text",
|
|
130
|
+
style: [styles.card, { backgroundColor: colors.surface, borderColor: colors.border }],
|
|
131
|
+
testID,
|
|
132
|
+
children: [
|
|
133
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.label, { color: colors.textSecondary }], children: label }),
|
|
134
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.value, { color: colors.text }], children: formattedValue })
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
StatCard.displayName = "StatCard";
|
|
120
140
|
var BORDER_WIDTH = 1;
|
|
121
141
|
var BORDER_RADIUS = 12;
|
|
122
142
|
var COLUMN_GAP = 16;
|
|
@@ -951,6 +971,12 @@ function FilterBar({
|
|
|
951
971
|
!!actions && /* @__PURE__ */ jsx(View, { style: [chromeStyles.filtersActions, o?.filtersActions], children: actions })
|
|
952
972
|
] });
|
|
953
973
|
}
|
|
974
|
+
|
|
975
|
+
// src/accessibleName.ts
|
|
976
|
+
function accessibleName(translated, key, fallback) {
|
|
977
|
+
const isUntranslated = translated === key || translated === "";
|
|
978
|
+
return isUntranslated ? fallback : translated;
|
|
979
|
+
}
|
|
954
980
|
var CHEVRON_DOWN = "\u25BE";
|
|
955
981
|
var CHEVRON_UP = "\u25B4";
|
|
956
982
|
var IS_WEB2 = Platform.OS === "web";
|
|
@@ -1016,6 +1042,8 @@ function SizeDropdown({
|
|
|
1016
1042
|
pageSizeOptions,
|
|
1017
1043
|
onPageSizeChange,
|
|
1018
1044
|
testID,
|
|
1045
|
+
triggerLabel,
|
|
1046
|
+
getOptionLabel,
|
|
1019
1047
|
triggerHint,
|
|
1020
1048
|
optionHint,
|
|
1021
1049
|
textColor,
|
|
@@ -1059,7 +1087,7 @@ function SizeDropdown({
|
|
|
1059
1087
|
{
|
|
1060
1088
|
testID: `${testID}-size-${size}`,
|
|
1061
1089
|
accessibilityRole: "menuitem",
|
|
1062
|
-
accessibilityLabel:
|
|
1090
|
+
accessibilityLabel: getOptionLabel(size),
|
|
1063
1091
|
accessibilityHint: optionHint,
|
|
1064
1092
|
accessibilityState: { selected: active },
|
|
1065
1093
|
onPress: () => select(size),
|
|
@@ -1077,7 +1105,7 @@ function SizeDropdown({
|
|
|
1077
1105
|
{
|
|
1078
1106
|
testID: `${testID}-size-trigger`,
|
|
1079
1107
|
accessibilityRole: "button",
|
|
1080
|
-
accessibilityLabel:
|
|
1108
|
+
accessibilityLabel: triggerLabel,
|
|
1081
1109
|
accessibilityHint: triggerHint,
|
|
1082
1110
|
accessibilityState: { expanded: isOpen },
|
|
1083
1111
|
"aria-expanded": isOpen,
|
|
@@ -1114,6 +1142,14 @@ function NavButton({ label, hint, disabled, onPress, color, border, testID, styl
|
|
|
1114
1142
|
}
|
|
1115
1143
|
);
|
|
1116
1144
|
}
|
|
1145
|
+
function rowsTriggerLabel(t, pageSize) {
|
|
1146
|
+
const size = String(pageSize);
|
|
1147
|
+
return accessibleName(t(TABLE_I18N.pagerRowsTriggerLabel, size), TABLE_I18N.pagerRowsTriggerLabel, size);
|
|
1148
|
+
}
|
|
1149
|
+
function rowsOptionLabel(t, optionSize) {
|
|
1150
|
+
const size = String(optionSize);
|
|
1151
|
+
return accessibleName(t(TABLE_I18N.pagerRowsOptionLabel, size), TABLE_I18N.pagerRowsOptionLabel, size);
|
|
1152
|
+
}
|
|
1117
1153
|
function RowsControl({ pageSize, pageSizeOptions, onPageSizeChange, isDropdown, testID, styleOverrides: o }) {
|
|
1118
1154
|
const { theme, t } = useUi();
|
|
1119
1155
|
const { colors, palette } = theme;
|
|
@@ -1127,6 +1163,8 @@ function RowsControl({ pageSize, pageSizeOptions, onPageSizeChange, isDropdown,
|
|
|
1127
1163
|
pageSizeOptions,
|
|
1128
1164
|
onPageSizeChange,
|
|
1129
1165
|
testID,
|
|
1166
|
+
triggerLabel: rowsTriggerLabel(t, pageSize),
|
|
1167
|
+
getOptionLabel: (size) => rowsOptionLabel(t, size),
|
|
1130
1168
|
triggerHint: t(TABLE_I18N.pagerRowsTriggerHint),
|
|
1131
1169
|
optionHint: t(TABLE_I18N.pagerRowsOptionHint),
|
|
1132
1170
|
textColor: colors.text,
|
|
@@ -1144,7 +1182,7 @@ function RowsControl({ pageSize, pageSizeOptions, onPageSizeChange, isDropdown,
|
|
|
1144
1182
|
{
|
|
1145
1183
|
testID: `${testID}-size-${size}`,
|
|
1146
1184
|
accessibilityRole: "button",
|
|
1147
|
-
accessibilityLabel:
|
|
1185
|
+
accessibilityLabel: rowsOptionLabel(t, size),
|
|
1148
1186
|
accessibilityHint: t(TABLE_I18N.pagerRowsOptionHint),
|
|
1149
1187
|
accessibilityState: { selected: active },
|
|
1150
1188
|
hitSlop: PAGER_HIT_SLOP,
|
|
@@ -1441,6 +1479,13 @@ var FILTERS_I18N = {
|
|
|
1441
1479
|
selectPlaceholder: "uiTables.filters.selectPlaceholder",
|
|
1442
1480
|
dropdownHint: "uiTables.filters.dropdownHint",
|
|
1443
1481
|
optionHint: "uiTables.filters.optionHint",
|
|
1482
|
+
/**
|
|
1483
|
+
* Accessible NAME of a select trigger, e.g. "{{p1}}: {{p2}}" → "Status: Active". The
|
|
1484
|
+
* trigger's `accessibilityLabel` REPLACES its visible text for a screen reader, so labelling
|
|
1485
|
+
* it with the field name alone silently hides the current selection. Untranslated it
|
|
1486
|
+
* degrades to the field label alone (prior behaviour) — never to the raw key.
|
|
1487
|
+
*/
|
|
1488
|
+
selectTriggerLabel: "uiTables.filters.selectTriggerLabel",
|
|
1444
1489
|
from: "uiTables.filters.from",
|
|
1445
1490
|
to: "uiTables.filters.to"
|
|
1446
1491
|
};
|
|
@@ -1613,7 +1658,7 @@ function AnchoredMenu({
|
|
|
1613
1658
|
var CHEVRON_DOWN2 = "\u25BE";
|
|
1614
1659
|
var CHEVRON_UP2 = "\u25B4";
|
|
1615
1660
|
function SelectField({ field, barTestID, value, onChange, placeholder, dropdownHint, optionHint }) {
|
|
1616
|
-
const { theme } = useUi();
|
|
1661
|
+
const { theme, t } = useUi();
|
|
1617
1662
|
const { colors, palette } = theme;
|
|
1618
1663
|
const anchorRef = useRef(null);
|
|
1619
1664
|
const [isOpen, setIsOpen] = useState(false);
|
|
@@ -1622,6 +1667,11 @@ function SelectField({ field, barTestID, value, onChange, placeholder, dropdownH
|
|
|
1622
1667
|
const found = field.options.find((o) => o.value === value);
|
|
1623
1668
|
return found?.label ?? field.placeholder ?? placeholder;
|
|
1624
1669
|
}, [field.options, field.placeholder, placeholder, value]);
|
|
1670
|
+
const triggerLabel = accessibleName(
|
|
1671
|
+
t(FILTERS_I18N.selectTriggerLabel, field.label, selectedLabel),
|
|
1672
|
+
FILTERS_I18N.selectTriggerLabel,
|
|
1673
|
+
field.label
|
|
1674
|
+
);
|
|
1625
1675
|
const close = useCallback(() => {
|
|
1626
1676
|
setIsOpen(false);
|
|
1627
1677
|
}, []);
|
|
@@ -1640,7 +1690,7 @@ function SelectField({ field, barTestID, value, onChange, placeholder, dropdownH
|
|
|
1640
1690
|
Pressable,
|
|
1641
1691
|
{
|
|
1642
1692
|
accessibilityRole: "button",
|
|
1643
|
-
accessibilityLabel:
|
|
1693
|
+
accessibilityLabel: triggerLabel,
|
|
1644
1694
|
accessibilityHint: field.accessibilityHint ?? dropdownHint,
|
|
1645
1695
|
accessibilityState: { expanded: isOpen },
|
|
1646
1696
|
"aria-expanded": isOpen,
|
|
@@ -1987,7 +2037,37 @@ function useFilterDraft({ initial, onApply, onReset }) {
|
|
|
1987
2037
|
const dirty = useMemo(() => !shallowEqual(draft, committed), [draft, committed]);
|
|
1988
2038
|
return { draft, committed, setField, setDraft, apply, reset, dirty };
|
|
1989
2039
|
}
|
|
2040
|
+
var DEFAULT_PAGE_SIZE = 10;
|
|
2041
|
+
function usePagedRows(rows, options = {}) {
|
|
2042
|
+
const pageSize = Math.max(1, options.pageSize ?? DEFAULT_PAGE_SIZE);
|
|
2043
|
+
const [currentPage, setCurrentPage] = useState(0);
|
|
2044
|
+
const totalPages = Math.ceil(rows.length / pageSize);
|
|
2045
|
+
useEffect(() => {
|
|
2046
|
+
const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
|
|
2047
|
+
if (currentPage > lastValidPage) setCurrentPage(lastValidPage);
|
|
2048
|
+
}, [currentPage, totalPages]);
|
|
2049
|
+
const pageRows = useMemo(() => {
|
|
2050
|
+
const start = currentPage * pageSize;
|
|
2051
|
+
return rows.slice(start, start + pageSize);
|
|
2052
|
+
}, [rows, currentPage, pageSize]);
|
|
2053
|
+
const setPage = useCallback(
|
|
2054
|
+
(page) => {
|
|
2055
|
+
const lastValidPage = totalPages > 0 ? totalPages - 1 : 0;
|
|
2056
|
+
const clamped = Math.min(Math.max(0, page), lastValidPage);
|
|
2057
|
+
setCurrentPage(clamped);
|
|
2058
|
+
},
|
|
2059
|
+
[totalPages]
|
|
2060
|
+
);
|
|
2061
|
+
return {
|
|
2062
|
+
pageRows,
|
|
2063
|
+
currentPage,
|
|
2064
|
+
totalPages,
|
|
2065
|
+
setPage,
|
|
2066
|
+
hasPages: totalPages > 1,
|
|
2067
|
+
pageSize
|
|
2068
|
+
};
|
|
2069
|
+
}
|
|
1990
2070
|
|
|
1991
|
-
export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DataTable, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, Filters, Pager, StatCard, TABLE_I18N, TABLE_TEST_IDS, applyTestID, clearTestID, fieldTestID, isUnmatched, rowDetailTestID, rowSelectTestID, rowTestID, selectAllTestID, suggestOptions, useFilterDraft };
|
|
2071
|
+
export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE, DEFAULT_PAGE_SIZE_OPTIONS, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DataTable, FIELD_MIN_WIDTH, FILTERS_I18N, FILTERS_TEST_ID, FilterBar, Filters, Pager, StatCard, TABLE_I18N, TABLE_TEST_IDS, applyTestID, clearTestID, fieldTestID, isUnmatched, rowDetailTestID, rowSelectTestID, rowTestID, selectAllTestID, suggestOptions, useFilterDraft, usePagedRows };
|
|
1992
2072
|
//# sourceMappingURL=index.mjs.map
|
|
1993
2073
|
//# sourceMappingURL=index.mjs.map
|