feat: enhance sidebar and theme utilities for improved UI consistency
- Updated the Sidebar component styles to utilize theme-based classes for better visual consistency. - Added new utility functions to retrieve and convert theme colors for use in components, enhancing theming capabilities. - Improved layout logic to ensure the default theme is applied correctly based on user preferences and document readiness.
This commit is contained in:
@@ -192,3 +192,89 @@ export function obterTemaPadrao(): Tema {
|
||||
return temasDisponiveis[0]; // Purple
|
||||
}
|
||||
|
||||
/**
|
||||
* Obter cores CSS do tema atual para usar em gráficos e componentes
|
||||
*/
|
||||
export function obterCoresDoTema(): {
|
||||
primary: string;
|
||||
success: string;
|
||||
error: string;
|
||||
warning: string;
|
||||
info: string;
|
||||
baseContent: string;
|
||||
base100: string;
|
||||
base200: string;
|
||||
base300: string;
|
||||
} {
|
||||
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
||||
// Valores padrão para SSR
|
||||
return {
|
||||
primary: '#667eea',
|
||||
success: '#10b981',
|
||||
error: '#ef4444',
|
||||
warning: '#f59e0b',
|
||||
info: '#3b82f6',
|
||||
baseContent: '#1f2937',
|
||||
base100: '#ffffff',
|
||||
base200: '#f3f4f6',
|
||||
base300: '#e5e7eb'
|
||||
};
|
||||
}
|
||||
|
||||
const htmlElement = document.documentElement;
|
||||
const getComputedStyle = (varName: string): string => {
|
||||
return getComputedStyle(htmlElement).getPropertyValue(varName).trim() || '';
|
||||
};
|
||||
|
||||
// Tentar obter variáveis CSS do DaisyUI
|
||||
const primary = getComputedStyle('--p') || '#667eea';
|
||||
const success = getComputedStyle('--suc') || '#10b981';
|
||||
const error = getComputedStyle('--er') || '#ef4444';
|
||||
const warning = getComputedStyle('--wa') || '#f59e0b';
|
||||
const info = getComputedStyle('--in') || '#3b82f6';
|
||||
const baseContent = getComputedStyle('--bc') || '#1f2937';
|
||||
const base100 = getComputedStyle('--b1') || '#ffffff';
|
||||
const base200 = getComputedStyle('--b2') || '#f3f4f6';
|
||||
const base300 = getComputedStyle('--b3') || '#e5e7eb';
|
||||
|
||||
return {
|
||||
primary: primary || '#667eea',
|
||||
success: success || '#10b981',
|
||||
error: error || '#ef4444',
|
||||
warning: warning || '#f59e0b',
|
||||
info: info || '#3b82f6',
|
||||
baseContent: baseContent || '#1f2937',
|
||||
base100: base100 || '#ffffff',
|
||||
base200: base200 || '#f3f4f6',
|
||||
base300: base300 || '#e5e7eb'
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Converter cor hex para rgba
|
||||
*/
|
||||
export function hexToRgba(hex: string, alpha: number = 1): string {
|
||||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
if (!result) return `rgba(102, 126, 234, ${alpha})`;
|
||||
|
||||
const r = parseInt(result[1], 16);
|
||||
const g = parseInt(result[2], 16);
|
||||
const b = parseInt(result[3], 16);
|
||||
|
||||
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converter cor hex para rgb
|
||||
*/
|
||||
export function hexToRgb(hex: string): string {
|
||||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
if (!result) return 'rgb(102, 126, 234)';
|
||||
|
||||
const r = parseInt(result[1], 16);
|
||||
const g = parseInt(result[2], 16);
|
||||
const b = parseInt(result[3], 16);
|
||||
|
||||
return `rgb(${r}, ${g}, ${b})`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user