/** * Theme Select Modal * A modal dialog for selecting terminal themes in settings */ import React, { memo, useCallback, useMemo } from 'react'; import { createPortal } from 'react-dom'; import { Check, Palette, X } from 'lucide-react'; import { useI18n } from '../../application/i18n/I18nProvider'; import { TERMINAL_THEMES, TerminalThemeConfig } from '../../infrastructure/config/terminalThemes'; import { Button } from '../ui/button'; import { cn } from '../../lib/utils'; // Memoized theme item component to prevent unnecessary re-renders const ThemeItem = memo(({ theme, isSelected, onSelect }: { theme: TerminalThemeConfig; isSelected: boolean; onSelect: (id: string) => void; }) => ( )); ThemeItem.displayName = 'ThemeItem'; interface ThemeSelectModalProps { open: boolean; onClose: () => void; selectedThemeId: string; onSelect: (themeId: string) => void; } export const ThemeSelectModal: React.FC = ({ open, onClose, selectedThemeId, onSelect, }) => { const { t } = useI18n(); // Group themes by type const { darkThemes, lightThemes } = useMemo(() => { const dark = TERMINAL_THEMES.filter(t => t.type === 'dark'); const light = TERMINAL_THEMES.filter(t => t.type === 'light'); return { darkThemes: dark, lightThemes: light }; }, []); // Handle theme selection - select and close const handleThemeSelect = useCallback((themeId: string) => { onSelect(themeId); onClose(); }, [onSelect, onClose]); // Handle ESC key React.useEffect(() => { if (!open) return; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; document.addEventListener('keydown', handleKeyDown); return () => document.removeEventListener('keydown', handleKeyDown); }, [open, onClose]); // Handle backdrop click const handleBackdropClick = useCallback((e: React.MouseEvent) => { if (e.target === e.currentTarget) onClose(); }, [onClose]); if (!open) return null; const modalTitleId = 'theme-select-modal-title'; const modalContent = (
e.stopPropagation()} > {/* Header */}

{t('settings.terminal.themeModal.title')}

{/* Theme List */}
{/* Dark Themes Section */}
{t('settings.terminal.themeModal.darkThemes')}
{darkThemes.map(theme => ( ))}
{/* Light Themes Section */}
{t('settings.terminal.themeModal.lightThemes')}
{lightThemes.map(theme => ( ))}
{/* Footer */}
); // Use Portal to render at document root return createPortal(modalContent, document.body); }; export default ThemeSelectModal;