import React from 'react'; import { IonPopover, IonList, IonItem, IonLabel, IonAvatar } from '@ionic/react'; import { bookOutline } from 'ionicons/icons'; import { useTranslation } from 'react-i18next'; import { MdxProfile } from '../types'; import { getIconUrl } from '../utils/iframeTools/mdxHtmlTools'; interface ProfileListMenuProps { profiles: MdxProfile[]; activeProfileId: number; onProfileSelect: (profileId: number) => void; anchorEl: HTMLElement | null; open: boolean; onClose: () => void; } /** * ProfileListMenu Component * * A dropdown menu component that displays a list of profiles (dictionaries). * Uses Ionic Popover component for consistent behavior. * This component only handles the menu rendering - the trigger button * should be managed by the parent component. * * @example * ```tsx * handleProfileChange(profileId)} * anchorEl={anchorEl} * open={open} * onClose={() => setAnchorEl(null)} * /> * ``` */ export const ProfileListMenu: React.FC = ({ profiles, activeProfileId, onProfileSelect, anchorEl, open, onClose, }) => { const { t } = useTranslation(); const handleProfileSelect = (profileId: number) => { onProfileSelect(profileId); onClose(); }; // Don't render menu if there are no profiles or only one profile if (!profiles.length || profiles.length <= 1) { return null; } return ( {/* Header */}
{t('Select Dictionary ({count} total)', { count: profiles.length })}
{/* Profile list */} {profiles.map((profile) => { const isActive = profile.profileId === activeProfileId; return ( handleProfileSelect(profile.profileId)} color={isActive ? 'light' : undefined} style={{ '--padding-start': '16px', '--padding-end': '16px', '--min-height': '40px', }} > { // Fallback to icon if image fails to load e.currentTarget.style.display = 'none'; e.currentTarget.parentElement!.innerHTML = ` `; }} />
{profile.title}
{isActive && (
)} ); })} ); }; export default ProfileListMenu;