bsd/components/ActivityCard.tsx

82 lines
2.6 KiB
TypeScript
Raw Normal View History

2024-12-13 19:46:49 +08:00
'use client'
import Image from 'next/image'
import { useState } from 'react'
import { ChevronDown, ChevronUp } from 'lucide-react'
interface ActivityProps {
activity: {
title: string
coverImage: string
description: string
date: string
participants: string[]
organizer: string
}
}
const ActivityCard: React.FC<ActivityProps> = ({ activity }) => {
const [isExpanded, setIsExpanded] = useState(false)
return (
<div className="bg-white shadow-lg rounded-lg overflow-hidden">
<div className="relative h-48">
<Image
src={activity.coverImage}
alt={activity.title}
layout="fill"
objectFit="cover"
/>
</div>
<div className="p-6">
<h3 className="text-xl font-semibold mb-2">{activity.title}</h3>
<p className="text-gray-600 mb-2">{activity.description}</p>
<p className="text-sm text-gray-500 mb-2">{activity.date}</p>
<p className="text-sm text-gray-500 mb-2">{activity.organizer}</p>
<div className="mt-4">
<p className="text-sm font-semibold mb-1"></p>
{activity.participants.length <= 3 ? (
<ul className="list-disc list-inside">
{activity.participants.map((participant, index) => (
<li key={index} className="text-sm text-gray-600">{participant}</li>
))}
</ul>
) : (
<div>
<ul className="list-disc list-inside">
{activity.participants.slice(0, 3).map((participant, index) => (
<li key={index} className="text-sm text-gray-600">{participant}</li>
))}
</ul>
{isExpanded && (
<ul className="list-disc list-inside mt-2">
{activity.participants.slice(3).map((participant, index) => (
<li key={index + 3} className="text-sm text-gray-600">{participant}</li>
))}
</ul>
)}
<button
className="mt-2 text-sm text-blue-600 hover:text-blue-800 flex items-center"
onClick={() => setIsExpanded(!isExpanded)}
>
{isExpanded ? (
<>
<ChevronUp className="ml-1 w-4 h-4" />
</>
) : (
<>
({activity.participants.length - 3}) <ChevronDown className="ml-1 w-4 h-4" />
</>
)}
</button>
</div>
)}
</div>
</div>
</div>
)
}
export default ActivityCard