@aiready/components 0.13.19 → 0.13.20
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/dist/index.d.ts +2 -1
- package/dist/index.js +47 -47
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/utils/__tests__/score.test.ts +28 -7
- package/src/utils/score.ts +64 -51
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiready/components",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.20",
|
|
4
4
|
"description": "Unified shared components library (UI, charts, hooks, utilities) for AIReady",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -128,7 +128,7 @@
|
|
|
128
128
|
"framer-motion": "^12.35.0",
|
|
129
129
|
"lucide-react": "^0.577.0",
|
|
130
130
|
"tailwind-merge": "^3.0.0",
|
|
131
|
-
"@aiready/core": "0.23.
|
|
131
|
+
"@aiready/core": "0.23.21"
|
|
132
132
|
},
|
|
133
133
|
"devDependencies": {
|
|
134
134
|
"@testing-library/jest-dom": "^6.6.5",
|
|
@@ -1,28 +1,49 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
scoreColor,
|
|
4
|
+
scoreBg,
|
|
5
|
+
scoreLabel,
|
|
6
|
+
getScoreRating,
|
|
7
|
+
scoreGlow,
|
|
8
|
+
} from '../score';
|
|
3
9
|
|
|
4
10
|
describe('Score Utilities', () => {
|
|
5
11
|
it('should return correct color for scores', () => {
|
|
12
|
+
expect(scoreColor(95)).toBe('text-emerald-400');
|
|
6
13
|
expect(scoreColor(80)).toBe('text-emerald-400');
|
|
7
|
-
expect(scoreColor(
|
|
8
|
-
expect(scoreColor(
|
|
14
|
+
expect(scoreColor(65)).toBe('text-amber-400');
|
|
15
|
+
expect(scoreColor(45)).toBe('text-red-400');
|
|
16
|
+
expect(scoreColor(20)).toBe('text-red-400');
|
|
9
17
|
expect(scoreColor(null)).toBe('text-slate-400');
|
|
10
18
|
});
|
|
11
19
|
|
|
12
20
|
it('should return correct background for scores', () => {
|
|
21
|
+
expect(scoreBg(95)).toContain('emerald');
|
|
13
22
|
expect(scoreBg(80)).toContain('emerald');
|
|
14
|
-
expect(scoreBg(
|
|
15
|
-
expect(scoreBg(
|
|
23
|
+
expect(scoreBg(65)).toContain('amber');
|
|
24
|
+
expect(scoreBg(45)).toContain('red');
|
|
25
|
+
expect(scoreBg(20)).toContain('red');
|
|
16
26
|
expect(scoreBg(null)).toContain('slate');
|
|
17
27
|
});
|
|
18
28
|
|
|
19
29
|
it('should return correct labels', () => {
|
|
30
|
+
expect(scoreLabel(95)).toBe('Excellent');
|
|
20
31
|
expect(scoreLabel(80)).toBe('AI-Ready');
|
|
21
|
-
expect(scoreLabel(
|
|
22
|
-
expect(scoreLabel(
|
|
32
|
+
expect(scoreLabel(65)).toBe('Fair');
|
|
33
|
+
expect(scoreLabel(45)).toBe('Needs Improvement');
|
|
34
|
+
expect(scoreLabel(20)).toBe('Critical Issues');
|
|
23
35
|
expect(scoreLabel(null)).toBe('Not analyzed');
|
|
24
36
|
});
|
|
25
37
|
|
|
38
|
+
it('should return correct glow for scores', () => {
|
|
39
|
+
expect(scoreGlow(95)).toContain('emerald');
|
|
40
|
+
expect(scoreGlow(80)).toContain('emerald');
|
|
41
|
+
expect(scoreGlow(65)).toContain('amber');
|
|
42
|
+
expect(scoreGlow(45)).toContain('red');
|
|
43
|
+
expect(scoreGlow(20)).toContain('red');
|
|
44
|
+
expect(scoreGlow(null)).toBe('');
|
|
45
|
+
});
|
|
46
|
+
|
|
26
47
|
it('should return correct rating strings', () => {
|
|
27
48
|
expect(getScoreRating(95)).toBe('excellent');
|
|
28
49
|
expect(getScoreRating(80)).toBe('good');
|
package/src/utils/score.ts
CHANGED
|
@@ -1,82 +1,95 @@
|
|
|
1
1
|
import { getRatingSlug } from '@aiready/core/client';
|
|
2
2
|
|
|
3
|
+
type RatingSlug = 'excellent' | 'good' | 'fair' | 'needs-work' | 'critical';
|
|
4
|
+
|
|
5
|
+
interface ScoreMetadata {
|
|
6
|
+
color: string;
|
|
7
|
+
bg: string;
|
|
8
|
+
label: string;
|
|
9
|
+
glow: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const SCORE_METADATA: Record<RatingSlug, ScoreMetadata> = {
|
|
13
|
+
excellent: {
|
|
14
|
+
color: 'text-emerald-400',
|
|
15
|
+
bg: 'bg-emerald-900/30 border-emerald-500/30',
|
|
16
|
+
label: 'Excellent',
|
|
17
|
+
glow: 'shadow-emerald-500/20',
|
|
18
|
+
},
|
|
19
|
+
good: {
|
|
20
|
+
color: 'text-emerald-400',
|
|
21
|
+
bg: 'bg-emerald-900/30 border-emerald-500/30',
|
|
22
|
+
label: 'AI-Ready',
|
|
23
|
+
glow: 'shadow-emerald-500/20',
|
|
24
|
+
},
|
|
25
|
+
fair: {
|
|
26
|
+
color: 'text-amber-400',
|
|
27
|
+
bg: 'bg-amber-900/30 border-amber-500/30',
|
|
28
|
+
label: 'Fair',
|
|
29
|
+
glow: 'shadow-amber-500/20',
|
|
30
|
+
},
|
|
31
|
+
'needs-work': {
|
|
32
|
+
color: 'text-red-400',
|
|
33
|
+
bg: 'bg-red-900/30 border-red-500/30',
|
|
34
|
+
label: 'Needs Improvement',
|
|
35
|
+
glow: 'shadow-red-500/20',
|
|
36
|
+
},
|
|
37
|
+
critical: {
|
|
38
|
+
color: 'text-red-400',
|
|
39
|
+
bg: 'bg-red-900/30 border-red-500/30',
|
|
40
|
+
label: 'Critical Issues',
|
|
41
|
+
glow: 'shadow-red-500/20',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const DEFAULT_METADATA: ScoreMetadata = {
|
|
46
|
+
color: 'text-slate-400',
|
|
47
|
+
bg: 'bg-slate-800/50 border-slate-700',
|
|
48
|
+
label: 'Not analyzed',
|
|
49
|
+
glow: '',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get the metadata for a score using core rating system
|
|
54
|
+
*/
|
|
55
|
+
function getMetadata(score: number | null | undefined): ScoreMetadata {
|
|
56
|
+
if (score == null) return DEFAULT_METADATA;
|
|
57
|
+
const rating = getRatingSlug(score) as RatingSlug;
|
|
58
|
+
return SCORE_METADATA[rating] || SCORE_METADATA.critical;
|
|
59
|
+
}
|
|
60
|
+
|
|
3
61
|
/**
|
|
4
62
|
* Get the Tailwind color class for a score using core rating system
|
|
5
63
|
*/
|
|
6
64
|
export function scoreColor(score: number | null | undefined): string {
|
|
7
|
-
|
|
8
|
-
const rating = getRatingSlug(score);
|
|
9
|
-
switch (rating) {
|
|
10
|
-
case 'excellent':
|
|
11
|
-
case 'good':
|
|
12
|
-
return 'text-emerald-400';
|
|
13
|
-
case 'fair':
|
|
14
|
-
return 'text-amber-400';
|
|
15
|
-
default:
|
|
16
|
-
return 'text-red-400';
|
|
17
|
-
}
|
|
65
|
+
return getMetadata(score).color;
|
|
18
66
|
}
|
|
19
67
|
|
|
20
68
|
/**
|
|
21
69
|
* Get the Tailwind background/border class for a score using core rating system
|
|
22
70
|
*/
|
|
23
71
|
export function scoreBg(score: number | null | undefined): string {
|
|
24
|
-
|
|
25
|
-
const rating = getRatingSlug(score);
|
|
26
|
-
switch (rating) {
|
|
27
|
-
case 'excellent':
|
|
28
|
-
case 'good':
|
|
29
|
-
return 'bg-emerald-900/30 border-emerald-500/30';
|
|
30
|
-
case 'fair':
|
|
31
|
-
return 'bg-amber-900/30 border-amber-500/30';
|
|
32
|
-
default:
|
|
33
|
-
return 'bg-red-900/30 border-red-500/30';
|
|
34
|
-
}
|
|
72
|
+
return getMetadata(score).bg;
|
|
35
73
|
}
|
|
36
74
|
|
|
37
75
|
/**
|
|
38
76
|
* Get the display label for a score using core rating system
|
|
39
77
|
*/
|
|
40
78
|
export function scoreLabel(score: number | null | undefined): string {
|
|
41
|
-
|
|
42
|
-
const rating = getRatingSlug(score);
|
|
43
|
-
switch (rating) {
|
|
44
|
-
case 'excellent':
|
|
45
|
-
return 'Excellent';
|
|
46
|
-
case 'good':
|
|
47
|
-
return 'AI-Ready';
|
|
48
|
-
case 'fair':
|
|
49
|
-
return 'Fair';
|
|
50
|
-
case 'needs-work':
|
|
51
|
-
return 'Needs Improvement';
|
|
52
|
-
default:
|
|
53
|
-
return 'Critical Issues';
|
|
54
|
-
}
|
|
79
|
+
return getMetadata(score).label;
|
|
55
80
|
}
|
|
56
81
|
|
|
57
82
|
/**
|
|
58
83
|
* Get the Tailwind shadow glow class for a score using core rating system
|
|
59
84
|
*/
|
|
60
85
|
export function scoreGlow(score: number | null | undefined): string {
|
|
61
|
-
|
|
62
|
-
const rating = getRatingSlug(score);
|
|
63
|
-
switch (rating) {
|
|
64
|
-
case 'excellent':
|
|
65
|
-
case 'good':
|
|
66
|
-
return 'shadow-emerald-500/20';
|
|
67
|
-
case 'fair':
|
|
68
|
-
return 'shadow-amber-500/20';
|
|
69
|
-
default:
|
|
70
|
-
return 'shadow-red-500/20';
|
|
71
|
-
}
|
|
86
|
+
return getMetadata(score).glow;
|
|
72
87
|
}
|
|
73
88
|
|
|
74
89
|
/**
|
|
75
90
|
* Get rating from score (for use with ScoreBar component)
|
|
76
91
|
*/
|
|
77
|
-
export function getScoreRating(
|
|
78
|
-
score: number | null | undefined
|
|
79
|
-
): 'excellent' | 'good' | 'fair' | 'needs-work' | 'critical' {
|
|
92
|
+
export function getScoreRating(score: number | null | undefined): RatingSlug {
|
|
80
93
|
if (score == null) return 'critical';
|
|
81
|
-
return getRatingSlug(score) as
|
|
94
|
+
return getRatingSlug(score) as RatingSlug;
|
|
82
95
|
}
|