@kolkrabbi/kol-component 0.39.0 → 0.40.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/package.json +1 -1
- package/src/atoms/Avatar.jsx +34 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolkrabbi/kol-component",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.0",
|
|
4
4
|
"description": "KOL design-system components — atoms through organisms, emitting canonical kol-* classes. Pairs with @kolkrabbi/kol-theme for styling.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/atoms/Avatar.jsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
|
|
1
3
|
const SIZE_MAP = {
|
|
2
4
|
sm: 'w-8 h-8 kol-helper-12',
|
|
3
5
|
md: 'w-10 h-10 kol-helper-14',
|
|
@@ -5,11 +7,41 @@ const SIZE_MAP = {
|
|
|
5
7
|
xl: 'w-24 h-24 kol-helper-20',
|
|
6
8
|
}
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Avatar — the initials disc, or a photo at the same geometry.
|
|
12
|
+
*
|
|
13
|
+
* `src` was added when the ArticleHeader reconciliation (2026-08-15) found the
|
|
14
|
+
* consumer hand-rolling `<img className="w-12 h-12 rounded-full object-cover">`
|
|
15
|
+
* beside a grey-circle fallback, because the atom did initials only. The size
|
|
16
|
+
* ladder is the atom's to own — a caller writing its own w-/h- pair is how a
|
|
17
|
+
* fifth avatar size gets invented. Falls back to the initial on a broken src,
|
|
18
|
+
* so a dead photo URL degrades to the disc instead of a torn-image glyph.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} initial glyph shown when there is no photo
|
|
21
|
+
* @param {string} [src] resolved image src — the consumer resolves it, this
|
|
22
|
+
* atom never builds a URL
|
|
23
|
+
* @param {string} [alt=''] photo alt text
|
|
24
|
+
* @param {'sm'|'md'|'lg'|'xl'} [size='sm']
|
|
25
|
+
*/
|
|
26
|
+
export default function Avatar({ initial, src, alt = '', size = 'sm', className = '' }) {
|
|
9
27
|
const sizeCls = SIZE_MAP[size] ?? SIZE_MAP.sm
|
|
28
|
+
const [failed, setFailed] = useState(false)
|
|
29
|
+
const shell = `kol-avatar rounded-full bg-surface-secondary shrink-0 ${sizeCls} ${className}`
|
|
30
|
+
|
|
31
|
+
if (src && !failed) {
|
|
32
|
+
return (
|
|
33
|
+
<img
|
|
34
|
+
src={src}
|
|
35
|
+
alt={alt}
|
|
36
|
+
className={`${shell} object-cover`}
|
|
37
|
+
onError={() => setFailed(true)}
|
|
38
|
+
/>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
10
42
|
return (
|
|
11
43
|
<span
|
|
12
|
-
className={
|
|
44
|
+
className={`${shell} inline-flex items-center justify-center text-emphasis font-narrow font-semibold`}
|
|
13
45
|
>
|
|
14
46
|
{initial}
|
|
15
47
|
</span>
|