import { useState, useEffect } from 'react'; import { Type, Sun, MonitorOff, RotateCcw, Accessibility, Eye, Volume2 } from 'lucide-react'; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { useTranslation } from 'react-i18next'; const AccessibilityMenu = () => { const { i18n } = useTranslation(); const [fontSize, setFontSize] = useState(100); const [highContrast, setHighContrast] = useState(false); const [grayscale, setGrayscale] = useState(false); const [readableFont, setReadableFont] = useState(false); const [screenReader, setScreenReader] = useState(false); // Apply changes to the document useEffect(() => { const root = document.documentElement; // Font Size root.style.fontSize = `${fontSize}%`; // High Contrast if (highContrast) { root.classList.add('high-contrast'); document.body.style.backgroundColor = '#000'; document.body.style.color = '#fff'; // Force specific elements to contrast const cards = document.querySelectorAll('.bg-white'); cards.forEach((el: any) => { el.style.backgroundColor = '#1a1a1a'; el.style.color = '#fff'; el.style.borderColor = '#333'; }); } else { root.classList.remove('high-contrast'); document.body.style.backgroundColor = ''; document.body.style.color = ''; const cards = document.querySelectorAll('.bg-white'); cards.forEach((el: any) => { el.style.backgroundColor = ''; el.style.color = ''; el.style.borderColor = ''; }); } // Grayscale if (grayscale) { root.style.filter = 'grayscale(100%)'; } else { root.style.filter = ''; } // Readable Font if (readableFont) { document.body.classList.add('readable-font'); document.body.style.fontFamily = 'Arial, Helvetica, sans-serif'; document.body.style.lineHeight = '1.8'; document.body.style.letterSpacing = '0.05em'; } else { document.body.classList.remove('readable-font'); document.body.style.fontFamily = ''; document.body.style.lineHeight = ''; document.body.style.letterSpacing = ''; } }, [fontSize, highContrast, grayscale, readableFont]); // Simple Screen Reader Simulation (reads hovered text) useEffect(() => { if (!screenReader) { window.speechSynthesis.cancel(); return; } const handleMouseOver = (e: MouseEvent) => { const target = e.target as HTMLElement; if (target && (target.innerText || target.getAttribute('aria-label'))) { window.speechSynthesis.cancel(); const text = target.getAttribute('aria-label') || target.innerText; if (text && text.trim().length > 0) { // Filter out long text blocks to avoid annoyance if (text.length < 200) { const utterance = new SpeechSynthesisUtterance(text); // Try to match language utterance.lang = i18n.language === 'hi' ? 'hi-IN' : 'en-US'; window.speechSynthesis.speak(utterance); } } } }; document.addEventListener('mouseover', handleMouseOver); return () => { document.removeEventListener('mouseover', handleMouseOver); window.speechSynthesis.cancel(); }; }, [screenReader, i18n.language]); const resetSettings = () => { setFontSize(100); setHighContrast(false); setGrayscale(false); setReadableFont(false); setScreenReader(false); }; return (
Accessibility Tools {/* Font Size Control */}
Text Size ({fontSize}%)
{/* Display Options */}
); }; export default AccessibilityMenu;