ui · 6 variants · 1 categories
Audio Player
Audio player wrapper — minimal, podcast row, waveform, live radio, playlist, pill.
npx "@rueda.dev/gems-diamond" add audio-player Display
6 variants0:00
minimalOn the discipline of shipping
EP 03 · 12 MIN
podcast0:00
waveformNow playing
Diamond FM · Radio
radioplaylist0:00
pillUsage Guide
How to wire up this component in your app — props, callbacks, customization, and the conventions Diamond shares across the library.
Two ways to drive playback
- Autonomous — pass
srcand the component renders a hidden<audio>, tracks time via native events, and lets you seek by clicking the progress bar / waveform. - Controlled — pass
playing,progress,currentTime,durationand handleonPlayPauseToggle,onSeek. Useful for demos with no real audio, or when you orchestrate playback from a global store. - Hybrid — pass
srcand selectively override any display prop. The override wins.
Playback API
| Prop | Type | Description |
|---|---|---|
src | string | Audio URL. When set, renders a real <audio> and manages playback. |
loop | boolean | Loop natively. |
autoPlay | boolean | Try to autoplay on mount (subject to browser policy). |
volume | number (0..1) | Clamped and applied to the underlying element. |
muted | boolean | Mute natively. |
preload | "none" | "metadata" | "auto" | Default 'metadata'. |
onEnded / onTimeUpdate / onPlayingChange | callbacks | Native lifecycle, surfaced. |
Playlist variant
tracks accepts { id, title, duration?, src? }. Selecting a track swaps the source automatically. defaultActiveTrackId = uncontrolled, activeTrackId = controlled.
<AudioPlayer
variant="playlist"
defaultActiveTrackId={1}
tracks={[
{ id: 1, title: "Intro", src: "/audio/01.mp3", duration: "0:42" },
{ id: 2, title: "Body", src: "/audio/02.mp3", duration: "3:18" },
]}
onSelectTrack={(id) => analytics.track("track-changed", { id })}
/>Universal patterns
Every Diamond component shares the same prop conventions, so once you learn one you can predict the others.
variant— discriminated union of every visual option. Categories shown above are docs-only metadata; the prop is a flat string union.accent— any CSS color string. Overrides--diamond-accentjust for that instance via inlinestyle. Cascades into hover, ring, and selection states.asChild(when present) — renders the underlying primitive via@radix-ui/react-slot, letting you compose with<Link>,motion.button, etc.className— merged with internal Tailwind classes viacn(). Use it to override layout, spacing, or colors.- Native HTML attributes (
onClick,aria-*,data-*,ref, etc.) flow through to the root element without any whitelist. - Diamond is the skin: zero domain state, zero fetch, zero providers. You wire data and reactions in your app code; the components just render and emit events.