@dloizides/ui-tables 1.0.1 → 1.2.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 CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0
4
+
5
+ - `Pager` — new optional `unitLabel?: string` prop. When supplied it appends an
6
+ already-translated unit noun to the count line, e.g. `unitLabel="leadership terms"`
7
+ renders `1–50 of 3,023 leadership terms` (v1 parity). Backward-compatible: when the
8
+ prop is omitted (or empty) the count line stays the generic `from–to of N`,
9
+ byte-identical to prior behaviour.
10
+ - Test tooling — added `src/jest-dom.d.ts` so ts-jest picks up the
11
+ `@testing-library/jest-dom` matcher types (`toBeDisabled`, …) when type-checking each
12
+ test file (`jest.setup.ts` sits outside the `src/**` include). Fixes the `Pager` suite
13
+ failing to compile under the isolated ts-jest type-check.
14
+
15
+ ## 1.1.0
16
+
17
+ - `DataTable` — promoted from the `/coverage` RN-web POC and hardened into the shared,
18
+ tokenized grid (the `wwwroot/shared/GRID.md` contract):
19
+ - per-row `testID` + `accessibilityLabel`/`accessibilityHint`, pressable rows (`onRowPress`);
20
+ - all user-facing chrome routed through the UiProvider `t` (no literals) — falls back to
21
+ caller-supplied `loadingLabel`/`emptyLabel`;
22
+ - fixed the POC's double `col.render()` call in the desktop path (now rendered once per cell);
23
+ - added the rest of the GRID.md contract: `FilterBar`, `Pager` (page-info + Prev/Next +
24
+ rows-per-page), an optional `zebra` modifier, and a `stickyHeader`;
25
+ - responsive label:value card-stack via `useWindowDimensions` below `stackBreakpoint`;
26
+ - every colour from `@dloizides/design-tokens` via the `useUi()` theme — no hardcoded colours.
27
+ - Component tests (`DataTable`, `FilterBar`, `Pager`) added.
28
+
3
29
  ## 1.0.0
4
30
 
5
31
  Initial release (Capability Wave C1, batch 3).
package/README.md CHANGED
@@ -8,7 +8,27 @@ portfolio. Reads theme + translations from the shared `@dloizides/ui-feedback` U
8
8
  | Component | Status |
9
9
  |-----------|--------|
10
10
  | `StatCard` | ✅ Available — labelled metric tile (label + locale-formatted value). |
11
- | `DataTable`, `StatGrid` | ⏳ Deferred — currently exist only in kefi-web (n=1). They move in here when a 2nd consumer appears ("extract on the 2nd use, not the first"). |
11
+ | `DataTable` | ✅ Available — the shared, tokenized RN-web grid (the `GRID.md` contract): `columns + rows` API, sticky header, zebra striping, per-row tint, pressable rows, per-row `testID` + a11y, and a responsive label:value **card-stack** below `stackBreakpoint`. |
12
+ | `FilterBar` | ✅ Available — the `.ui-filters` shell: wrapping field row + live results count + actions slot. |
13
+ | `Pager` | ✅ Available — the `.ui-pager` control: `from–to of N` page-info + rows-per-page pills + Prev/Next. Pass an optional, already-translated `unitLabel` (e.g. `"leadership terms"`) to render `1–50 of 3,023 leadership terms`. |
14
+ | `StatGrid` | ⏳ Deferred — exists only in kefi-web (n=1); moves in when a 2nd consumer appears. |
15
+
16
+ ### DataTable / FilterBar / Pager
17
+
18
+ ```tsx
19
+ import { DataTable, FilterBar, Pager, type DataTableColumn } from '@dloizides/ui-tables';
20
+
21
+ const columns: DataTableColumn<Row>[] = [
22
+ { key: 'name', header: 'Name', weight: 2, render: (r) => r.name },
23
+ { key: 'score', header: 'Score', numeric: true, render: (r) => String(r.score) },
24
+ ];
25
+
26
+ <FilterBar resultsCount={rows.length} actions={<ApplyButton />}>{fields}</FilterBar>
27
+ <DataTable columns={columns} rows={rows} keyExtractor={(r) => r.id} zebra stickyHeader testID="grid" />
28
+ <Pager page={page} pageSize={size} total={total} onPageChange={setPage} onPageSizeChange={setSize} />
29
+ ```
30
+
31
+ Colours come entirely from `useUi().theme` (drive it with `@dloizides/design-tokens` via `tokensToUiTheme`), so the grid re-themes per tenant. Every component-authored string is routed through the UiProvider `t` — provide the `uiTables.*` keys (see `TABLE_I18N`) in your locale files; a caller may also pass already-translated `loadingLabel` / `emptyLabel` / `resultsLabel` directly.
12
32
 
13
33
  ## Install
14
34
 
package/dist/index.d.mts CHANGED
@@ -11,4 +11,151 @@ interface StatCardProps {
11
11
  }
12
12
  declare const StatCard: React.MemoExoticComponent<({ label, value, testID }: StatCardProps) => React.ReactElement>;
13
13
 
14
- export { StatCard, type StatCardProps };
14
+ /**
15
+ * The DataTable contract — a `columns + rows` grid (the shape proven in the POC and
16
+ * carried over unchanged; it is the right API). Every user-facing string is either
17
+ * caller-supplied (already translated by the app's FM) or routed through the
18
+ * UiProvider `t` inside the components — no literals baked into the render.
19
+ */
20
+
21
+ interface DataTableColumn<T> {
22
+ /** Stable column id (used for React keys + per-cell test ids). */
23
+ key: string;
24
+ /** Column header text. Also the `label` in the mobile label:value card-stack. */
25
+ header: string;
26
+ /** Right-align + tabular figures for numeric columns (GRID.md `.num`). */
27
+ numeric?: boolean;
28
+ /** Flex weight on desktop. Default 1. */
29
+ weight?: number;
30
+ render: (row: T) => React.ReactNode;
31
+ }
32
+ interface DataTableProps<T> {
33
+ columns: ReadonlyArray<DataTableColumn<T>>;
34
+ rows: readonly T[];
35
+ keyExtractor: (row: T) => string;
36
+ /** Optional per-row background tint (e.g. gap rows). Wins over `zebra`. */
37
+ rowTint?: (row: T) => string | undefined;
38
+ /** Even-row striping (GRID.md `.ui-table--zebra`). Ignored on rows that have a `rowTint`. */
39
+ zebra?: boolean;
40
+ /** Keep the header pinned while the body scrolls (web `position: sticky`). */
41
+ stickyHeader?: boolean;
42
+ /** Make rows pressable (GRID.md `is-click`). Enables row accessibilityRole=button. */
43
+ onRowPress?: (row: T) => void;
44
+ /** Per-row accessibility label. Falls back to the kit's `rowLabel` translation. */
45
+ getRowAccessibilityLabel?: (row: T) => string;
46
+ loading?: boolean;
47
+ /** Loading text (already translated). Falls back to the kit's `loading` translation. */
48
+ loadingLabel?: string;
49
+ /** Empty text (already translated). Falls back to the kit's `empty` translation. */
50
+ emptyLabel?: string;
51
+ /** Below this width (px) rows collapse to a label:value card. Default 640. */
52
+ stackBreakpoint?: number;
53
+ testID?: string;
54
+ }
55
+
56
+ /**
57
+ * DataTable — the shared, tokenized RN-web grid for every dloizides.com surface
58
+ * (and the future AML v2 portal). Promoted from the POC draft; completes the
59
+ * `wwwroot/shared/GRID.md` behavioural contract in the RN idiom:
60
+ *
61
+ * - columns + rows API (unchanged from the POC — it is the right shape).
62
+ * - sticky header (`stickyHeader`), zebra striping (`zebra`), per-row tint.
63
+ * - a responsive label:value **card-stack** below `stackBreakpoint` via
64
+ * `useWindowDimensions` (the CSS `data-label` card-stack does not port).
65
+ * - per-row `testID` + `accessibilityLabel`/`accessibilityHint` (kit standard).
66
+ * - every colour from `useUi().theme`; every component-authored string via `t`.
67
+ */
68
+
69
+ declare function DataTable<T>(props: DataTableProps<T>): React.ReactElement;
70
+
71
+ /**
72
+ * FilterBar — the shared filter-bar shell from GRID.md (`.ui-filters`): a themed,
73
+ * wrapping row that holds the caller's filter fields, an optional live results
74
+ * count (`<b>N</b> results`) and an optional actions slot (Apply / Export …).
75
+ * Layout + theming only — the fields themselves come from the app (or @dloizides/
76
+ * ui-forms), keeping this reusable across every grid rather than coverage-specific.
77
+ */
78
+
79
+ interface FilterBarProps {
80
+ /** The filter fields (labels + inputs), supplied by the app / ui-forms. */
81
+ children?: React.ReactNode;
82
+ /** Live count shown as `<b>{resultsCount}</b> {results}`. Omit to hide. */
83
+ resultsCount?: number;
84
+ /** Overrides the kit's translated "results" word (pass an app-translated string). */
85
+ resultsLabel?: string;
86
+ /** Right-aligned action buttons (Apply, Export CSV, …). */
87
+ actions?: React.ReactNode;
88
+ testID?: string;
89
+ }
90
+ declare function FilterBar({ children, resultsCount, resultsLabel, actions, testID, }: FilterBarProps): React.ReactElement;
91
+
92
+ /**
93
+ * Pager — the shared pagination control from GRID.md (`.ui-pager`): page-info on
94
+ * the left (`from–to of N`), nav on the right (rows-per-page + Prev/Next). Sits ON
95
+ * TOP of the grid (in the section header row), so every paged grid looks the same.
96
+ * RN idiom: rows-per-page is a row of pressable pills (RN has no native `<select>`);
97
+ * everything is themed from `useUi().theme` and labelled via the UiProvider `t`.
98
+ */
99
+
100
+ interface PagerProps {
101
+ /** 1-based current page. */
102
+ page: number;
103
+ /** Rows per page. */
104
+ pageSize: number;
105
+ /** Total row count across all pages. */
106
+ total: number;
107
+ onPageChange: (page: number) => void;
108
+ onPageSizeChange: (pageSize: number) => void;
109
+ /** Rows-per-page choices. Default 25 / 50 / 100 / 200. */
110
+ pageSizeOptions?: readonly number[];
111
+ /**
112
+ * Optional, already-translated unit noun appended to the count line, e.g.
113
+ * `"leadership terms"` renders `1–50 of 3,023 leadership terms`. When omitted the
114
+ * count line stays the generic `from–to of N` (byte-identical to prior behaviour).
115
+ */
116
+ unitLabel?: string;
117
+ testID?: string;
118
+ }
119
+ declare function Pager({ page, pageSize, total, onPageChange, onPageSizeChange, pageSizeOptions, unitLabel, testID, }: PagerProps): React.ReactElement;
120
+
121
+ /**
122
+ * Shared constants for the DataTable family (DataTable / FilterBar / Pager).
123
+ * Keeps every literal (test ids, i18n keys, layout numbers) in one place so the
124
+ * components hold no magic numbers and no ad-hoc strings.
125
+ */
126
+ /** Default breakpoint (px): below this a row collapses to a label:value card. */
127
+ declare const CARD_STACK_BREAKPOINT = 640;
128
+ /** Default rows-per-page choices, matching the vanilla console's GRID.md pager. */
129
+ declare const DEFAULT_PAGE_SIZE_OPTIONS: readonly number[];
130
+ /** Stable test ids so consumers/e2e can target the shared chrome. */
131
+ declare const TABLE_TEST_IDS: {
132
+ readonly root: "ui-data-table";
133
+ readonly head: "ui-data-table-head";
134
+ readonly filterBar: "ui-filters";
135
+ readonly results: "ui-results";
136
+ readonly pager: "ui-pager";
137
+ readonly pagerInfo: "ui-pager-info";
138
+ readonly pagerPrev: "ui-pager-prev";
139
+ readonly pagerNext: "ui-pager-next";
140
+ };
141
+ /**
142
+ * Translation keys for every component-authored, user-facing string. Apps map
143
+ * these in their UiProvider `t` (FM); the neutral default `t` returns the key, so
144
+ * a host that forgets a key degrades to the key rather than a hardcoded literal.
145
+ */
146
+ declare const TABLE_I18N: {
147
+ readonly loading: "uiTables.loading";
148
+ readonly empty: "uiTables.empty";
149
+ readonly rowLabel: "uiTables.rowLabel";
150
+ readonly rowHint: "uiTables.rowHint";
151
+ readonly results: "uiTables.results";
152
+ readonly pagerInfo: "uiTables.pager.info";
153
+ readonly pagerPrev: "uiTables.pager.prev";
154
+ readonly pagerNext: "uiTables.pager.next";
155
+ readonly pagerPrevHint: "uiTables.pager.prevHint";
156
+ readonly pagerNextHint: "uiTables.pager.nextHint";
157
+ readonly pagerRows: "uiTables.pager.rows";
158
+ readonly pagerRowsOptionHint: "uiTables.pager.rowsOptionHint";
159
+ };
160
+
161
+ export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, type DataTableColumn, type DataTableProps, FilterBar, type FilterBarProps, Pager, type PagerProps, StatCard, type StatCardProps, TABLE_I18N, TABLE_TEST_IDS };
package/dist/index.d.ts CHANGED
@@ -11,4 +11,151 @@ interface StatCardProps {
11
11
  }
12
12
  declare const StatCard: React.MemoExoticComponent<({ label, value, testID }: StatCardProps) => React.ReactElement>;
13
13
 
14
- export { StatCard, type StatCardProps };
14
+ /**
15
+ * The DataTable contract — a `columns + rows` grid (the shape proven in the POC and
16
+ * carried over unchanged; it is the right API). Every user-facing string is either
17
+ * caller-supplied (already translated by the app's FM) or routed through the
18
+ * UiProvider `t` inside the components — no literals baked into the render.
19
+ */
20
+
21
+ interface DataTableColumn<T> {
22
+ /** Stable column id (used for React keys + per-cell test ids). */
23
+ key: string;
24
+ /** Column header text. Also the `label` in the mobile label:value card-stack. */
25
+ header: string;
26
+ /** Right-align + tabular figures for numeric columns (GRID.md `.num`). */
27
+ numeric?: boolean;
28
+ /** Flex weight on desktop. Default 1. */
29
+ weight?: number;
30
+ render: (row: T) => React.ReactNode;
31
+ }
32
+ interface DataTableProps<T> {
33
+ columns: ReadonlyArray<DataTableColumn<T>>;
34
+ rows: readonly T[];
35
+ keyExtractor: (row: T) => string;
36
+ /** Optional per-row background tint (e.g. gap rows). Wins over `zebra`. */
37
+ rowTint?: (row: T) => string | undefined;
38
+ /** Even-row striping (GRID.md `.ui-table--zebra`). Ignored on rows that have a `rowTint`. */
39
+ zebra?: boolean;
40
+ /** Keep the header pinned while the body scrolls (web `position: sticky`). */
41
+ stickyHeader?: boolean;
42
+ /** Make rows pressable (GRID.md `is-click`). Enables row accessibilityRole=button. */
43
+ onRowPress?: (row: T) => void;
44
+ /** Per-row accessibility label. Falls back to the kit's `rowLabel` translation. */
45
+ getRowAccessibilityLabel?: (row: T) => string;
46
+ loading?: boolean;
47
+ /** Loading text (already translated). Falls back to the kit's `loading` translation. */
48
+ loadingLabel?: string;
49
+ /** Empty text (already translated). Falls back to the kit's `empty` translation. */
50
+ emptyLabel?: string;
51
+ /** Below this width (px) rows collapse to a label:value card. Default 640. */
52
+ stackBreakpoint?: number;
53
+ testID?: string;
54
+ }
55
+
56
+ /**
57
+ * DataTable — the shared, tokenized RN-web grid for every dloizides.com surface
58
+ * (and the future AML v2 portal). Promoted from the POC draft; completes the
59
+ * `wwwroot/shared/GRID.md` behavioural contract in the RN idiom:
60
+ *
61
+ * - columns + rows API (unchanged from the POC — it is the right shape).
62
+ * - sticky header (`stickyHeader`), zebra striping (`zebra`), per-row tint.
63
+ * - a responsive label:value **card-stack** below `stackBreakpoint` via
64
+ * `useWindowDimensions` (the CSS `data-label` card-stack does not port).
65
+ * - per-row `testID` + `accessibilityLabel`/`accessibilityHint` (kit standard).
66
+ * - every colour from `useUi().theme`; every component-authored string via `t`.
67
+ */
68
+
69
+ declare function DataTable<T>(props: DataTableProps<T>): React.ReactElement;
70
+
71
+ /**
72
+ * FilterBar — the shared filter-bar shell from GRID.md (`.ui-filters`): a themed,
73
+ * wrapping row that holds the caller's filter fields, an optional live results
74
+ * count (`<b>N</b> results`) and an optional actions slot (Apply / Export …).
75
+ * Layout + theming only — the fields themselves come from the app (or @dloizides/
76
+ * ui-forms), keeping this reusable across every grid rather than coverage-specific.
77
+ */
78
+
79
+ interface FilterBarProps {
80
+ /** The filter fields (labels + inputs), supplied by the app / ui-forms. */
81
+ children?: React.ReactNode;
82
+ /** Live count shown as `<b>{resultsCount}</b> {results}`. Omit to hide. */
83
+ resultsCount?: number;
84
+ /** Overrides the kit's translated "results" word (pass an app-translated string). */
85
+ resultsLabel?: string;
86
+ /** Right-aligned action buttons (Apply, Export CSV, …). */
87
+ actions?: React.ReactNode;
88
+ testID?: string;
89
+ }
90
+ declare function FilterBar({ children, resultsCount, resultsLabel, actions, testID, }: FilterBarProps): React.ReactElement;
91
+
92
+ /**
93
+ * Pager — the shared pagination control from GRID.md (`.ui-pager`): page-info on
94
+ * the left (`from–to of N`), nav on the right (rows-per-page + Prev/Next). Sits ON
95
+ * TOP of the grid (in the section header row), so every paged grid looks the same.
96
+ * RN idiom: rows-per-page is a row of pressable pills (RN has no native `<select>`);
97
+ * everything is themed from `useUi().theme` and labelled via the UiProvider `t`.
98
+ */
99
+
100
+ interface PagerProps {
101
+ /** 1-based current page. */
102
+ page: number;
103
+ /** Rows per page. */
104
+ pageSize: number;
105
+ /** Total row count across all pages. */
106
+ total: number;
107
+ onPageChange: (page: number) => void;
108
+ onPageSizeChange: (pageSize: number) => void;
109
+ /** Rows-per-page choices. Default 25 / 50 / 100 / 200. */
110
+ pageSizeOptions?: readonly number[];
111
+ /**
112
+ * Optional, already-translated unit noun appended to the count line, e.g.
113
+ * `"leadership terms"` renders `1–50 of 3,023 leadership terms`. When omitted the
114
+ * count line stays the generic `from–to of N` (byte-identical to prior behaviour).
115
+ */
116
+ unitLabel?: string;
117
+ testID?: string;
118
+ }
119
+ declare function Pager({ page, pageSize, total, onPageChange, onPageSizeChange, pageSizeOptions, unitLabel, testID, }: PagerProps): React.ReactElement;
120
+
121
+ /**
122
+ * Shared constants for the DataTable family (DataTable / FilterBar / Pager).
123
+ * Keeps every literal (test ids, i18n keys, layout numbers) in one place so the
124
+ * components hold no magic numbers and no ad-hoc strings.
125
+ */
126
+ /** Default breakpoint (px): below this a row collapses to a label:value card. */
127
+ declare const CARD_STACK_BREAKPOINT = 640;
128
+ /** Default rows-per-page choices, matching the vanilla console's GRID.md pager. */
129
+ declare const DEFAULT_PAGE_SIZE_OPTIONS: readonly number[];
130
+ /** Stable test ids so consumers/e2e can target the shared chrome. */
131
+ declare const TABLE_TEST_IDS: {
132
+ readonly root: "ui-data-table";
133
+ readonly head: "ui-data-table-head";
134
+ readonly filterBar: "ui-filters";
135
+ readonly results: "ui-results";
136
+ readonly pager: "ui-pager";
137
+ readonly pagerInfo: "ui-pager-info";
138
+ readonly pagerPrev: "ui-pager-prev";
139
+ readonly pagerNext: "ui-pager-next";
140
+ };
141
+ /**
142
+ * Translation keys for every component-authored, user-facing string. Apps map
143
+ * these in their UiProvider `t` (FM); the neutral default `t` returns the key, so
144
+ * a host that forgets a key degrades to the key rather than a hardcoded literal.
145
+ */
146
+ declare const TABLE_I18N: {
147
+ readonly loading: "uiTables.loading";
148
+ readonly empty: "uiTables.empty";
149
+ readonly rowLabel: "uiTables.rowLabel";
150
+ readonly rowHint: "uiTables.rowHint";
151
+ readonly results: "uiTables.results";
152
+ readonly pagerInfo: "uiTables.pager.info";
153
+ readonly pagerPrev: "uiTables.pager.prev";
154
+ readonly pagerNext: "uiTables.pager.next";
155
+ readonly pagerPrevHint: "uiTables.pager.prevHint";
156
+ readonly pagerNextHint: "uiTables.pager.nextHint";
157
+ readonly pagerRows: "uiTables.pager.rows";
158
+ readonly pagerRowsOptionHint: "uiTables.pager.rowsOptionHint";
159
+ };
160
+
161
+ export { CARD_STACK_BREAKPOINT, DEFAULT_PAGE_SIZE_OPTIONS, DataTable, type DataTableColumn, type DataTableProps, FilterBar, type FilterBarProps, Pager, type PagerProps, StatCard, type StatCardProps, TABLE_I18N, TABLE_TEST_IDS };
package/dist/index.js CHANGED
@@ -49,6 +49,305 @@ var StatCard = react.memo(({ label, value, testID }) => {
49
49
  });
50
50
  StatCard.displayName = "StatCard";
51
51
 
52
+ // src/DataTable/constants.ts
53
+ var CARD_STACK_BREAKPOINT = 640;
54
+ var DEFAULT_PAGE_SIZE_OPTIONS = [25, 50, 100, 200];
55
+ var TABLE_TEST_IDS = {
56
+ root: "ui-data-table",
57
+ head: "ui-data-table-head",
58
+ filterBar: "ui-filters",
59
+ results: "ui-results",
60
+ pager: "ui-pager",
61
+ pagerInfo: "ui-pager-info",
62
+ pagerPrev: "ui-pager-prev",
63
+ pagerNext: "ui-pager-next"
64
+ };
65
+ var TABLE_I18N = {
66
+ loading: "uiTables.loading",
67
+ empty: "uiTables.empty",
68
+ rowLabel: "uiTables.rowLabel",
69
+ rowHint: "uiTables.rowHint",
70
+ results: "uiTables.results",
71
+ pagerInfo: "uiTables.pager.info",
72
+ pagerPrev: "uiTables.pager.prev",
73
+ pagerNext: "uiTables.pager.next",
74
+ pagerPrevHint: "uiTables.pager.prevHint",
75
+ pagerNextHint: "uiTables.pager.nextHint",
76
+ pagerRows: "uiTables.pager.rows",
77
+ pagerRowsOptionHint: "uiTables.pager.rowsOptionHint"
78
+ };
79
+ var BORDER_WIDTH = 1;
80
+ var BORDER_RADIUS = 12;
81
+ var COLUMN_GAP = 16;
82
+ var ROW_PAD_H = 14;
83
+ var ROW_PAD_V = 12;
84
+ var HEAD_PAD_V = 11;
85
+ var STATE_PAD_V = 34;
86
+ var HEAD_FONT = 12;
87
+ var CELL_FONT = 14;
88
+ var STATE_FONT = 14;
89
+ var CARD_LINE_PAD_V = 3;
90
+ var CARD_LINE_GAP = 12;
91
+ var PILL_RADIUS = 999;
92
+ var PAGER_GAP = 8;
93
+ var PAGER_SIZE_GAP = 6;
94
+ var CONTROL_PAD_H = 12;
95
+ var CONTROL_PAD_V = 6;
96
+ var CONTROL_FONT = 13;
97
+ var RESULTS_FONT = 13;
98
+ var HEAD_LETTER_SPACING = 0.4;
99
+ var LABEL_LETTER_SPACING = 0.3;
100
+ var STICKY_Z = 2;
101
+ var STICKY_HEADER_STYLE = {
102
+ position: "sticky",
103
+ top: 0,
104
+ zIndex: STICKY_Z
105
+ };
106
+ var tableStyles = reactNative.StyleSheet.create({
107
+ wrap: { borderWidth: BORDER_WIDTH, borderRadius: BORDER_RADIUS, overflow: "hidden" },
108
+ headRow: { flexDirection: "row", columnGap: COLUMN_GAP, paddingHorizontal: ROW_PAD_H, paddingVertical: HEAD_PAD_V },
109
+ headCell: { fontSize: HEAD_FONT, fontWeight: "600", letterSpacing: HEAD_LETTER_SPACING, textTransform: "uppercase" },
110
+ row: { flexDirection: "row", columnGap: COLUMN_GAP, alignItems: "center", paddingHorizontal: ROW_PAD_H, paddingVertical: ROW_PAD_V, borderTopWidth: BORDER_WIDTH },
111
+ cell: { fontSize: CELL_FONT, fontWeight: "400" },
112
+ numCell: { fontVariant: ["tabular-nums"], textAlign: "right" },
113
+ state: { paddingVertical: STATE_PAD_V, alignItems: "center" },
114
+ stateText: { fontSize: STATE_FONT },
115
+ card: { paddingHorizontal: ROW_PAD_H, paddingVertical: ROW_PAD_V, borderTopWidth: BORDER_WIDTH },
116
+ cardLine: { flexDirection: "row", justifyContent: "space-between", alignItems: "baseline", paddingVertical: CARD_LINE_PAD_V, gap: CARD_LINE_GAP },
117
+ cardLabel: { fontSize: HEAD_FONT, fontWeight: "600", textTransform: "uppercase", letterSpacing: LABEL_LETTER_SPACING },
118
+ cardValue: { flexShrink: 1, alignItems: "flex-end" }
119
+ });
120
+ var chromeStyles = reactNative.StyleSheet.create({
121
+ filters: { flexDirection: "row", flexWrap: "wrap", alignItems: "flex-end", columnGap: COLUMN_GAP, rowGap: PAGER_GAP, borderWidth: BORDER_WIDTH, borderRadius: BORDER_RADIUS, paddingHorizontal: ROW_PAD_H, paddingVertical: ROW_PAD_V },
122
+ filtersSpacer: { flexGrow: 1 },
123
+ results: { fontSize: RESULTS_FONT },
124
+ filtersActions: { flexDirection: "row", gap: PAGER_SIZE_GAP, alignItems: "center" },
125
+ pager: { flexDirection: "row", flexWrap: "wrap", alignItems: "center", justifyContent: "space-between", gap: PAGER_GAP },
126
+ pagerInfo: { fontSize: CONTROL_FONT, fontVariant: ["tabular-nums"] },
127
+ pagerNav: { flexDirection: "row", alignItems: "center", gap: PAGER_SIZE_GAP, flexWrap: "wrap" },
128
+ pagerRowsLabel: { fontSize: HEAD_FONT, textTransform: "uppercase", letterSpacing: LABEL_LETTER_SPACING },
129
+ sizeGroup: { flexDirection: "row", gap: PAGER_SIZE_GAP, alignItems: "center" },
130
+ control: { paddingHorizontal: CONTROL_PAD_H, paddingVertical: CONTROL_PAD_V, borderRadius: BORDER_RADIUS, borderWidth: BORDER_WIDTH },
131
+ controlText: { fontSize: CONTROL_FONT, fontWeight: "600" },
132
+ sizePill: { paddingHorizontal: CONTROL_PAD_H, paddingVertical: CONTROL_PAD_V, borderRadius: PILL_RADIUS, borderWidth: BORDER_WIDTH },
133
+ sizePillText: { fontSize: HEAD_FONT, fontWeight: "600", fontVariant: ["tabular-nums"] }
134
+ });
135
+ var FIRST_ROW_INDEX = 0;
136
+ function DesktopCell({ column, row, textColor, testID }) {
137
+ const content = column.render(row);
138
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: { flex: column.weight ?? 1, alignItems: column.numeric ? "flex-end" : "flex-start" }, testID, children: typeof content === "string" ? /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [tableStyles.cell, column.numeric ? tableStyles.numCell : null, { color: textColor }], children: content }) : content });
139
+ }
140
+ function DataTable(props) {
141
+ const {
142
+ columns,
143
+ rows,
144
+ keyExtractor,
145
+ rowTint,
146
+ zebra,
147
+ stickyHeader,
148
+ onRowPress,
149
+ getRowAccessibilityLabel,
150
+ loading,
151
+ loadingLabel,
152
+ emptyLabel,
153
+ stackBreakpoint = CARD_STACK_BREAKPOINT,
154
+ testID = TABLE_TEST_IDS.root
155
+ } = props;
156
+ const { theme, t } = uiFeedback.useUi();
157
+ const { colors } = theme;
158
+ const { width } = reactNative.useWindowDimensions();
159
+ const stacked = width < stackBreakpoint;
160
+ const frame = { backgroundColor: colors.surface, borderColor: colors.border };
161
+ const rowBackground = react.useCallback(
162
+ (row, index) => {
163
+ const tint = rowTint?.(row);
164
+ if (tint) return tint;
165
+ return zebra && index % 2 === 1 ? colors.background : void 0;
166
+ },
167
+ [rowTint, zebra, colors.background]
168
+ );
169
+ if (loading) {
170
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [tableStyles.wrap, frame], testID, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: tableStyles.state, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [tableStyles.stateText, { color: colors.textSecondary }], children: loadingLabel ?? t(TABLE_I18N.loading) }) }) });
171
+ }
172
+ if (rows.length === 0) {
173
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [tableStyles.wrap, frame], testID, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: tableStyles.state, children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [tableStyles.stateText, { color: colors.textSecondary }], children: emptyLabel ?? t(TABLE_I18N.empty) }) }) });
174
+ }
175
+ const rowTestID = (key) => `${testID}-row-${key}`;
176
+ const rowA11y = (row) => ({
177
+ accessibilityLabel: getRowAccessibilityLabel?.(row) ?? t(TABLE_I18N.rowLabel),
178
+ accessibilityHint: t(TABLE_I18N.rowHint),
179
+ accessibilityRole: onRowPress ? "button" : "text"
180
+ });
181
+ if (stacked) {
182
+ return /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: [tableStyles.wrap, frame], testID, children: rows.map((row, i) => {
183
+ const key = keyExtractor(row);
184
+ const bg = rowBackground(row, i);
185
+ return /* @__PURE__ */ jsxRuntime.jsx(
186
+ reactNative.Pressable,
187
+ {
188
+ testID: rowTestID(key),
189
+ disabled: !onRowPress,
190
+ onPress: onRowPress ? () => onRowPress(row) : void 0,
191
+ ...rowA11y(row),
192
+ style: [tableStyles.card, { borderTopColor: colors.border }, i === FIRST_ROW_INDEX ? { borderTopWidth: 0 } : null, bg ? { backgroundColor: bg } : null],
193
+ children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: tableStyles.cardLine, children: [
194
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [tableStyles.cardLabel, { color: colors.textSecondary }], children: col.header }),
195
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: tableStyles.cardValue, children: col.render(row) })
196
+ ] }, col.key))
197
+ },
198
+ key
199
+ );
200
+ }) });
201
+ }
202
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [tableStyles.wrap, frame], testID, children: [
203
+ /* @__PURE__ */ jsxRuntime.jsx(
204
+ reactNative.View,
205
+ {
206
+ testID: TABLE_TEST_IDS.head,
207
+ style: [tableStyles.headRow, { backgroundColor: colors.background }, stickyHeader ? STICKY_HEADER_STYLE : null],
208
+ children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx(
209
+ reactNative.Text,
210
+ {
211
+ style: [tableStyles.headCell, { color: colors.textSecondary, flex: col.weight ?? 1, textAlign: col.numeric ? "right" : "left" }],
212
+ children: col.header
213
+ },
214
+ col.key
215
+ ))
216
+ }
217
+ ),
218
+ rows.map((row, i) => {
219
+ const key = keyExtractor(row);
220
+ const bg = rowBackground(row, i);
221
+ return /* @__PURE__ */ jsxRuntime.jsx(
222
+ reactNative.Pressable,
223
+ {
224
+ testID: rowTestID(key),
225
+ disabled: !onRowPress,
226
+ onPress: onRowPress ? () => onRowPress(row) : void 0,
227
+ ...rowA11y(row),
228
+ style: [tableStyles.row, { borderTopColor: colors.border }, bg ? { backgroundColor: bg } : null],
229
+ children: columns.map((col) => /* @__PURE__ */ jsxRuntime.jsx(DesktopCell, { column: col, row, textColor: colors.text, testID: `${rowTestID(key)}-${col.key}` }, col.key))
230
+ },
231
+ key
232
+ );
233
+ })
234
+ ] });
235
+ }
236
+ function FilterBar({
237
+ children,
238
+ resultsCount,
239
+ resultsLabel,
240
+ actions,
241
+ testID = TABLE_TEST_IDS.filterBar
242
+ }) {
243
+ const { theme, t } = uiFeedback.useUi();
244
+ const { colors } = theme;
245
+ const word = resultsLabel ?? t(TABLE_I18N.results);
246
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: [chromeStyles.filters, { backgroundColor: colors.surface, borderColor: colors.border }], testID, children: [
247
+ children,
248
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: chromeStyles.filtersSpacer }),
249
+ typeof resultsCount === "number" && /* @__PURE__ */ jsxRuntime.jsxs(reactNative.Text, { style: [chromeStyles.results, { color: colors.textSecondary }], testID: TABLE_TEST_IDS.results, children: [
250
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: { color: colors.text, fontWeight: "700" }, children: resultsCount.toLocaleString() }),
251
+ ` ${word}`
252
+ ] }),
253
+ !!actions && /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: chromeStyles.filtersActions, children: actions })
254
+ ] });
255
+ }
256
+ var FIRST_PAGE = 1;
257
+ var EN_DASH = "\u2013";
258
+ function NavButton({ label, hint, disabled, onPress, color, border, testID }) {
259
+ const DISABLED_OPACITY = 0.4;
260
+ return /* @__PURE__ */ jsxRuntime.jsx(
261
+ reactNative.Pressable,
262
+ {
263
+ testID,
264
+ accessibilityRole: "button",
265
+ accessibilityLabel: label,
266
+ accessibilityHint: hint,
267
+ accessibilityState: { disabled },
268
+ disabled,
269
+ onPress,
270
+ style: [chromeStyles.control, { borderColor: border, opacity: disabled ? DISABLED_OPACITY : 1 }],
271
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [chromeStyles.controlText, { color }], children: label })
272
+ }
273
+ );
274
+ }
275
+ function Pager({
276
+ page,
277
+ pageSize,
278
+ total,
279
+ onPageChange,
280
+ onPageSizeChange,
281
+ pageSizeOptions = DEFAULT_PAGE_SIZE_OPTIONS,
282
+ unitLabel,
283
+ testID = TABLE_TEST_IDS.pager
284
+ }) {
285
+ const { theme, t } = uiFeedback.useUi();
286
+ const { colors, palette } = theme;
287
+ const brand = palette.primary["500"];
288
+ const lastPage = Math.max(FIRST_PAGE, Math.ceil(total / pageSize));
289
+ const safePage = Math.min(Math.max(page, FIRST_PAGE), lastPage);
290
+ const from = total === 0 ? 0 : (safePage - 1) * pageSize + 1;
291
+ const to = Math.min(safePage * pageSize, total);
292
+ const count = `${from.toLocaleString()}${EN_DASH}${to.toLocaleString()} ${t(TABLE_I18N.pagerInfo)} ${total.toLocaleString()}`;
293
+ const hasUnit = unitLabel !== void 0 && unitLabel !== "";
294
+ const info = hasUnit ? `${count} ${unitLabel}` : count;
295
+ return /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: chromeStyles.pager, testID, children: [
296
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [chromeStyles.pagerInfo, { color: colors.textSecondary }], testID: TABLE_TEST_IDS.pagerInfo, children: info }),
297
+ /* @__PURE__ */ jsxRuntime.jsxs(reactNative.View, { style: chromeStyles.pagerNav, children: [
298
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [chromeStyles.pagerRowsLabel, { color: colors.textSecondary }], children: t(TABLE_I18N.pagerRows) }),
299
+ /* @__PURE__ */ jsxRuntime.jsx(reactNative.View, { style: chromeStyles.sizeGroup, children: pageSizeOptions.map((size) => {
300
+ const active = size === pageSize;
301
+ return /* @__PURE__ */ jsxRuntime.jsx(
302
+ reactNative.Pressable,
303
+ {
304
+ testID: `${testID}-size-${size}`,
305
+ accessibilityRole: "button",
306
+ accessibilityLabel: String(size),
307
+ accessibilityHint: t(TABLE_I18N.pagerRowsOptionHint),
308
+ accessibilityState: { selected: active },
309
+ onPress: () => onPageSizeChange(size),
310
+ style: [chromeStyles.sizePill, { borderColor: active ? brand : colors.border, backgroundColor: active ? brand : "transparent" }],
311
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [chromeStyles.sizePillText, { color: active ? colors.surface : colors.textSecondary }], children: size })
312
+ },
313
+ size
314
+ );
315
+ }) }),
316
+ /* @__PURE__ */ jsxRuntime.jsx(
317
+ NavButton,
318
+ {
319
+ label: t(TABLE_I18N.pagerPrev),
320
+ hint: t(TABLE_I18N.pagerPrevHint),
321
+ disabled: safePage <= FIRST_PAGE,
322
+ onPress: () => onPageChange(safePage - 1),
323
+ color: colors.text,
324
+ border: colors.border,
325
+ testID: TABLE_TEST_IDS.pagerPrev
326
+ }
327
+ ),
328
+ /* @__PURE__ */ jsxRuntime.jsx(
329
+ NavButton,
330
+ {
331
+ label: t(TABLE_I18N.pagerNext),
332
+ hint: t(TABLE_I18N.pagerNextHint),
333
+ disabled: safePage >= lastPage,
334
+ onPress: () => onPageChange(safePage + 1),
335
+ color: colors.text,
336
+ border: colors.border,
337
+ testID: TABLE_TEST_IDS.pagerNext
338
+ }
339
+ )
340
+ ] })
341
+ ] });
342
+ }
343
+
344
+ exports.CARD_STACK_BREAKPOINT = CARD_STACK_BREAKPOINT;
345
+ exports.DEFAULT_PAGE_SIZE_OPTIONS = DEFAULT_PAGE_SIZE_OPTIONS;
346
+ exports.DataTable = DataTable;
347
+ exports.FilterBar = FilterBar;
348
+ exports.Pager = Pager;
52
349
  exports.StatCard = StatCard;
350
+ exports.TABLE_I18N = TABLE_I18N;
351
+ exports.TABLE_TEST_IDS = TABLE_TEST_IDS;
53
352
  //# sourceMappingURL=index.js.map
54
353
  //# sourceMappingURL=index.js.map