@molecule/app-reputation-badge-svelte 0.0.1-stage → 1.1.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/README.md +260 -4
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,11 +1,267 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-11-21T12:47:10.444Z
|
|
7
|
+
-->
|
|
8
|
+
|
|
1
9
|
# @molecule/app-reputation-badge-svelte
|
|
2
10
|
|
|
3
|
-
|
|
11
|
+
Svelte reputation/karma surfaces — `<ReputationBadge>` and `<BadgeShelf>` —
|
|
12
|
+
for forum, discussion-board, and social flagships.
|
|
13
|
+
|
|
14
|
+
`<ReputationBadge score={n} />` renders a compact-formatted score ("1.5k")
|
|
15
|
+
plus a tier chip; the tier derives from `score` via `levelForScore` and
|
|
16
|
+
`DEFAULT_THRESHOLDS` (contributor 100, trusted 500, veteran 2000,
|
|
17
|
+
legend 10000) unless you pass `level` or `thresholds`. `variant` is
|
|
18
|
+
`'compact'` (default) or `'full'` (stacked with a "Reputation" caption).
|
|
19
|
+
`<BadgeShelf badges limit onClick />` renders earned-badge icons with a
|
|
20
|
+
trailing `+N` overflow chip (`onClick(null)` signals "expand all").
|
|
21
|
+
|
|
22
|
+
This is the Svelte counterpart of `@molecule/app-reputation-badge-react`:
|
|
23
|
+
same exports, same props (React names), same DOM for the same input.
|
|
24
|
+
|
|
25
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
26
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
27
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
28
|
+
|
|
29
|
+
## Quick Start
|
|
30
|
+
|
|
31
|
+
```svelte
|
|
32
|
+
<script lang="ts">
|
|
33
|
+
import { BadgeShelf, ReputationBadge } from '@molecule/app-reputation-badge-svelte'
|
|
34
|
+
import type { Badge } from '@molecule/app-reputation-badge-svelte'
|
|
35
|
+
|
|
36
|
+
let {
|
|
37
|
+
score,
|
|
38
|
+
badges,
|
|
39
|
+
onBadgeClick,
|
|
40
|
+
}: {
|
|
41
|
+
score: number
|
|
42
|
+
badges: Badge[]
|
|
43
|
+
onBadgeClick: (badge: Badge | null) => void
|
|
44
|
+
} = $props()
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<div>
|
|
48
|
+
<ReputationBadge {score} variant="full" />
|
|
49
|
+
<BadgeShelf {badges} limit={5} onClick={onBadgeClick} />
|
|
50
|
+
</div>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Type
|
|
54
|
+
|
|
55
|
+
`feature`
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
npm install @molecule/app-reputation-badge-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## API
|
|
64
|
+
|
|
65
|
+
### Interfaces
|
|
66
|
+
|
|
67
|
+
#### `ReputationThresholds`
|
|
68
|
+
|
|
69
|
+
Optional thresholds for deriving a `ReputationLevel` from a numeric score.
|
|
4
70
|
|
|
71
|
+
If a `level` prop isn't passed to `<ReputationBadge>`, the component will
|
|
72
|
+
pick the highest level whose threshold the `score` meets or exceeds.
|
|
73
|
+
|
|
74
|
+
Default thresholds:
|
|
75
|
+
|
|
76
|
+
- `contributor` >= 100
|
|
77
|
+
- `trusted` >= 500
|
|
78
|
+
- `veteran` >= 2000
|
|
79
|
+
- `legend` >= 10000
|
|
80
|
+
- below 100 → `newcomer`
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
interface ReputationThresholds {
|
|
84
|
+
/** Score >= contributor threshold ⇒ `'contributor'`. */
|
|
85
|
+
contributor: number
|
|
86
|
+
/** Score >= trusted threshold ⇒ `'trusted'`. */
|
|
87
|
+
trusted: number
|
|
88
|
+
/** Score >= veteran threshold ⇒ `'veteran'`. */
|
|
89
|
+
veteran: number
|
|
90
|
+
/** Score >= legend threshold ⇒ `'legend'`. */
|
|
91
|
+
legend: number
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
#### `Badge`
|
|
96
|
+
|
|
97
|
+
A single earned badge — one icon on the `<BadgeShelf>` row.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
interface Badge {
|
|
101
|
+
/** Stable identifier (used as the row key + click payload). */
|
|
102
|
+
id: string
|
|
103
|
+
/** Display name (translated upstream — passed verbatim). */
|
|
104
|
+
name: string
|
|
105
|
+
/** Optional longer description, shown in the native tooltip. */
|
|
106
|
+
description?: string
|
|
107
|
+
/** Icon glyph or short emoji (rendered inline). Mutually exclusive with `iconSrc`. */
|
|
108
|
+
icon?: string
|
|
109
|
+
/** Image URL for the badge icon. */
|
|
110
|
+
iconSrc?: string
|
|
111
|
+
/** ISO date string the badge was earned (passed back via `onClick`). */
|
|
112
|
+
earnedAt?: string
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### `ReputationBadgeProps`
|
|
117
|
+
|
|
118
|
+
Props accepted by the `ReputationBadge` component — the same props
|
|
119
|
+
React's `@molecule/app-reputation-badge-react` accepts.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
interface ReputationBadgeProps {
|
|
123
|
+
/** Numeric reputation / karma score. */
|
|
124
|
+
score: number
|
|
125
|
+
/**
|
|
126
|
+
* Explicit reputation level. If omitted, derived from `score` via
|
|
127
|
+
* `levelForScore` using `thresholds` (or `DEFAULT_THRESHOLDS`).
|
|
128
|
+
*/
|
|
129
|
+
level?: ReputationLevel
|
|
130
|
+
/** Override the default score → level thresholds. */
|
|
131
|
+
thresholds?: ReputationThresholds
|
|
132
|
+
/**
|
|
133
|
+
* Layout variant.
|
|
134
|
+
* - `'compact'` (default) — score number inline with a small level chip.
|
|
135
|
+
* - `'full'` — stacked layout with a "Reputation" caption above the row.
|
|
136
|
+
*/
|
|
137
|
+
variant?: 'compact' | 'full'
|
|
138
|
+
/** Extra classes merged onto the outer wrapper. */
|
|
139
|
+
className?: string
|
|
140
|
+
}
|
|
5
141
|
```
|
|
6
|
-
|
|
142
|
+
|
|
143
|
+
#### `BadgeShelfProps`
|
|
144
|
+
|
|
145
|
+
Props accepted by the `BadgeShelf` component — the same props React's
|
|
146
|
+
`@molecule/app-reputation-badge-react` accepts.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
interface BadgeShelfProps {
|
|
150
|
+
/** Earned badges to display, ordered most-prominent-first. */
|
|
151
|
+
badges: Badge[]
|
|
152
|
+
/**
|
|
153
|
+
* Maximum number of badge icons rendered inline. Any remaining are
|
|
154
|
+
* summarised in a trailing `+N` overflow chip.
|
|
155
|
+
*
|
|
156
|
+
* @default 5
|
|
157
|
+
*/
|
|
158
|
+
limit?: number
|
|
159
|
+
/**
|
|
160
|
+
* Click handler — invoked with the clicked badge (or `null` when the
|
|
161
|
+
* trailing overflow chip is clicked, signalling "expand all").
|
|
162
|
+
*/
|
|
163
|
+
onClick?: (badge: Badge | null) => void
|
|
164
|
+
/** Extra classes merged onto the outer row. */
|
|
165
|
+
className?: string
|
|
166
|
+
}
|
|
7
167
|
```
|
|
8
168
|
|
|
9
|
-
|
|
169
|
+
### Types
|
|
170
|
+
|
|
171
|
+
#### `ReputationLevel`
|
|
172
|
+
|
|
173
|
+
Reputation level identifiers — used to pick a tier color/label.
|
|
174
|
+
|
|
175
|
+
Apps that need finer granularity can pass a `level` string of any value;
|
|
176
|
+
unknown values fall back to `'newcomer'` styling.
|
|
177
|
+
|
|
178
|
+
```typescript
|
|
179
|
+
type ReputationLevel = 'newcomer' | 'contributor' | 'trusted' | 'veteran' | 'legend'
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Functions
|
|
183
|
+
|
|
184
|
+
#### `levelForScore(score, thresholds)`
|
|
185
|
+
|
|
186
|
+
Derive a {@link ReputationLevel} from a numeric score.
|
|
187
|
+
|
|
188
|
+
Picks the highest level whose threshold is met or exceeded. Any score
|
|
189
|
+
below `thresholds.contributor` returns `'newcomer'`.
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
function levelForScore(score: number, thresholds?: ReputationThresholds): ReputationLevel
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
- `score` — Reputation score (any non-negative number).
|
|
196
|
+
- `thresholds` — Optional override thresholds; defaults to {@link DEFAULT_THRESHOLDS}.
|
|
197
|
+
|
|
198
|
+
**Returns:** The derived reputation level.
|
|
199
|
+
|
|
200
|
+
#### `colorForLevel(level)`
|
|
201
|
+
|
|
202
|
+
Return the semantic Badge color for a given level.
|
|
203
|
+
|
|
204
|
+
Unknown levels fall back to `'secondary'`.
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
function colorForLevel(
|
|
208
|
+
level: ReputationLevel,
|
|
209
|
+
): 'primary' | 'secondary' | 'success' | 'warning' | 'info'
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
- `level` — The reputation level.
|
|
213
|
+
|
|
214
|
+
**Returns:** A badge color name from `@molecule/app-ui-vue`.
|
|
215
|
+
|
|
216
|
+
### Constants
|
|
217
|
+
|
|
218
|
+
#### `BadgeShelf`
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
const BadgeShelf: LegacyComponentType
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
#### `ReputationBadge`
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
const ReputationBadge: LegacyComponentType
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### `DEFAULT_THRESHOLDS`
|
|
231
|
+
|
|
232
|
+
Default thresholds used when no `thresholds` prop is supplied.
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
const DEFAULT_THRESHOLDS: ReputationThresholds
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Injection Notes
|
|
239
|
+
|
|
240
|
+
### Requirements
|
|
241
|
+
|
|
242
|
+
Peer dependencies:
|
|
243
|
+
|
|
244
|
+
- `@molecule/app-svelte` ^3.5.0
|
|
245
|
+
- `@molecule/app-ui` ^1.0.1
|
|
246
|
+
- `@molecule/app-ui-svelte` ^1.1.0
|
|
247
|
+
- `svelte` ^5.0.0
|
|
248
|
+
|
|
249
|
+
### Runtime Dependencies
|
|
250
|
+
|
|
251
|
+
- `@molecule/app-svelte`
|
|
252
|
+
- `@molecule/app-ui`
|
|
253
|
+
- `@molecule/app-ui-svelte`
|
|
254
|
+
- `svelte`
|
|
255
|
+
|
|
256
|
+
- Both components throw unless mounted under `setMoleculeContext({ i18n })`
|
|
257
|
+
(`useTranslation()` needs it) with a ClassMap bonded via `setClassMap()`.
|
|
258
|
+
- This package exports a `Badge` TYPE (earned-badge data shape) — distinct
|
|
259
|
+
from the `Badge` COMPONENT in `@molecule/app-ui-svelte`; alias one when
|
|
260
|
+
importing both in a file.
|
|
261
|
+
- Server-side score/badge issuance pairs with `@molecule/api-reputation`.
|
|
262
|
+
- Translations live in the companion `@molecule/app-locales-reputation-badge`
|
|
263
|
+
bond (registered).
|
|
264
|
+
|
|
265
|
+
## Translations
|
|
10
266
|
|
|
11
|
-
|
|
267
|
+
Translation strings are provided by `@molecule/app-locales-reputation-badge`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-reputation-badge-svelte",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
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-svelte",
|
|
6
6
|
"type": "module",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"@molecule/app-framework-conformance": "0.0.0",
|
|
60
60
|
"@molecule/app-i18n": "1.2.2",
|
|
61
61
|
"@molecule/app-icons": "1.0.4",
|
|
62
|
-
"@molecule/app-svelte": "3.
|
|
63
|
-
"@molecule/app-ui": "1.
|
|
64
|
-
"@molecule/app-ui-svelte": "1.1
|
|
62
|
+
"@molecule/app-svelte": "3.9.0",
|
|
63
|
+
"@molecule/app-ui": "1.5.0",
|
|
64
|
+
"@molecule/app-ui-svelte": "1.2.1",
|
|
65
65
|
"@sveltejs/package": "3.0.2",
|
|
66
66
|
"@sveltejs/vite-plugin-svelte": "7.1.2",
|
|
67
67
|
"@types/node": "26.6.5",
|