@aiready/components 0.1.21 → 0.1.24
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/charts/ForceDirectedGraph.js +8 -8
- package/dist/charts/ForceDirectedGraph.js.map +1 -1
- package/dist/index.d.ts +98 -3
- package/dist/index.js +405 -10
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/charts/ForceDirectedGraph.tsx +8 -8
- package/src/code-block/CodeBlock.tsx +147 -0
- package/src/code-block/index.ts +1 -0
- package/src/data-display/ScoreBar.tsx +124 -0
- package/src/data-display/index.ts +1 -0
- package/src/feedback/ErrorDisplay.tsx +86 -0
- package/src/feedback/LoadingSpinner.tsx +35 -0
- package/src/feedback/index.ts +2 -0
- package/src/index.ts +25 -0
- package/src/navigation/Breadcrumb.tsx +61 -0
- package/src/navigation/index.ts +1 -0
- package/src/theme/ThemeProvider.tsx +124 -0
- package/src/theme/index.ts +1 -0
- package/src/utils/score.ts +56 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { createContext, useContext, useEffect, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
export type Theme = 'dark' | 'light' | 'system';
|
|
6
|
+
export type EffectiveTheme = 'dark' | 'light';
|
|
7
|
+
|
|
8
|
+
interface ThemeContextValue {
|
|
9
|
+
theme: Theme;
|
|
10
|
+
setTheme: (theme: Theme) => void;
|
|
11
|
+
effectiveTheme: EffectiveTheme;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ThemeContext = createContext<ThemeContextValue | undefined>(undefined);
|
|
15
|
+
|
|
16
|
+
const STORAGE_KEY = 'aiready-theme';
|
|
17
|
+
|
|
18
|
+
function getSystemTheme(): EffectiveTheme {
|
|
19
|
+
if (typeof window === 'undefined') return 'light';
|
|
20
|
+
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getStoredTheme(): Theme {
|
|
24
|
+
if (typeof window === 'undefined') return 'system';
|
|
25
|
+
try {
|
|
26
|
+
const stored = localStorage.getItem(STORAGE_KEY);
|
|
27
|
+
if (stored === 'dark' || stored === 'light' || stored === 'system') {
|
|
28
|
+
return stored;
|
|
29
|
+
}
|
|
30
|
+
} catch {
|
|
31
|
+
// localStorage not available
|
|
32
|
+
}
|
|
33
|
+
return 'system';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ThemeProviderProps {
|
|
37
|
+
children: React.ReactNode;
|
|
38
|
+
defaultTheme?: Theme;
|
|
39
|
+
storageKey?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function ThemeProvider({
|
|
43
|
+
children,
|
|
44
|
+
defaultTheme = 'system',
|
|
45
|
+
storageKey = STORAGE_KEY,
|
|
46
|
+
}: ThemeProviderProps) {
|
|
47
|
+
const [theme, setThemeState] = useState<Theme>(defaultTheme);
|
|
48
|
+
const [effectiveTheme, setEffectiveTheme] = useState<EffectiveTheme>('light');
|
|
49
|
+
const [mounted, setMounted] = useState(false);
|
|
50
|
+
|
|
51
|
+
// Initialize theme from storage on mount
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const storedTheme = getStoredTheme();
|
|
54
|
+
setThemeState(storedTheme);
|
|
55
|
+
setMounted(true);
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
// Update effective theme when theme or system preference changes
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (!mounted) return;
|
|
61
|
+
|
|
62
|
+
const updateEffectiveTheme = () => {
|
|
63
|
+
if (theme === 'system') {
|
|
64
|
+
setEffectiveTheme(getSystemTheme());
|
|
65
|
+
} else {
|
|
66
|
+
setEffectiveTheme(theme);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
updateEffectiveTheme();
|
|
71
|
+
|
|
72
|
+
// Listen for system theme changes
|
|
73
|
+
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
74
|
+
const handleChange = () => {
|
|
75
|
+
if (theme === 'system') {
|
|
76
|
+
setEffectiveTheme(getSystemTheme());
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
mediaQuery.addEventListener('change', handleChange);
|
|
81
|
+
return () => mediaQuery.removeEventListener('change', handleChange);
|
|
82
|
+
}, [theme, mounted]);
|
|
83
|
+
|
|
84
|
+
// Apply theme class to document
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (!mounted) return;
|
|
87
|
+
|
|
88
|
+
const root = document.documentElement;
|
|
89
|
+
root.classList.remove('light', 'dark');
|
|
90
|
+
root.classList.add(effectiveTheme);
|
|
91
|
+
}, [effectiveTheme, mounted]);
|
|
92
|
+
|
|
93
|
+
const setTheme = (newTheme: Theme) => {
|
|
94
|
+
setThemeState(newTheme);
|
|
95
|
+
try {
|
|
96
|
+
localStorage.setItem(storageKey, newTheme);
|
|
97
|
+
} catch {
|
|
98
|
+
// localStorage not available
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// Prevent hydration mismatch
|
|
103
|
+
if (!mounted) {
|
|
104
|
+
return (
|
|
105
|
+
<ThemeContext.Provider value={{ theme: defaultTheme, setTheme: () => {}, effectiveTheme: 'light' }}>
|
|
106
|
+
{children}
|
|
107
|
+
</ThemeContext.Provider>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<ThemeContext.Provider value={{ theme, setTheme, effectiveTheme }}>
|
|
113
|
+
{children}
|
|
114
|
+
</ThemeContext.Provider>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function useTheme(): ThemeContextValue {
|
|
119
|
+
const context = useContext(ThemeContext);
|
|
120
|
+
if (context === undefined) {
|
|
121
|
+
throw new Error('useTheme must be used within a ThemeProvider');
|
|
122
|
+
}
|
|
123
|
+
return context;
|
|
124
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ThemeProvider, useTheme, type Theme, type EffectiveTheme } from './ThemeProvider';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Score utility functions for AI readiness scoring
|
|
3
|
+
* Provides color, background, glow, and label helpers for score display
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get the Tailwind color class for a score
|
|
8
|
+
*/
|
|
9
|
+
export function scoreColor(score: number | null | undefined): string {
|
|
10
|
+
if (score == null) return 'text-slate-400';
|
|
11
|
+
if (score >= 75) return 'text-emerald-400';
|
|
12
|
+
if (score >= 50) return 'text-amber-400';
|
|
13
|
+
return 'text-red-400';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get the Tailwind background/border class for a score
|
|
18
|
+
*/
|
|
19
|
+
export function scoreBg(score: number | null | undefined): string {
|
|
20
|
+
if (score == null) return 'bg-slate-800/50 border-slate-700';
|
|
21
|
+
if (score >= 75) return 'bg-emerald-900/30 border-emerald-500/30';
|
|
22
|
+
if (score >= 50) return 'bg-amber-900/30 border-amber-500/30';
|
|
23
|
+
return 'bg-red-900/30 border-red-500/30';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get the display label for a score
|
|
28
|
+
*/
|
|
29
|
+
export function scoreLabel(score: number | null | undefined): string {
|
|
30
|
+
if (score == null) return 'Not analyzed';
|
|
31
|
+
if (score >= 75) return 'AI-Ready';
|
|
32
|
+
if (score >= 50) return 'Needs Improvement';
|
|
33
|
+
return 'Critical Issues';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get the Tailwind shadow glow class for a score
|
|
38
|
+
*/
|
|
39
|
+
export function scoreGlow(score: number | null | undefined): string {
|
|
40
|
+
if (score == null) return '';
|
|
41
|
+
if (score >= 75) return 'shadow-emerald-500/20';
|
|
42
|
+
if (score >= 50) return 'shadow-amber-500/20';
|
|
43
|
+
return 'shadow-red-500/20';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Get rating from score (for use with ScoreBar component)
|
|
48
|
+
*/
|
|
49
|
+
export function getScoreRating(score: number | null | undefined): 'excellent' | 'good' | 'fair' | 'needs-work' | 'critical' {
|
|
50
|
+
if (score == null) return 'critical';
|
|
51
|
+
if (score >= 90) return 'excellent';
|
|
52
|
+
if (score >= 75) return 'good';
|
|
53
|
+
if (score >= 60) return 'fair';
|
|
54
|
+
if (score >= 40) return 'needs-work';
|
|
55
|
+
return 'critical';
|
|
56
|
+
}
|