@molecule/app-reputation-badge-react 3.0.0 → 4.0.1
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 -3
- package/dist/BadgeShelf.js +1 -1
- package/dist/ReputationBadge.d.ts.map +1 -1
- package/dist/ReputationBadge.js +35 -12
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-
|
|
6
|
+
Generated: 2026-11-12T04:41:28.255Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-reputation-badge-react
|
|
@@ -274,9 +274,9 @@ const DEFAULT_THRESHOLDS: ReputationThresholds
|
|
|
274
274
|
|
|
275
275
|
Peer dependencies:
|
|
276
276
|
|
|
277
|
-
- `@molecule/app-react` ^
|
|
277
|
+
- `@molecule/app-react` ^4.0.0
|
|
278
278
|
- `@molecule/app-ui` ^1.0.1
|
|
279
|
-
- `@molecule/app-ui-react` ^
|
|
279
|
+
- `@molecule/app-ui-react` ^4.0.0
|
|
280
280
|
- `react` ^18.0.0 || ^19.0.0
|
|
281
281
|
|
|
282
282
|
### Runtime Dependencies
|
package/dist/BadgeShelf.js
CHANGED
|
@@ -26,6 +26,6 @@ export function BadgeShelf({ badges, limit = 5, onClick, className, }) {
|
|
|
26
26
|
const tooltip = badge.description ? `${badge.name} — ${badge.description}` : badge.name;
|
|
27
27
|
const interactive = typeof onClick === 'function';
|
|
28
28
|
const content = badge.iconSrc ? (_jsx("img", { src: badge.iconSrc, alt: "", className: cm.cn(cm.shrink0), style: { width: 24, height: 24 }, "data-mol-id": "badge-shelf-icon-img" })) : (_jsx("span", { "aria-hidden": "true", "data-mol-id": "badge-shelf-icon-glyph", children: badge.icon ?? '*' }));
|
|
29
|
-
return (_jsx("li", { className: cm.cn(cm.flex({ align: 'center', justify: 'center' })), "data-mol-id": "badge-shelf-item", "data-badge-id": badge.id, children: interactive ? (_jsx("button", { type: "button", className: cm.cn(cm.flex({ align: 'center', justify: 'center' }), cm.roundedFull), onClick: () => onClick?.(badge), title: tooltip, "aria-label": badge.name, "data-mol-id": "badge-shelf-button", children: content })) : (_jsx("span", { title: tooltip, "aria-label": badge.name, children: content })) }, badge.id));
|
|
29
|
+
return (_jsx("li", { className: cm.cn(cm.flex({ align: 'center', justify: 'center' })), "data-mol-id": "badge-shelf-item", "data-badge-id": badge.id, children: interactive ? (_jsx("button", { type: "button", className: cm.cn(cm.flex({ align: 'center', justify: 'center' }), cm.roundedFull), onClick: () => onClick?.(badge), title: tooltip, "aria-label": badge.name, "data-mol-id": "badge-shelf-button", children: content })) : (_jsx("span", { title: tooltip, "aria-label": badge.name, role: "img", children: content })) }, badge.id));
|
|
30
30
|
}), overflow > 0 && (_jsx("li", { className: cm.cn(cm.flex({ align: 'center', justify: 'center' })), "data-mol-id": "badge-shelf-overflow", children: typeof onClick === 'function' ? (_jsxs("button", { type: "button", className: cm.cn(cm.flex({ align: 'center', justify: 'center' }), cm.roundedFull, cm.textSize('xs'), cm.fontWeight('semibold')), onClick: () => onClick(null), "aria-label": t('badgeShelf.overflow.aria', { count: overflow }, { defaultValue: 'Show {{count}} more badges' }), "data-mol-id": "badge-shelf-overflow-button", children: ["+", overflow] })) : (_jsxs("span", { className: cm.cn(cm.textSize('xs'), cm.fontWeight('semibold')), "aria-label": t('badgeShelf.overflow.aria', { count: overflow }, { defaultValue: 'Show {{count}} more badges' }), children: ["+", overflow] })) }))] }));
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReputationBadge.d.ts","sourceRoot":"","sources":["../src/ReputationBadge.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAO9B,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"ReputationBadge.d.ts","sourceRoot":"","sources":["../src/ReputationBadge.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAO9B,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAqCvE,+DAA+D;AAC/D,MAAM,WAAW,oBAAoB;IACnC,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,KAAK,CAAC,EAAE,eAAe,CAAA;IACvB,qDAAqD;IACrD,UAAU,CAAC,EAAE,oBAAoB,CAAA;IACjC;;;;OAIG;IACH,OAAO,CAAC,EAAE,SAAS,GAAG,MAAM,CAAA;IAC5B,mDAAmD;IACnD,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,KAAK,EACL,UAA+B,EAC/B,OAAmB,EACnB,SAAS,GACV,EAAE,oBAAoB,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAmD1C"}
|
package/dist/ReputationBadge.js
CHANGED
|
@@ -3,6 +3,37 @@ import { useTranslation } from '@molecule/app-react';
|
|
|
3
3
|
import { getClassMap } from '@molecule/app-ui';
|
|
4
4
|
import { Badge } from '@molecule/app-ui-react';
|
|
5
5
|
import { colorForLevel, DEFAULT_THRESHOLDS, levelForScore } from './levels.js';
|
|
6
|
+
/**
|
|
7
|
+
* Resolve a level's translated label through one LITERAL i18n key per
|
|
8
|
+
* in-contract level, and the literal `reputationBadge.level.fallback` key (its
|
|
9
|
+
* English is the bare `{{level}}` placeholder, so an unknown id renders as
|
|
10
|
+
* itself) for anything else.
|
|
11
|
+
*
|
|
12
|
+
* Keys are literals, never built from the level id: the i18n gate
|
|
13
|
+
* (`scripts/check-i18n-parity.js`) can only see literal keys, so a key built at
|
|
14
|
+
* runtime that no locale bond carries leaves every non-English user on English
|
|
15
|
+
* with nothing reporting it.
|
|
16
|
+
*
|
|
17
|
+
* @param t - The bonded translate function.
|
|
18
|
+
* @param level - The level id (may be out of contract).
|
|
19
|
+
* @returns The translated label.
|
|
20
|
+
*/
|
|
21
|
+
function levelLabel(t, level) {
|
|
22
|
+
switch (level) {
|
|
23
|
+
case 'newcomer':
|
|
24
|
+
return t('reputationBadge.level.newcomer', {}, { defaultValue: 'Newcomer' });
|
|
25
|
+
case 'contributor':
|
|
26
|
+
return t('reputationBadge.level.contributor', {}, { defaultValue: 'Contributor' });
|
|
27
|
+
case 'trusted':
|
|
28
|
+
return t('reputationBadge.level.trusted', {}, { defaultValue: 'Trusted' });
|
|
29
|
+
case 'veteran':
|
|
30
|
+
return t('reputationBadge.level.veteran', {}, { defaultValue: 'Veteran' });
|
|
31
|
+
case 'legend':
|
|
32
|
+
return t('reputationBadge.level.legend', {}, { defaultValue: 'Legend' });
|
|
33
|
+
default:
|
|
34
|
+
return t('reputationBadge.level.fallback', { level }, { defaultValue: '{{level}}' });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
6
37
|
/**
|
|
7
38
|
* User reputation / karma display.
|
|
8
39
|
*
|
|
@@ -21,21 +52,13 @@ export function ReputationBadge({ score, level, thresholds = DEFAULT_THRESHOLDS,
|
|
|
21
52
|
const { t } = useTranslation();
|
|
22
53
|
const resolvedLevel = level ?? levelForScore(score, thresholds);
|
|
23
54
|
const color = colorForLevel(resolvedLevel);
|
|
24
|
-
const
|
|
25
|
-
defaultValue: {
|
|
26
|
-
newcomer: 'Newcomer',
|
|
27
|
-
contributor: 'Contributor',
|
|
28
|
-
trusted: 'Trusted',
|
|
29
|
-
veteran: 'Veteran',
|
|
30
|
-
legend: 'Legend',
|
|
31
|
-
}[resolvedLevel],
|
|
32
|
-
});
|
|
55
|
+
const levelLabelText = levelLabel(t, resolvedLevel);
|
|
33
56
|
const formattedScore = formatScore(score);
|
|
34
|
-
const ariaLabel = t('reputationBadge.aria', { score: formattedScore, level:
|
|
57
|
+
const ariaLabel = t('reputationBadge.aria', { score: formattedScore, level: levelLabelText }, { defaultValue: '{{score}} reputation, {{level}}' });
|
|
35
58
|
if (variant === 'full') {
|
|
36
|
-
return (_jsxs("div", { className: cm.cn(cm.stack(1), className), "data-mol-id": "reputation-badge", "aria-label": ariaLabel, children: [_jsx("span", { className: cm.cn(cm.textSize('xs'), cm.fontWeight('medium')), children: t('reputationBadge.caption', {}, { defaultValue: 'Reputation' }) }), _jsxs("div", { className: cm.flex({ align: 'center', gap: 'sm' }), "data-mol-id": "reputation-badge-row", children: [_jsx("span", { className: cm.cn(cm.textSize('lg'), cm.fontWeight('bold')), "data-mol-id": "reputation-badge-score", children: formattedScore }), _jsx(Badge, { color: color, children:
|
|
59
|
+
return (_jsxs("div", { className: cm.cn(cm.stack(1), className), "data-mol-id": "reputation-badge", "aria-label": ariaLabel, children: [_jsx("span", { className: cm.cn(cm.textSize('xs'), cm.fontWeight('medium')), children: t('reputationBadge.caption', {}, { defaultValue: 'Reputation' }) }), _jsxs("div", { className: cm.flex({ align: 'center', gap: 'sm' }), "data-mol-id": "reputation-badge-row", children: [_jsx("span", { className: cm.cn(cm.textSize('lg'), cm.fontWeight('bold')), "data-mol-id": "reputation-badge-score", children: formattedScore }), _jsx(Badge, { color: color, children: levelLabelText })] })] }));
|
|
37
60
|
}
|
|
38
|
-
return (_jsxs("span", { className: cm.cn(cm.flex({ align: 'center', gap: 'xs' }), className), "data-mol-id": "reputation-badge", "aria-label": ariaLabel, children: [_jsx("span", { className: cm.fontWeight('semibold'), "data-mol-id": "reputation-badge-score", children: formattedScore }), _jsx(Badge, { color: color, children:
|
|
61
|
+
return (_jsxs("span", { className: cm.cn(cm.flex({ align: 'center', gap: 'xs' }), className), "data-mol-id": "reputation-badge", "aria-label": ariaLabel, children: [_jsx("span", { className: cm.fontWeight('semibold'), "data-mol-id": "reputation-badge-score", children: formattedScore }), _jsx(Badge, { color: color, children: levelLabelText })] }));
|
|
39
62
|
}
|
|
40
63
|
/**
|
|
41
64
|
* Compact-thousands formatter — keeps the badge readable at large scores.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-reputation-badge-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "User reputation/karma badge with score, level chip, and earned-badges shelf",
|
|
5
5
|
"homepage": "https://www.molecule.dev/packages/app-reputation-badge-react",
|
|
6
6
|
"type": "module",
|
|
@@ -35,16 +35,16 @@
|
|
|
35
35
|
"directory": "packages/app/features/reputation-badge-react"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@molecule/app-react": "^
|
|
38
|
+
"@molecule/app-react": "^4.0.0",
|
|
39
39
|
"@molecule/app-ui": "^1.0.1",
|
|
40
|
-
"@molecule/app-ui-react": "^
|
|
40
|
+
"@molecule/app-ui-react": "^4.0.0",
|
|
41
41
|
"react": "^18.0.0 || ^19.0.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@molecule/app-i18n": "1.
|
|
45
|
-
"@molecule/app-react": "
|
|
46
|
-
"@molecule/app-ui": "1.
|
|
47
|
-
"@molecule/app-ui-react": "
|
|
44
|
+
"@molecule/app-i18n": "1.2.2",
|
|
45
|
+
"@molecule/app-react": "4.10.1",
|
|
46
|
+
"@molecule/app-ui": "1.5.0",
|
|
47
|
+
"@molecule/app-ui-react": "4.2.0",
|
|
48
48
|
"@testing-library/react": "16.3.3",
|
|
49
49
|
"@types/node": "26.6.5",
|
|
50
50
|
"@types/react": "19.3.0",
|