kyd-shared-badge 0.2.3 → 0.2.5
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/SharedBadgeDisplay.tsx +14 -8
- package/src/colors.ts +39 -1
- package/src/components/ReportHeader.tsx +17 -2
package/package.json
CHANGED
|
@@ -17,6 +17,14 @@ const getScoreColor = (score: number) => {
|
|
|
17
17
|
return red;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
const hexToRgba = (hex: string, alpha: number) => {
|
|
21
|
+
const clean = hex.replace('#', '');
|
|
22
|
+
const r = parseInt(clean.substring(0, 2), 16);
|
|
23
|
+
const g = parseInt(clean.substring(2, 4), 16);
|
|
24
|
+
const b = parseInt(clean.substring(4, 6), 16);
|
|
25
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
26
|
+
};
|
|
27
|
+
|
|
20
28
|
const getRiskText = (risk: number) => {
|
|
21
29
|
if (risk >= 80) return 'Low Risk';
|
|
22
30
|
if (risk >= 65) return 'Medium Risk';
|
|
@@ -55,14 +63,14 @@ interface ScoreCardProps {
|
|
|
55
63
|
description: string;
|
|
56
64
|
descriptor?: string;
|
|
57
65
|
scoreType: 'number' | 'risk' | 'descriptor';
|
|
58
|
-
isRecruiter?: boolean;
|
|
59
66
|
iconImageSrc: string;
|
|
60
67
|
}
|
|
61
68
|
|
|
62
|
-
const ScoreCard = ({ title, score, description, descriptor, scoreType,
|
|
69
|
+
const ScoreCard = ({ title, score, description, descriptor, scoreType, iconImageSrc }: ScoreCardProps) => {
|
|
63
70
|
const isDescriptor = scoreType === 'descriptor';
|
|
64
71
|
const scoreHex = isDescriptor ? undefined : getScoreColor(score);
|
|
65
72
|
const scoreClass = isDescriptor ? 'text-neutral-400' : '';
|
|
73
|
+
const overlay = scoreHex ? hexToRgba(scoreHex, 0.08) : 'transparent';
|
|
66
74
|
let displayScore;
|
|
67
75
|
|
|
68
76
|
if (scoreType === 'risk') {
|
|
@@ -76,18 +84,16 @@ const ScoreCard = ({ title, score, description, descriptor, scoreType, isRecruit
|
|
|
76
84
|
return (
|
|
77
85
|
<div
|
|
78
86
|
className={
|
|
79
|
-
|
|
80
|
-
? 'p-6 rounded-xl flex flex-col items-center justify-start text-center shadow h-full border'
|
|
81
|
-
: 'p-6 rounded-lg flex flex-col items-center justify-start text-center dark:bg-neutral-800/50 backdrop-blur-sm bg-white/70 shadow-lg border border-neutral-200 dark:border-neutral-700 h-full'
|
|
87
|
+
'p-6 rounded-xl flex flex-col items-center justify-start text-center shadow h-full border'
|
|
82
88
|
}
|
|
83
|
-
style={
|
|
89
|
+
style={{ backgroundColor: 'var(--content-card-background)', borderColor: 'var(--icon-button-secondary)', backgroundImage: `linear-gradient(${overlay}, ${overlay})` }}
|
|
84
90
|
>
|
|
85
91
|
<div className={`text-3xl mb-4 ${scoreClass}`} style={scoreHex ? { color: scoreHex } : undefined}>
|
|
86
92
|
<Image src={iconImageSrc} alt="icon" width={32} height={32} className="h-8 w-8 object-contain" />
|
|
87
93
|
</div>
|
|
88
|
-
<h3 className={`font-semibold text-xl ${isDescriptor ? 'text-neutral-400' : ''}`} style={
|
|
94
|
+
<h3 className={`font-semibold text-xl ${isDescriptor ? 'text-neutral-400' : ''}`} style={{ color: 'var(--text-main)' }}>{title}</h3>
|
|
89
95
|
<p className={`text-4xl font-bold ${scoreClass}`} style={scoreHex ? { color: scoreHex } : undefined}>{displayScore}</p>
|
|
90
|
-
<p className={
|
|
96
|
+
<p className={'text-sm text-neutral-600 dark:text-neutral-400 mt-4'} style={{ color: 'var(--text-secondary)' }}>{description}</p>
|
|
91
97
|
</div>
|
|
92
98
|
);
|
|
93
99
|
};
|
package/src/colors.ts
CHANGED
|
@@ -2,4 +2,42 @@ const red = '#EC6662'
|
|
|
2
2
|
const yellow = '#ffbb54'
|
|
3
3
|
const green = '#02a389'
|
|
4
4
|
|
|
5
|
-
export { red, yellow, green }
|
|
5
|
+
export { red, yellow, green }
|
|
6
|
+
|
|
7
|
+
// red
|
|
8
|
+
|
|
9
|
+
// #EC6662
|
|
10
|
+
|
|
11
|
+
// #F1908C
|
|
12
|
+
|
|
13
|
+
// #F5B7B3
|
|
14
|
+
|
|
15
|
+
// #FADBDA
|
|
16
|
+
|
|
17
|
+
// #FDF0EF
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
// // yellow
|
|
21
|
+
|
|
22
|
+
// #F4BE66
|
|
23
|
+
|
|
24
|
+
// #F7CF8F
|
|
25
|
+
|
|
26
|
+
// #F9DFB6
|
|
27
|
+
|
|
28
|
+
// #FDEFDB
|
|
29
|
+
|
|
30
|
+
// #FEF9F0
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// // green
|
|
34
|
+
|
|
35
|
+
// #02a389
|
|
36
|
+
|
|
37
|
+
// #7BB9AA
|
|
38
|
+
|
|
39
|
+
// #A9D1C6
|
|
40
|
+
|
|
41
|
+
// #D5E8E2
|
|
42
|
+
|
|
43
|
+
// #EEF6F4
|
|
@@ -8,6 +8,20 @@ const getBadgeImageUrl = (score: number) => {
|
|
|
8
8
|
return '/badgered.png';
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
+
const hexToRgba = (hex: string, alpha: number) => {
|
|
12
|
+
const clean = hex.replace('#', '');
|
|
13
|
+
const r = parseInt(clean.substring(0, 2), 16);
|
|
14
|
+
const g = parseInt(clean.substring(2, 4), 16);
|
|
15
|
+
const b = parseInt(clean.substring(4, 6), 16);
|
|
16
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const pickTint = (score: number) => {
|
|
20
|
+
if (score >= 75) return '#02a389';
|
|
21
|
+
if (score >= 50) return '#ffbb54';
|
|
22
|
+
return '#EC6662';
|
|
23
|
+
};
|
|
24
|
+
|
|
11
25
|
interface ReportHeaderProps {
|
|
12
26
|
badgeId: string | undefined;
|
|
13
27
|
developerName: string | undefined;
|
|
@@ -20,6 +34,7 @@ interface ReportHeaderProps {
|
|
|
20
34
|
const ReportHeader = ({ badgeId, developerName, updatedAt, score = 0, isPublic, badgeImageUrl }: ReportHeaderProps) => {
|
|
21
35
|
// Use the dynamic image if available, otherwise fall back to the score-based one.
|
|
22
36
|
const finalBadgeImageUrl = badgeImageUrl || getBadgeImageUrl(score);
|
|
37
|
+
const tint = hexToRgba(pickTint(score), 0.06);
|
|
23
38
|
|
|
24
39
|
const formattedDate = updatedAt ? new Date(updatedAt).toLocaleString(undefined, {
|
|
25
40
|
year: 'numeric',
|
|
@@ -30,7 +45,7 @@ const ReportHeader = ({ badgeId, developerName, updatedAt, score = 0, isPublic,
|
|
|
30
45
|
return (
|
|
31
46
|
<div
|
|
32
47
|
className={'mb-8 p-6 rounded-xl shadow-lg flex flex-col md:flex-row items-start md:items-center justify-between gap-6 border'}
|
|
33
|
-
style={{ backgroundColor: 'var(--content-card-background)', borderColor: 'var(--icon-button-secondary)' }}
|
|
48
|
+
style={{ backgroundColor: 'var(--content-card-background)', borderColor: 'var(--icon-button-secondary)', backgroundImage: `linear-gradient(${tint}, ${tint})` }}
|
|
34
49
|
>
|
|
35
50
|
{/* Left Section */}
|
|
36
51
|
<div className="flex items-center text-left md:text-center gap-5">
|
|
@@ -56,7 +71,7 @@ const ReportHeader = ({ badgeId, developerName, updatedAt, score = 0, isPublic,
|
|
|
56
71
|
<p><span className={'font-semibold'} style={{ color: 'var(--text-main)' }}>Requested By:</span> {developerName || 'N/A'}</p>
|
|
57
72
|
<p><span className={'font-semibold'} style={{ color: 'var(--text-main)' }}>Organization:</span> Unaffiliated</p>
|
|
58
73
|
<p><span className={'font-semibold'} style={{ color: 'var(--text-main)' }}>Date Generated:</span> {formattedDate}</p>
|
|
59
|
-
<p><span className={'font-semibold'} style={{ color: 'var(--text-main)' }}>Report ID:</span> {badgeId}</p>
|
|
74
|
+
<p><span className={'font-semibold'} style={{ color: 'var(--text-main)' }}>Report ID:</span> {badgeId ? `${badgeId.slice(0,4)}...${badgeId.slice(-4)}` : 'N/A'}</p>
|
|
60
75
|
</div>
|
|
61
76
|
</div>
|
|
62
77
|
);
|