import { memo } from 'react'; import { IonButton, IonIcon, IonPopover } from '@ionic/react'; import { chevronDown } from 'ionicons/icons'; import { INSTRUMENT_BY_ID } from '../domain/instruments'; import type { InstrumentId } from '../domain/instruments'; import { usePopoverDisclosure } from '../hooks/usePopoverDisclosure'; interface SoundRingSelectorProps { soundIds: readonly InstrumentId[]; focusedSoundId: InstrumentId | null; colorBySoundId: Partial>; onSelectSound: (soundId: InstrumentId) => void; } export const SoundRingSelector = memo(function SoundRingSelector({ soundIds, focusedSoundId, colorBySoundId, onSelectSound, }: SoundRingSelectorProps) { const popover = usePopoverDisclosure(); const focusedSound = focusedSoundId ? INSTRUMENT_BY_ID[focusedSoundId] : undefined; return ( <> popover.open(event.nativeEvent)} aria-label={focusedSound ? `Selected ring: ${focusedSound.label}` : 'Select a sound ring'} aria-haspopup="dialog" aria-expanded={popover.isOpen} > {focusedSoundId && ( )} {focusedSound ? `${focusedSound.label} ring` : 'Sound rings'}
{soundIds.map((soundId) => { const selected = soundId === focusedSoundId; return ( { popover.close(); onSelectSound(soundId); }} > {INSTRUMENT_BY_ID[soundId].label} ring ); })}
); });