MCPcopy Create free account
hub / github.com/chokcoco/iCSS / LanguageToggle

Function LanguageToggle

website/app/components/LanguageToggle.tsx:8–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6import { ChevronDown, Globe } from 'lucide-react';
7
8export default function LanguageToggle() {
9 const { language, setLanguage } = useApp();
10 const [isOpen, setIsOpen] = useState(false);
11 const dropdownRef = useRef<HTMLDivElement>(null);
12
13 const currentLanguage = languages.find(l => l.value === language) || languages[0];
14
15 useEffect(() => {
16 function handleClickOutside(event: MouseEvent) {
17 if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
18 setIsOpen(false);
19 }
20 }
21
22 document.addEventListener('mousedown', handleClickOutside);
23 return () => {
24 document.removeEventListener('mousedown', handleClickOutside);
25 };
26 }, []);
27
28 return (
29 <div className="relative" ref={dropdownRef}>
30 <button
31 onClick={() => setIsOpen(!isOpen)}
32 className="flex items-center space-x-2 px-3 py-2 text-sm font-medium text-gray-700 dark:text-gray-200 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500 transition-colors"
33 >
34 <Globe className="w-4 h-4" />
35 <span>{currentLanguage.flag}</span>
36 <span>{currentLanguage.name}</span>
37 <ChevronDown className={`w-4 h-4 transition-transform ${isOpen ? 'rotate-180' : ''}`} />
38 </button>
39
40 {isOpen && (
41 <div className="absolute right-0 mt-2 w-48 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg shadow-lg z-50">
42 <div className="py-1">
43 {languages.map((languageOption: LanguageConfig) => (
44 <button
45 key={languageOption.value}
46 onClick={() => {
47 setLanguage(languageOption.value);
48 setIsOpen(false);
49 }}
50 className={`w-full flex items-center space-x-3 px-4 py-2 text-sm text-left hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors ${
51 language === languageOption.value
52 ? 'bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300'
53 : 'text-gray-700 dark:text-gray-200'
54 }`}
55 >
56 <span className="text-lg">{languageOption.flag}</span>
57 <span>{languageOption.name}</span>
58 </button>
59 ))}
60 </div>
61 </div>
62 )}
63 </div>
64 );
65}

Callers

nothing calls this directly

Calls 2

useAppFunction · 0.90
setLanguageFunction · 0.85

Tested by

no test coverage detected