- bar at the bottom of every page with cover, artists, controls, seek and time - full-screen player in a dialog: big cover, bar-style seek control, up next, focus kept inside, Escape closes - Space plays and pauses unless the key belongs to a field, a button or a link - songs list row, seek control and time formatting - jumpTo in the queue store for a click on an upcoming track
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import type { Track } from '@/api/catalog'
|
|
import { formatTime } from '@/lib/time'
|
|
import { cn } from '@/lib/utils'
|
|
|
|
interface TrackRowProps {
|
|
track: Track
|
|
/** Position in the list, shown when the track has no number of its own. */
|
|
index: number
|
|
onPlay(): void
|
|
/** The track that is playing now. */
|
|
active?: boolean
|
|
}
|
|
|
|
/** One song in a list: number, title, artists and length. Clicking it plays it. */
|
|
export default function TrackRow({ track, index, onPlay, active = false }: TrackRowProps) {
|
|
const artists = track.artists.map((a) => a.name).join(', ') || '—'
|
|
return (
|
|
<button
|
|
type="button"
|
|
onClick={onPlay}
|
|
aria-current={active ? 'true' : undefined}
|
|
className={cn(
|
|
'grid min-h-13 w-full grid-cols-[2.5rem_minmax(0,1fr)_4.5rem] items-center gap-3 rounded-lg px-4 text-left hover:bg-secondary',
|
|
active && 'bg-secondary',
|
|
)}
|
|
>
|
|
<span className={cn('tabular-nums', active ? 'font-bold text-primary' : 'text-muted-foreground')}>
|
|
{track.track_no > 0 ? track.track_no : index + 1}
|
|
</span>
|
|
<span className="min-w-0">
|
|
<span className={cn('block truncate font-semibold', active && 'text-primary')}>{track.title}</span>
|
|
<span className="block truncate text-sm text-muted-foreground">{artists}</span>
|
|
</span>
|
|
<span className="text-right text-sm tabular-nums text-muted-foreground">{formatTime(track.duration_ms)}</span>
|
|
</button>
|
|
)
|
|
}
|