import { memo } from 'react'; import type { CSSProperties } from 'react'; import { IonButton, IonIcon, IonPopover } from '@ionic/react'; import { chevronDown } from 'ionicons/icons'; import { MAX_TEMPO_BPM, MIN_TEMPO_BPM } from '../domain/sequencer'; import { usePopoverDisclosure } from '../hooks/usePopoverDisclosure'; interface TempoControlProps { tempoBpm: number; onTempoChange: (tempoBpm: number) => void; } const TEMPO_TRACK_HEIGHT = 164; const TEMPO_THUMB_SIZE = 18; export const TempoControl = memo(function TempoControl({ tempoBpm, onTempoChange }: TempoControlProps) { const popover = usePopoverDisclosure(); const tempoProgress = ((tempoBpm - MIN_TEMPO_BPM) / (MAX_TEMPO_BPM - MIN_TEMPO_BPM)) * 100; const tempoThumbCenter = (TEMPO_TRACK_HEIGHT - TEMPO_THUMB_SIZE) / 2 + ((100 - tempoProgress) / 100) * (TEMPO_TRACK_HEIGHT - TEMPO_THUMB_SIZE); return ( <> popover.open(event.nativeEvent)} aria-label={`Change tempo, currently ${tempoBpm} BPM`} aria-haspopup="dialog" aria-expanded={popover.isOpen} > {tempoBpm} BPM {tempoBpm} BPM onTempoChange(event.currentTarget.valueAsNumber)} /> > ); });