Ir al contenido
Español

Cómo funciona

One card surface: a tint from the track's tone glows from the top, the cover is abstract art drawn with CSS gradients, and the footer is the only soft-filled group. A change of track is derived during render, so the first frame already holds the old cover, titles and tint beside the new ones. Progress has no frame loop: the bar is one linear Web Animation run by the compositor, React re-renders once a second for the time, and both stop while the card is off screen or the tab is hidden. The likes row unfolds with a grid-template-rows 0fr to 1fr transition, so its height animates to its content.

Úsalo para

  • A now-playing widget for music, podcasts or voice notes in an app or dashboard.
  • A media preview where liking and seeing who liked belong with the player.

Busca otra opción cuando

  • A full player with a queue, lyrics and volume: build a page.
  • A list of many tracks: use a list with a small play button per row.

Uso

import { useState } from 'react'
import { TrackCard } from './TrackCard.jsx'

const tracks = [
  { id: 'a', title: 'Low Tide Letters', artist: 'Harbor Lights Trio', duration: 214, tone: 7, likes: 128, likers: [{ id: 'u1', name: 'Maya Ortiz', when: '2 min ago' }] },
  { id: 'b', title: 'Paper Satellites', artist: 'Juno Vale', duration: 187, tone: 5, likes: 96, likers: [] },
]

export function NowPlaying() {
  const [index, setIndex] = useState(0)
  const [playing, setPlaying] = useState(false)
  return (
    <TrackCard
      tracks={tracks}
      index={index}
      onIndexChange={setIndex}
      playing={playing}
      onPlayingChange={setPlaying}
      onLikedChange={(liked, track) => console.log(track.id, liked)}
    />
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
tracks{ id, title, artist, duration, cover?, glow?, tone?, art?, likes?, liked?, likers? }[][]The queue. duration is in seconds; tone (chart colour 1-8) colours the cover and the tint behind the card; art picks one of three gradient covers (0-2, default by position). likes counts other people (the viewer's like adds one); likers is { id?, name, initials?, when?, tone? }[]. cover is a picture URL for the art (square works best; it fills the frame), and glow the colour behind the card, best taken from the cover; without cover the art is drawn with CSS gradients from tone.
index / defaultIndex / onIndexChangenumber / number / (index, track) => void- / 0 / -The current track, controlled or uncontrolled. Previous and next wrap around; the end of a track moves to the next one.
playing / defaultPlaying / onPlayingChangeboolean / boolean / (playing) => void- / false / -Whether the track plays. While playing, the bar runs as one linear Web Animation (no frame loop) and the time label updates each second; both pause while the card is off screen or the tab is hidden, and the clock keeps wall time.
liked / defaultLiked / onLikedChangeboolean / boolean / (liked, track) => void- / false / -The heart for the current track. Uncontrolled, it is remembered per track id (seeded from track.liked).
expanded / defaultExpanded / onExpandedChangeboolean / boolean / (expanded) => void- / false / -Whether the likes row shows the list of people.
defaultElapsednumber0Seconds already played of the first track.
freezebooleanfalseStops the clock without changing playing (for previews and screenshots).
labelsobject—Replaces built-in text: region, play, pause, previous, next, like, seek, time(elapsed, total), likes(n), likesUnit(n), likers, you, justNow, formatCount(n), trackOf(i, n). Shallow-merged over the English defaults.
...restHTMLAttributes—Other attributes go to the root <section>.

Accesibilidad

  • The card is a region named "Now playing"; the title and artist are announced politely when the track changes, with its position in the queue.
  • Play / pause is one button whose name follows the state; the heart is a toggle button with aria-pressed; the likes row has aria-expanded and aria-controls, and the closed list is inert.
  • The progress is a slider: Left / Right move 5 seconds, PageUp / PageDown 30, Home and End go to the ends; its value text reads "0:48 of 3:34".
  • Every control is a real button reachable with Tab and has a visible focus ring; buttons are 40 to 56px (44px on touch screens).
  • Leaving layers are aria-hidden and the cover is decorative.
  • Reduced motion swaps tracks at once, fades the play icon without rotating and opens the list without height animation.

Movimiento

Track change: the old cover blurs to 8px, scales to 0.96 and fades in 360ms while the new one sharpens from 8px blur and 1.04 in 440ms ease-out; the titles leave 12px against the travel direction in 240ms and the new ones rise 14px from the travel side with a 4px blur in 380ms, the artist 60ms later; the tint crossfades in 520ms and the bar eases back to the start in 420ms. Play / pause: the glyphs swap with scale 0.4 and a 90 degree turn on a light spring (340ms). Heart: squash, stretch and settle in 520ms with the fill springing in; changed digits of the count roll up or down in 300ms. Likes row: grid-template-rows 0fr to 1fr in 320ms, the chevron turns, rows fade up 6px with a 40ms stagger.

Añádelo a tu proyecto

Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.

TrackCard.jsxtrack-card.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Tarjetas
Tarjeta con borde animado viene con Pro. La vista previa aparece al desbloquearlo.
Borde con haz de luz viene con Pro. La vista previa aparece al desbloquearlo.
Tarjeta con hoja de datos viene con Pro. La vista previa aparece al desbloquearlo.