news/app/components/list/List.tsx

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-11-18 17:36:30 +08:00
import React from 'react';
import { mockNewsData } from './NewsData'; // 导入新闻数据
interface NewsProps {
title?: string;
description?: string;
time?: string;
type?: string;
url?: string;
}
const NewsItem: React.FC<NewsProps> = ({ title = '', time = '', url = '' }) => {
return (
<div className="mb-4">
<div
onClick={() => url && window.open(url)}
className="flex items-center justify-between hover:text-blue-600 cursor-pointer transition duration-300 ease-in-out"
>
<h3 className="text-lg font-semibold text-gray-800">{title}</h3>
<p className="text-sm text-gray-500">{time}</p>
</div>
</div>
);
};
// 使用新闻数据渲染列表
const List: React.FC = () => {
return (
<div className=" ">
<div className="grid grid-cols-1 md:grid-cols-2 ">
<div className=" p-6 rounded-lg ">
<ul className="space-y-4">
{mockNewsData.map((news) => (
<NewsItem title={news.title} time={news.time} url={news.url} />
))}
</ul>
</div>
</div>
</div>
);
};
export default List;