tahamajs's picture
download
raw
7.44 kB
// src/components/blog/BlogCard.tsx
import { Link } from "react-router-dom";
import { Calendar, Eye, Heart, MessageCircle, Bookmark, Clock, User } from "lucide-react";
import { motion } from "framer-motion";
import { BlogPost } from "@/types/blog";
import { useState } from "react";
interface BlogCardProps {
post: BlogPost;
variant?: "default" | "featured" | "compact";
className?: string;
}
export function BlogCard({ post, variant = "default", className = "" }: BlogCardProps) {
const [imageLoaded, setImageLoaded] = useState(false);
if (variant === "compact") {
return (
<Link to={`/blog/${post.slug}`} className={`group flex gap-3 p-3 rounded-xl hover:bg-gray-50 dark:hover:bg-gray-800 transition ${className}`}>
<div className="w-20 h-20 rounded-lg overflow-hidden flex-shrink-0">
<img
src={post.coverImage}
alt={post.title}
className="w-full h-full object-cover group-hover:scale-110 transition duration-300"
/>
</div>
<div className="flex-1 min-w-0">
<h4 className="font-medium text-sm line-clamp-2 group-hover:text-primary transition">{post.title}</h4>
<div className="flex items-center gap-2 mt-1 text-xs text-gray-500">
<span>{new Date(post.publishedAt ?? post.createdAt).toLocaleDateString()}</span>
<span>•</span>
<span>{post.readTime ?? 0} min read</span>
</div>
</div>
</Link>
);
}
if (variant === "featured") {
return (
<Link to={`/blog/${post.slug}`} className={`group relative overflow-hidden rounded-2xl ${className}`}>
<div className="absolute inset-0 bg-gradient-to-t from-black/80 via-black/30 to-transparent z-10" />
<img
src={post.coverImage}
alt={post.title}
className="w-full h-96 object-cover group-hover:scale-105 transition duration-500"
/>
<div className="absolute bottom-0 left-0 right-0 p-6 z-20">
{post.featured && (
<span className="inline-block px-2 py-1 text-xs font-semibold bg-yellow-500 text-black rounded mb-2">Featured</span>
)}
<h2 className="text-2xl font-bold text-white mb-2 line-clamp-2">{post.title}</h2>
<p className="text-white/80 line-clamp-2 mb-3">{post.excerpt}</p>
<div className="flex items-center gap-4 text-sm text-white/60">
<span className="flex items-center gap-1"><Calendar className="h-3 w-3" /> {new Date(post.publishedAt ?? post.createdAt).toLocaleDateString()}</span>
<span className="flex items-center gap-1"><Clock className="h-3 w-3" /> {post.readTime ?? 0} min read</span>
<span className="flex items-center gap-1"><Eye className="h-3 w-3" /> {post.views ?? 0}</span>
</div>
</div>
</Link>
);
}
return (
<motion.article
whileHover={{ y: -6, scale: 1.01 }}
className={`group premium-glass bg-white/60 dark:bg-slate-900/40 border border-white/40 dark:border-white/10 backdrop-blur-xl rounded-[2rem] shadow-sm hover:shadow-2xl hover:border-white/70 dark:hover:border-white/20 transition-all overflow-hidden relative ${className}`}
>
{/* Decorative gradient orb on hover */}
<div className="absolute -inset-16 bg-gradient-to-r from-blue-500/10 to-purple-500/10 opacity-0 group-hover:opacity-100 blur-2xl transition duration-700 pointer-events-none" />
<Link to={`/blog/${post.slug}`} className="block relative z-10">
<div className="relative h-52 overflow-hidden m-2 rounded-[1.5rem]">
{!imageLoaded && <div className="absolute inset-0 bg-gray-200 dark:bg-gray-700 animate-pulse" />}
<img
src={post.coverImage}
alt={post.title}
className={`w-full h-full object-cover group-hover:scale-105 transition duration-500 ${imageLoaded ? "opacity-100" : "opacity-0"}`}
onLoad={() => setImageLoaded(true)}
/>
{post.trending && (
<div className="absolute top-3 left-3">
<span className="px-2 py-1 text-xs font-semibold bg-gradient-to-r from-orange-500 to-red-500 text-white rounded-full">Trending</span>
</div>
)}
<div className="absolute bottom-3 right-3 flex gap-2">
<button className="p-1.5 rounded-full bg-white/90 dark:bg-gray-800/90 hover:bg-white transition">
<Bookmark className="h-3.5 w-3.5 text-gray-600" />
</button>
</div>
</div>
</Link>
<div className="p-5 relative z-10">
<div className="flex flex-wrap items-center gap-3 text-xs text-slate-500 dark:text-slate-400 mb-3">
<span className="flex items-center gap-1 font-medium bg-slate-100 dark:bg-slate-800/50 px-2 py-0.5 rounded-full">
<Calendar className="h-3 w-3" />
{new Date(post.publishedAt ?? post.createdAt).toLocaleDateString()}
</span>
<span className="flex items-center gap-1 font-medium bg-slate-100 dark:bg-slate-800/50 px-2 py-0.5 rounded-full">
<Clock className="h-3 w-3" />
{post.readTime ?? 0} min read
</span>
<span className="flex items-center gap-1 font-medium bg-slate-100 dark:bg-slate-800/50 px-2 py-0.5 rounded-full">
<Eye className="h-3 w-3" />
{(post.views ?? 0).toLocaleString()}
</span>
</div>
<Link to={`/blog/${post.slug}`}>
<h3 className="text-xl font-bold text-slate-900 dark:text-white mb-2 line-clamp-2 group-hover:text-transparent group-hover:bg-clip-text group-hover:bg-gradient-to-r group-hover:from-teal-500 group-hover:to-blue-500 transition-all">
{post.title}
</h3>
</Link>
<p className="text-slate-600 dark:text-slate-400 text-sm line-clamp-2 mb-4">
{post.excerpt}
</p>
<div className="flex items-center justify-between pt-4 border-t border-slate-200/50 dark:border-slate-800/50">
<div className="flex items-center gap-2">
<div className="w-8 h-8 rounded-full bg-gradient-to-br from-teal-500 to-blue-500 flex items-center justify-center text-white text-xs font-bold shadow-md">
{post.author.fullName?.[0]?.toUpperCase() || post.author.username?.[0]?.toUpperCase()}
</div>
<div>
<div className="text-sm font-bold text-slate-900 dark:text-white">{post.author.fullName || post.author.username}</div>
<div className="text-[10px] text-slate-500 font-medium uppercase tracking-wider">@{post.author.username}</div>
</div>
</div>
<div className="flex items-center gap-3">
<button className="flex items-center gap-1.5 text-slate-500 dark:text-slate-400 hover:text-rose-500 dark:hover:text-rose-400 transition">
<Heart className="h-4 w-4" />
<span className="text-xs font-semibold">{post.likes ?? 0}</span>
</button>
<button className="flex items-center gap-1.5 text-slate-500 dark:text-slate-400 hover:text-teal-500 dark:hover:text-teal-400 transition">
<MessageCircle className="h-4 w-4" />
<span className="text-xs font-semibold">{post.comments ?? 0}</span>
</button>
</div>
</div>
</div>
</motion.article>
);
}

Xet Storage Details

Size:
7.44 kB
·
Xet hash:
ebf46a611ff71df67cf69d2fe20d47d5e0b84814c3c37306cafeaa8c3e3176d7

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.