feat: implement dynamic theme support across chat components, enhancing UI consistency with reactive color updates and gradient functionalities
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
import NewConversationModal from './NewConversationModal.svelte';
|
||||
import { Search, Plus, MessageSquare, Users, UsersRound } from 'lucide-svelte';
|
||||
import type { Id, Doc } from '@sgse-app/backend/convex/_generated/dataModel';
|
||||
import { obterCoresDoTema } from '$lib/utils/temas';
|
||||
|
||||
const client = useConvexClient();
|
||||
|
||||
@@ -23,6 +24,57 @@
|
||||
|
||||
let searchQuery = $state('');
|
||||
let activeTab = $state<'usuarios' | 'conversas'>('usuarios');
|
||||
|
||||
// Obter cores do tema atual (reativo)
|
||||
let coresTema = $state(obterCoresDoTema());
|
||||
|
||||
// Atualizar cores quando o tema mudar
|
||||
$effect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
const atualizarCores = () => {
|
||||
coresTema = obterCoresDoTema();
|
||||
};
|
||||
|
||||
atualizarCores();
|
||||
|
||||
window.addEventListener('themechange', atualizarCores);
|
||||
|
||||
const observer = new MutationObserver(atualizarCores);
|
||||
const htmlElement = document.documentElement;
|
||||
observer.observe(htmlElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ['data-theme']
|
||||
});
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('themechange', atualizarCores);
|
||||
observer.disconnect();
|
||||
};
|
||||
});
|
||||
|
||||
// Função para obter rgba da cor primária
|
||||
function obterPrimariaRgba(alpha: number = 1) {
|
||||
const primary = coresTema.primary;
|
||||
if (primary.startsWith('rgba')) {
|
||||
const match = primary.match(/rgba?\(([^)]+)\)/);
|
||||
if (match) {
|
||||
const values = match[1].split(',');
|
||||
return `rgba(${values[0]}, ${values[1]}, ${values[2]}, ${alpha})`;
|
||||
}
|
||||
}
|
||||
if (primary.startsWith('#')) {
|
||||
const hex = primary.replace('#', '');
|
||||
const r = parseInt(hex.substring(0, 2), 16);
|
||||
const g = parseInt(hex.substring(2, 4), 16);
|
||||
const b = parseInt(hex.substring(4, 6), 16);
|
||||
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
||||
}
|
||||
if (primary.startsWith('hsl')) {
|
||||
return primary.replace(/\)$/, `, ${alpha})`).replace('hsl', 'hsla');
|
||||
}
|
||||
return `rgba(102, 126, 234, ${alpha})`;
|
||||
}
|
||||
|
||||
// Debug: monitorar carregamento de dados
|
||||
$effect(() => {
|
||||
@@ -263,7 +315,7 @@
|
||||
<!-- Ícone de mensagem -->
|
||||
<div
|
||||
class="flex h-10 w-10 shrink-0 items-center justify-center rounded-xl transition-all duration-300 hover:scale-110"
|
||||
style="background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%); border: 1px solid rgba(102, 126, 234, 0.2);"
|
||||
style="background: linear-gradient(135deg, {obterPrimariaRgba(0.1)} 0%, {obterPrimariaRgba(0.1)} 100%); border: 1px solid {obterPrimariaRgba(0.2)};"
|
||||
>
|
||||
<MessageSquare class="text-primary h-5 w-5" strokeWidth={2} />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user