@xeplr/ui-table 1.1.7 → 1.1.8
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 +3 -0
- package/package.json +1 -1
- package/src/index.js +5 -1
- package/src/renderers/index.js +4 -2
- package/src/renderers/trend.jsx +33 -0
- package/src/trend.js +41 -0
- package/src/xeplr-table.css +2 -0
package/README.md
CHANGED
|
@@ -231,6 +231,9 @@ Numeric strings compare as numbers. A host `cellStyle` prop result is merged ove
|
|
|
231
231
|
| `statusBadge` | `map: { value: { bg, color, border?, label? } }`, `default` | text |
|
|
232
232
|
| `dateDisplay` | `format`: `'date'` (`15 Sep 2026`), `'datetime'`, `'relative'` (`3h ago`, dates after 30 days) | Date or ISO string |
|
|
233
233
|
| `link` | `hrefKey` (renders `<a href={row[hrefKey]}>`) and `target`, or `onClick(row)` | text |
|
|
234
|
+
| `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 |
|
|
235
|
+
|
|
236
|
+
**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
237
|
|
|
235
238
|
Each renderer is `(config) => (ctx) => node`. The `renderers` object is the registry the table reads, so `renderers.myType = (config) => (ctx) => …` adds one.
|
|
236
239
|
|
package/package.json
CHANGED
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/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
|
+
}
|
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; }
|