@xeplr/ui-table 1.1.7 → 1.1.9
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/README.md +4 -0
- package/package.json +1 -1
- package/src/XeplrTable.jsx +8 -3
- package/src/index.js +5 -1
- package/src/pinRows.js +10 -0
- package/src/renderers/index.js +4 -2
- package/src/renderers/trend.jsx +33 -0
- package/src/trend.js +41 -0
- package/src/useTableController.js +13 -1
- package/src/xeplr-table.css +2 -0
package/README.md
CHANGED
|
@@ -59,6 +59,7 @@ The package ships its `src/` as ES modules with JSX and imports its own styleshe
|
|
|
59
59
|
| `toolbarLeading` | — | `(ctx) => node` after the built-in toolbar buttons |
|
|
60
60
|
| `toolbarActions` | — | `(ctx) => node` replacing Clear Filters / Clear Sort |
|
|
61
61
|
| `rowClassName` | — | `(row) => string` |
|
|
62
|
+
| `pinBottomRows` | — | `(row) => boolean` — rows kept at the **bottom of every page**, whatever is sorted, filtered or paged (a grand total: the last row of the data, which with pages was on the last page only). Drawn like any row (`rowClassName` still applies) after the page's own rows; TanStack row pinning with `keepPinnedRows` |
|
|
62
63
|
| `columnClassName` | — | `(column, index) => string`, applied to the header and every cell of that column |
|
|
63
64
|
| `cellStyle` | — | `({ row, rowIndex, columnKey, value }) => style` — on top of the schema's conditional styles |
|
|
64
65
|
| `headerStyle` | — | `({ columnKey, isGroupHeader, depth }) => style` |
|
|
@@ -231,6 +232,9 @@ Numeric strings compare as numbers. A host `cellStyle` prop result is merged ove
|
|
|
231
232
|
| `statusBadge` | `map: { value: { bg, color, border?, label? } }`, `default` | text |
|
|
232
233
|
| `dateDisplay` | `format`: `'date'` (`15 Sep 2026`), `'datetime'`, `'relative'` (`3h ago`, dates after 30 days) | Date or ISO string |
|
|
233
234
|
| `link` | `hrefKey` (renders `<a href={row[hrefKey]}>`) and `target`, or `onClick(row)` | text |
|
|
235
|
+
| `trend` | `format(value, row)` (how the number reads: a percent, a currency …), `absolute` (true: the arrow says the sign, so the number is shown without it), `color(value, row)` (a rule's colour, which wins), `colors` (`{ up, down }`) | number — ▲ green above zero, ▼ red below, nothing for zero or a blank |
|
|
236
|
+
|
|
237
|
+
**A trend** is one look everywhere: `trendOf(value)` (`'up'`, `'down'` or null), `trendLook(value, ruledColor?, colors?)` → `{ arrow, color }` and `TREND_COLORS` are exported, so a host that shows a single value as a trend (a KPI, a tile) draws it exactly as the `trend` cell does. A rule's colour wins over green/red — that is how "down is good" is said (a refund rate).
|
|
234
238
|
|
|
235
239
|
Each renderer is `(config) => (ctx) => node`. The `renderers` object is the registry the table reads, so `renderers.myType = (config) => (ctx) => …` adds one.
|
|
236
240
|
|
package/package.json
CHANGED
package/src/XeplrTable.jsx
CHANGED
|
@@ -186,13 +186,18 @@ export default function XeplrTable(props) {
|
|
|
186
186
|
sorting: props.sorting,
|
|
187
187
|
onSortingChange: props.onSortingChange,
|
|
188
188
|
enableFiltering: props.enableFiltering,
|
|
189
|
-
enablePagination: props.enablePagination
|
|
189
|
+
enablePagination: props.enablePagination,
|
|
190
|
+
// (row) → true for a row kept at the bottom of every page — a grand total.
|
|
191
|
+
pinBottomRows: props.pinBottomRows
|
|
190
192
|
});
|
|
191
193
|
|
|
192
194
|
var enableFiltering = props.enableFiltering !== false;
|
|
193
195
|
var enablePagination = props.enablePagination !== false;
|
|
194
196
|
var headerGroups = table.getHeaderGroups();
|
|
195
|
-
|
|
197
|
+
// Rows the host pins to the bottom (pinBottomRows — a grand total) are
|
|
198
|
+
// drawn after every page's rows; the page's own rows are the rest.
|
|
199
|
+
var pinned = table.getBottomRows ? table.getBottomRows() : [];
|
|
200
|
+
var rows = pinned.length ? table.getCenterRows() : table.getRowModel().rows;
|
|
196
201
|
|
|
197
202
|
// A consumer that wants a frozen header opts in with its own CSS
|
|
198
203
|
// (`position: sticky; top: 0` on .xeplr-table-th) — this component has no
|
|
@@ -595,7 +600,7 @@ export default function XeplrTable(props) {
|
|
|
595
600
|
<td className="xeplr-table-empty" colSpan={totalColumns}>No data</td>
|
|
596
601
|
</tr>
|
|
597
602
|
)}
|
|
598
|
-
{rows.map(function(row) {
|
|
603
|
+
{rows.concat(pinned).map(function(row) {
|
|
599
604
|
var original = row.original;
|
|
600
605
|
var rowId = getRowId(original);
|
|
601
606
|
var isSelected = actions.selectedIds.has(rowId);
|
package/src/index.js
CHANGED
|
@@ -47,4 +47,8 @@ export {
|
|
|
47
47
|
|
|
48
48
|
// Cell renderers (config-driven)
|
|
49
49
|
export { default as renderers } from './renderers/index.js';
|
|
50
|
-
export { avatarName, tags, currency, memberChips, twoLine, statusBadge, dateDisplay, link } from './renderers/index.js';
|
|
50
|
+
export { avatarName, tags, currency, memberChips, twoLine, statusBadge, dateDisplay, link, trend } from './renderers/index.js';
|
|
51
|
+
|
|
52
|
+
// A number shown as a trend (▲ green up, ▼ red down) — the `trend` renderer's,
|
|
53
|
+
// and any host's that shows one value as a trend, so every trend looks alike.
|
|
54
|
+
export { trendOf, trendLook, TREND_COLORS } from './trend.js';
|
package/src/pinRows.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// WHICH ROWS ARE KEPT AT THE BOTTOM OF EVERY PAGE — `pinBottomRows(row)`
|
|
2
|
+
// answered for each row of `data`, as TanStack's row ids (a top-level row's
|
|
3
|
+
// id is its position in `data`). A grand total is the usual one: the last row
|
|
4
|
+
// of the data, which with pages would otherwise be on the last page only.
|
|
5
|
+
export function bottomRowIds(data, pinBottomRows) {
|
|
6
|
+
if (typeof pinBottomRows !== 'function') return [];
|
|
7
|
+
var ids = [];
|
|
8
|
+
(data || []).forEach(function (row, i) { if (pinBottomRows(row)) ids.push(String(i)); });
|
|
9
|
+
return ids;
|
|
10
|
+
}
|
package/src/renderers/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import twoLine from './twoLine.jsx';
|
|
|
6
6
|
import statusBadge from './statusBadge.jsx';
|
|
7
7
|
import dateDisplay from './dateDisplay.jsx';
|
|
8
8
|
import link from './link.jsx';
|
|
9
|
+
import trend from './trend.jsx';
|
|
9
10
|
|
|
10
11
|
var renderers = {
|
|
11
12
|
avatarName: avatarName,
|
|
@@ -15,8 +16,9 @@ var renderers = {
|
|
|
15
16
|
twoLine: twoLine,
|
|
16
17
|
statusBadge: statusBadge,
|
|
17
18
|
dateDisplay: dateDisplay,
|
|
18
|
-
link: link
|
|
19
|
+
link: link,
|
|
20
|
+
trend: trend
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
export default renderers;
|
|
22
|
-
export { avatarName, tags, currency, memberChips, twoLine, statusBadge, dateDisplay, link };
|
|
24
|
+
export { avatarName, tags, currency, memberChips, twoLine, statusBadge, dateDisplay, link, trend };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { trendLook } from '../trend.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A number with its direction: ▲ green above zero, ▼ red below (trend.js).
|
|
5
|
+
*
|
|
6
|
+
* config: {
|
|
7
|
+
* format?: (value, row) => string how the number reads (a percent, a
|
|
8
|
+
* currency …); default: up to 2 decimals
|
|
9
|
+
* absolute?: boolean the arrow says the sign, so the number
|
|
10
|
+
* is shown without it (default true)
|
|
11
|
+
* color?: (value, row) => string a rule's colour, which wins
|
|
12
|
+
* colors?: { up, down } the defaults' replacement
|
|
13
|
+
* }
|
|
14
|
+
*/
|
|
15
|
+
export default function trend(config) {
|
|
16
|
+
var c = config || {};
|
|
17
|
+
var absolute = c.absolute !== false;
|
|
18
|
+
return function cell(ctx) {
|
|
19
|
+
var v = ctx.getValue();
|
|
20
|
+
if (v === null || v === undefined || v === '') return null;
|
|
21
|
+
var row = ctx.row && ctx.row.original;
|
|
22
|
+
var n = Number(v);
|
|
23
|
+
var shown = absolute && Number.isFinite(n) ? Math.abs(n) : v;
|
|
24
|
+
var text = c.format ? c.format(shown, row) : (Number.isFinite(Number(shown)) ? Number(shown).toLocaleString(undefined, { maximumFractionDigits: 2 }) : String(shown));
|
|
25
|
+
var look = trendLook(v, c.color ? c.color(v, row) : null, c.colors);
|
|
26
|
+
return (
|
|
27
|
+
<span className="xeplr-r-trend" style={look.color ? { color: look.color } : undefined}>
|
|
28
|
+
{look.arrow && <span className="xeplr-r-trend-arrow" aria-hidden="true">{look.arrow}</span>}
|
|
29
|
+
{text}
|
|
30
|
+
</span>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
}
|
package/src/trend.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// A NUMBER SHOWN AS A TREND — its own sign says which way it went: ▲ above
|
|
2
|
+
// zero, ▼ below. Zero, a blank or something that is not a number has no
|
|
3
|
+
// direction, so it gets no arrow and no colour.
|
|
4
|
+
//
|
|
5
|
+
// The colour: green up, red down — unless the caller's rule coloured the value
|
|
6
|
+
// (`ruledColor`), which wins. That is how "green when negative" is said: for a
|
|
7
|
+
// refund rate, down is good.
|
|
8
|
+
//
|
|
9
|
+
// Used by the `trend` cell renderer, and by any host that shows one value as a
|
|
10
|
+
// trend (a KPI, a tile) so every trend looks the same.
|
|
11
|
+
|
|
12
|
+
export var TREND_COLORS = { up: '#1a7f37', down: '#c2372e' };
|
|
13
|
+
var ARROWS = { up: '▲', down: '▼' };
|
|
14
|
+
|
|
15
|
+
function asNumber(value) {
|
|
16
|
+
if (typeof value === 'number') return Number.isFinite(value) ? value : null;
|
|
17
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
18
|
+
var n = Number(value);
|
|
19
|
+
return Number.isFinite(n) ? n : null;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** 'up', 'down', or null when the value has no direction. */
|
|
25
|
+
export function trendOf(value) {
|
|
26
|
+
var n = asNumber(value);
|
|
27
|
+
if (n === null || n === 0) return null;
|
|
28
|
+
return n > 0 ? 'up' : 'down';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* What a value shown as a trend looks like: { arrow, color } — the rule's
|
|
33
|
+
* colour when one coloured it, the default for its direction otherwise;
|
|
34
|
+
* { arrow: null, color: ruledColor } when it has no direction.
|
|
35
|
+
*/
|
|
36
|
+
export function trendLook(value, ruledColor, colors) {
|
|
37
|
+
var dir = trendOf(value);
|
|
38
|
+
var palette = colors || TREND_COLORS;
|
|
39
|
+
if (!dir) return { arrow: null, color: ruledColor || null };
|
|
40
|
+
return { arrow: ARROWS[dir], color: ruledColor || palette[dir] };
|
|
41
|
+
}
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
createColumnHelper
|
|
11
11
|
} from '@tanstack/react-table';
|
|
12
12
|
import { detectTypes, TYPES } from './detectTypes.js';
|
|
13
|
+
import { bottomRowIds } from './pinRows.js';
|
|
13
14
|
import { stringFilterFn } from './filters/StringFilter.jsx';
|
|
14
15
|
import { numberFilterFn } from './filters/NumberFilter.jsx';
|
|
15
16
|
import { dateFilterFn } from './filters/DateFilter.jsx';
|
|
@@ -155,6 +156,14 @@ export default function useTableController(options) {
|
|
|
155
156
|
var [columnFilters, setColumnFilters] = useState([]);
|
|
156
157
|
var [pagination, setPagination] = useState({ pageIndex: 0, pageSize: pageSize });
|
|
157
158
|
|
|
159
|
+
// ROWS KEPT AT THE BOTTOM OF EVERY PAGE (`pinBottomRows(row) → boolean`):
|
|
160
|
+
// a grand total is the last row of the data, so with pages it was on the
|
|
161
|
+
// last page only. Pinned, it is drawn under every page's rows and stays
|
|
162
|
+
// there whatever is sorted or filtered (TanStack row pinning,
|
|
163
|
+
// keepPinnedRows). By the row's position in `data`, TanStack's own id.
|
|
164
|
+
var pinBottomRows = options.pinBottomRows;
|
|
165
|
+
var bottomIds = useMemo(function () { return bottomRowIds(data, pinBottomRows); }, [data, pinBottomRows]);
|
|
166
|
+
|
|
158
167
|
// ── TanStack table instance ──
|
|
159
168
|
var table = useReactTable({
|
|
160
169
|
data: data,
|
|
@@ -162,8 +171,11 @@ export default function useTableController(options) {
|
|
|
162
171
|
state: {
|
|
163
172
|
sorting: sorting,
|
|
164
173
|
columnFilters: columnFilters,
|
|
165
|
-
pagination: pagination
|
|
174
|
+
pagination: pagination,
|
|
175
|
+
rowPinning: { top: [], bottom: bottomIds }
|
|
166
176
|
},
|
|
177
|
+
enableRowPinning: bottomIds.length > 0,
|
|
178
|
+
keepPinnedRows: true,
|
|
167
179
|
onSortingChange: setSorting,
|
|
168
180
|
onColumnFiltersChange: setColumnFilters,
|
|
169
181
|
onPaginationChange: setPagination,
|
package/src/xeplr-table.css
CHANGED
|
@@ -1025,6 +1025,8 @@
|
|
|
1025
1025
|
.xeplr-r-tag-more { color: var(--xeplr-text-secondary, #8a93b8); font-size: 11px; align-self: center; }
|
|
1026
1026
|
|
|
1027
1027
|
/* currency */
|
|
1028
|
+
.xeplr-r-trend { display: inline-flex; align-items: baseline; gap: 4px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
|
|
1029
|
+
.xeplr-r-trend-arrow { font-size: 0.8em; }
|
|
1028
1030
|
.xeplr-r-currency { display: inline-flex; align-items: baseline; gap: 2px; }
|
|
1029
1031
|
.xeplr-r-currency-bold { font-weight: 700; color: var(--xeplr-text-primary, #e6e9f5); }
|
|
1030
1032
|
.xeplr-r-currency-sym { color: var(--xeplr-text-secondary, #8a93b8); font-size: 0.92em; }
|