feat: add Tooltip component and related hooks for improved UI interactions

- Implemented Tooltip component using Radix UI for better accessibility and customization.
- Created TooltipProvider, TooltipTrigger, and TooltipContent for modular usage.
- Added useIsMobile hook to detect mobile devices based on screen width.
- Updated themes with new color variables for better design consistency across the application.
This commit is contained in:
2025-07-03 15:34:53 +00:00
committed by GitHub
parent f25b4dcac1
commit 7b622cb1ec
44 changed files with 6021 additions and 472 deletions

View File

@@ -2,12 +2,14 @@
import React, { createContext, useContext, useEffect, useState } from 'react';
type Theme = 'blue' | 'violet' | 'red' | 'rose' | 'orange' | 'green' | 'yellow';
type Theme = 'default' | 'blue' | 'violet' | 'red' | 'rose' | 'orange' | 'green' | 'yellow';
type Mode = 'light' | 'dark' | 'system';
interface ThemeContextType {
theme: Theme;
mode: Mode;
setTheme: (theme: Theme) => void;
setMode: (mode: Mode) => void;
}
const ThemeContext = createContext<ThemeContextType | undefined>(undefined);
@@ -25,18 +27,25 @@ interface ThemeProviderProps {
}
export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
const [theme, setTheme] = useState<Theme>('blue');
const [theme, setTheme] = useState<Theme>('default');
const [mode, setMode] = useState<Mode>('system');
const [mounted, setMounted] = useState(false);
// Load theme settings from localStorage on component mount
useEffect(() => {
setMounted(true);
const savedTheme = localStorage.getItem('theme');
const validThemes: Theme[] = ['blue', 'violet', 'red', 'rose', 'orange', 'green', 'yellow'];
const savedMode = localStorage.getItem('theme-mode');
const validThemes: Theme[] = ['default', 'blue', 'violet', 'red', 'rose', 'orange', 'green', 'yellow'];
const validModes: Mode[] = ['light', 'dark', 'system'];
if (savedTheme && validThemes.includes(savedTheme as Theme)) {
setTheme(savedTheme as Theme);
}
if (savedMode && validModes.includes(savedMode as Mode)) {
setMode(savedMode as Mode);
}
}, []);
// Apply theme changes
@@ -46,35 +55,54 @@ export const ThemeProvider: React.FC<ThemeProviderProps> = ({ children }) => {
const root = document.documentElement;
// Remove existing theme classes
root.classList.remove('theme-blue', 'theme-violet', 'theme-red', 'theme-rose', 'theme-orange', 'theme-green', 'theme-yellow', 'dark');
root.classList.remove('theme-default', 'theme-blue', 'theme-violet', 'theme-red', 'theme-rose', 'theme-orange', 'theme-green', 'theme-yellow', 'dark');
// Add new theme class
root.classList.add(`theme-${theme}`);
// Always follow system preference for dark mode
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
const applySystemTheme = () => {
root.classList.toggle('dark', mediaQuery.matches);
// Apply dark/light mode
const applyMode = () => {
if (mode === 'dark') {
root.classList.add('dark');
} else if (mode === 'light') {
root.classList.remove('dark');
} else { // system
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
root.classList.toggle('dark', mediaQuery.matches);
}
};
applySystemTheme();
mediaQuery.addEventListener('change', applySystemTheme);
applyMode();
// Save theme to localStorage
// Listen for system preference changes only if mode is 'system'
let mediaQuery: MediaQueryList | null = null;
if (mode === 'system') {
mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
mediaQuery.addEventListener('change', applyMode);
}
// Save settings to localStorage
localStorage.setItem('theme', theme);
localStorage.setItem('theme-mode', mode);
// Cleanup listener
return () => mediaQuery.removeEventListener('change', applySystemTheme);
}, [theme, mounted]);
return () => {
if (mediaQuery) {
mediaQuery.removeEventListener('change', applyMode);
}
};
}, [theme, mode, mounted]);
return (
<ThemeContext.Provider
value={{
theme,
mode,
setTheme,
setMode,
}}
>
<div className={`theme-${theme}`}>
<div>
{children}
</div>
</ThemeContext.Provider>