@dloizides/ui-tables 1.11.0 → 1.12.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/dist/index.mjs CHANGED
@@ -5,48 +5,6 @@ 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: String(size),
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: String(pageSize),
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: String(size),
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: field.label,
1693
+ accessibilityLabel: triggerLabel,
1644
1694
  accessibilityHint: field.accessibilityHint ?? dropdownHint,
1645
1695
  accessibilityState: { expanded: isOpen },
1646
1696
  "aria-expanded": isOpen,