Files
beat-hound/src/components/BeatSelectionHint.tsx
T

42 lines
1.2 KiB
TypeScript

import { memo } from 'react';
import { getLoopPositionPercent } from '../domain/timeline';
import { INSTRUMENT_BY_ID } from '../domain/instruments';
import type { BeatPoint } from '../domain/sequencer';
import type { InstrumentId } from '../domain/instruments';
interface BeatSelectionHintProps {
selectedBeat: BeatPoint | undefined;
focusedSoundId: InstrumentId | null;
colorBySoundId: Partial<Record<InstrumentId, string>>;
totalSteps: number;
}
export const BeatSelectionHint = memo(function BeatSelectionHint({
selectedBeat,
focusedSoundId,
colorBySoundId,
totalSteps,
}: BeatSelectionHintProps) {
const soundId = selectedBeat?.soundId ?? focusedSoundId;
if (!soundId) return <p className="timeline-hint" aria-live="polite" />;
const sound = INSTRUMENT_BY_ID[soundId];
return (
<p className="timeline-hint" aria-live="polite">
<span
className="hint-swatch"
style={{ backgroundColor: colorBySoundId[soundId] }}
/>
{sound.label}
{selectedBeat && (
<>
<span className="hint-separator">·</span>
Step {getLoopPositionPercent(selectedBeat.step, totalSteps)}% selected
</>
)}
{!selectedBeat && ' ring selected'}
</p>
);
});