opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Audio
  4. Music Playlist
Back to Audio

Components / Audio

Music Playlist

Free Audio React component — MusicPlaylistCard. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Playlist card with cover, header stats, and a track list where each row toggles play independently. One component, full playlist UI.

Preview

Chill Vibes

Playlist

Chill Vibes

24 songs · 1h 32m

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/audio/music-playlist-card.tsx in your project.

  4. 4

    Import and render:

    Example

    import { MusicPlaylistCard } from "@/components/audio/music-playlist-card";

    <MusicPlaylistCard />

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/audio/music-playlist-card.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
"use client";
 
import { forwardRef, useState, type ComponentPropsWithoutRef } from "react";
 
import Image from "next/image";
 
import { cn } from "@/lib/cn";
 
import { Pause, Play } from "lucide-react";
 
export type PlaylistTrack = {
title: string;
artist: string;
duration: string;
};
 
export type MusicPlaylistCardProps = Readonly<
{
coverImage?: string;
playlistType?: string;
title?: string;
songCount?: string;
totalDuration?: string;
tracks?: PlaylistTrack[];
} & ComponentPropsWithoutRef<"div">
>;
 
// Production-ready Music Playlist component — styled with Tailwind CSS.
export const MusicPlaylistCard = forwardRef<
HTMLDivElement,
MusicPlaylistCardProps
>(
(
{
className,
coverImage = "/wallpaper-3.png",
playlistType = "Playlist",
title = "Chill Vibes",
songCount = "24 songs",
totalDuration = "1h 32m",
tracks = [
{
title: "Blinding Lights",
artist: "The Weekend",
duration: "3:20",
},
{
title: "Save Your Tears",
artist: "The Weekend",
duration: "3:35",
},
{
title: "Starboy",
artist: "The Weekend",
duration: "3:50",
},
],
...props
},
ref,
) => {
const [playingIndex, setPlayingIndex] = useState<number | null>(null);
 
const toggleTrack = (index: number) => {
setPlayingIndex((prev) => (prev === index ? null : index));
};
 
return (
<div
ref={ref}
data-slot="music-playlist-card"
className={cn(
"w-72 overflow-hidden rounded-2xl border border-neutral-100 bg-white font-sans shadow-lg",
className,
)}
{...props}
>
<div data-slot="music-playlist-card-header" className="flex gap-3 p-4">
<div
data-slot="music-playlist-card-cover"
className="relative h-16 w-16 shrink-0 overflow-hidden rounded-xl shadow-sm"
>
<Image
src={coverImage}
alt={title}
fill
sizes="64px"
className="object-cover"
/>
</div>
 
<div data-slot="music-playlist-card-info">
<p className="font-mono text-[10px] tracking-wider text-neutral-400 uppercase">
{playlistType}
</p>
 
<h3 className="mt-0.5 text-sm font-semibold text-neutral-900">
{title}
</h3>
 
<p className="mt-0.5 text-[11px] text-neutral-500">
{songCount} · {totalDuration}
</p>
</div>
</div>
 
<div
data-slot="music-playlist-card-tracks"
className="divide-y divide-neutral-50"
>
{tracks.map((track, index) => {
const isPlaying = playingIndex === index;
 
return (
<button
key={`${track.title}-${track.artist}`}
type="button"
onClick={() => toggleTrack(index)}
data-slot="music-playlist-card-track"
className={cn(
"group flex w-full cursor-pointer items-center gap-3 px-4 py-2.5 text-left transition-colors hover:bg-neutral-50",
isPlaying && "bg-emerald-50/80",
)}
>
<span
className={cn(
"w-4 font-mono text-[10px] text-neutral-400",
isPlaying ? "hidden" : "group-hover:hidden",
)}
>
{index + 1}
</span>
 
<span
className={cn(
"w-4 text-[10px] text-emerald-600",
isPlaying ? "block" : "hidden group-hover:block",
)}
>
{isPlaying ? (
<Pause size={12} fill="green" />
) : (
<Play size={12} fill="green" />
)}
</span>
 
<div className="min-w-0 flex-1">
<p
className={cn(
"truncate text-xs font-medium",
isPlaying ? "text-emerald-700" : "text-neutral-800",
)}
>
{track.title}
</p>
 
<p className="text-[10px] text-neutral-400">{track.artist}</p>
</div>
 
<span className="font-mono text-[10px] text-neutral-400">
{track.duration}
</span>
</button>
);
})}
</div>
</div>
);
},
);
 
MusicPlaylistCard.displayName = "MusicPlaylistCard";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/audio/music-playlist-card.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.