@molecule/app-reputation-badge-react 4.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.
@@ -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;AAEvE,+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,CA+D1C"}
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"}
@@ -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 levelLabel = t(`reputationBadge.level.${resolvedLevel}`, {}, {
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: levelLabel }, { defaultValue: '{{score}} reputation, {{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: levelLabel })] })] }));
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: levelLabel })] }));
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": "4.0.0",
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",
@@ -41,10 +41,10 @@
41
41
  "react": "^18.0.0 || ^19.0.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@molecule/app-i18n": "1.1.2",
45
- "@molecule/app-react": "4.0.0",
46
- "@molecule/app-ui": "1.3.9",
47
- "@molecule/app-ui-react": "4.0.0",
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",