Here's a complete implementation of the YouTube clone frontend using React.js and Tailwind CSS:
// src/data/videos.js
export const videos = [
{
id: "1",
title: "Learn React in 10 Minutes",
channel: "DevTutor",
views: "200K",
date: "3d ago",
thumbnail: "https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg",
videoUrl: "https://www.w3schools.com/html/mov_bbb.mp4"
},
{
id: "2",
title: "JavaScript Fundamentals",
channel: "CodeMaster",
views: "150K",
date: "5d ago",
thumbnail: "https://i.ytimg.com/vi/ABC123/hqdefault.jpg",
videoUrl: "https://www.w3schools.com/html/movie.mp4"
},
// Add more dummy videos here...
]
// src/components/Navbar.jsx
import { Link } from 'react-router-dom';
const Navbar = () => {
return (
<nav className="bg-gray-800 text-white p-4 flex items-center">
<div className="flex-1">
<Link to="/" className="text-2xl font-bold">YouTube Clone</Link>
</div>
<div className="flex items-center space-x-4">
<input
type="text"
placeholder="Search..."
className="px-3 py-2 rounded-lg bg-gray-700"
/>
<button className="px-4 py-2 bg-red-500 rounded-lg text-white">Create</button>
<svg className="w-6 h-6" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M2.003 5.659a2.31 2.31 0 010-1.94 9.973 9.973 0 019.994 0a2.31 2.31 0 010 1.94 9.973 9.973 0 01-9.994 0zM12.027 15.659a2.31 2.31 0 000-1.94 9.973 9.973 0 00-9.994 0a2.31 2.31 0 000 1.94 9.973 9.973 0 009.994 0z"/></svg>
<img
src="https://i.pravatar.cc/30"
alt="Avatar"
className="rounded-full w-8 h-8"
/>
</div>
</nav>
);
};
export default Navbar;
// src/components/Sidebar.jsx
const Sidebar = () => {
return (
<div className="hidden md:block w-60 bg-gray-900 p-4 h-screen">
<ul className="space-y-2">
<li className="p-2 rounded-lg hover:bg-gray-700">
<Link to="/" className="text-white">Home</Link>
</li>
<li className="p-2 rounded-lg hover:bg-gray-700">
<Link to="/" className="text-white">Shorts</Link>
</li>
<li className="p-2 rounded-lg hover:bg-gray-700">
<Link to="/" className="text-white">Subscriptions</Link>
</li>
<li className="p-2 rounded-lg hover:bg-gray-700">
<Link to="/" className="text-white">History</Link>
</li>
</ul>
</div>
);
};
export default Sidebar;
// src/components/VideoCard.jsx
import { Link } from 'react-router-dom';
const VideoCard = ({ video }) => {
return (
<Link
to={`/watch/${video.id}`}
className="p-2 hover:bg-gray-800 rounded-lg transition duration-200"
>
<div className="relative aspect-video">
<img
src={video.thumbnail}
alt={video.title}
className="w-full h-full object-cover rounded-lg"
/>
</div>
<div className="mt-2">
<h3 className="text-white text-sm font-medium">{video.title}</h3>
<p className="text-gray-400 text-xs">{video.channel}</p>
<p className="text-gray-400 text-xs">{video.views} • {video.date}</p>
</div>
</Link>
);
};
export default VideoCard;