YouTube Clone UI with React.js and Tailwind CSS
Below is a simple implementation of the YouTube Clone UI using React.js and Tailwind CSS.
Step 1: Setup the Project
First, let's create a new React project and install the required dependencies.
npx create-react-app youtube-clone
cd youtube-clone
npm install react-router-dom tailwindcss
npx tailwindcss init -p
Configure Tailwind CSS by updating the tailwind.config.js file.
// tailwind.config.js
module.exports = {
content: [
"./src/**/*.{js,jsx,ts,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
Step 2: Create Dummy Video Data
Create a new file src/data/videos.js and add the dummy video data.
// src/data/videos.js
const videos = [
{
id: "1",
title: "Learn React in 10 Minutes",
channel: "DevTutor",
views: "200K views",
date: "3 days ago",
thumbnail: "https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg",
videoUrl: "https://www.w3schools.com/html/mov_bbb.mp4"
},
{
id: "2",
title: "Learn JavaScript in 10 Minutes",
channel: "DevTutor",
views: "150K views",
date: "5 days ago",
thumbnail: "https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg",
videoUrl: "https://www.w3schools.com/html/mov_bbb.mp4"
},
// Add more videos here...
];
export default videos;
Step 3: Create Components
Create the required components.
Navbar.jsx
// src/components/Navbar.jsx
import React from 'react';
const Navbar = () => {
return (
<nav className="flex justify-between items-center py-2 px-4 border-b border-gray-200">
<div className="flex items-center">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b8/YouTube_Logo_2017.svg/2560px-YouTube_Logo_2017.svg.png" alt="YouTube Logo" className="h-6 mr-2" />
<span className="text-lg font-bold">YouTube Clone</span>
</div>
<div className="flex items-center">
<input type="search" placeholder="Search" className="px-4 py-2 border border-gray-300 rounded-l-full" />
<button className="px-4 py-2 border border-gray-300 rounded-r-full bg-gray-100 hover:bg-gray-200">
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path fillRule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clipRule="evenodd" />
</svg>
</button>
</div>
<div className="flex items-center">
<button className="px-4 py-2 mx-2 bg-gray-100 hover:bg-gray-200 rounded-full">
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" />
</svg>
</button>
<button className="px-4 py-2 mx-2 bg-gray-100 hover:bg-gray-200 rounded-full">
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
<path d="M10 2a6 6 0 00-6 6v3.586l-.707.707A1 1 0 004 14h12a1 1 0 00.707-1.707L16 11.586V8a6 6 0 00-6-6zM10 18a3 3 0 01-3-3h6a3 3 0 01-3 3z" />
</svg>
</button>
<img src="https://via.placeholder.com/40" alt="Avatar" className="h-10 w-10 rounded-full" />
</div>
</nav>
);
};
export default Navbar;