-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy patharticle.tsx
77 lines (71 loc) · 2.04 KB
/
article.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import {ReactNode} from 'react';
import Date from './date';
import Tag from './tag';
type ArticleProps = {
children?: ReactNode;
className?: string;
date?: string | Date | null;
image?: string | null;
loading?: boolean;
slug?: string;
tags?: string[];
title?: string;
};
export default function Article({
title = '',
image,
tags = [],
date = null,
children,
loading,
className,
}: ArticleProps) {
if (loading) {
return <LoadingArticle />;
}
return (
<article className={`bg-white rounded-lg shadow-lg mb-8 ${className}`}>
{image && (
<img
className="object-cover relative w-full h-64 rounded-lg rounded-b-none"
src={image}
alt={title}
/>
)}
<div className="p-6">
<h3 className="text-3xl text-primary font-semibold mb-2">{title}</h3>
<div>
<div className="flex flex-wrap gap-1 py-1">
{Array.isArray(tags) && tags.map(tag => <Tag key={tag} text={tag} />)}
</div>
<div className="prose max-w-none text-gray-700 py-2">{children}</div>
<dl>
<dd className="text-xs leading-6 text-gray-400">
<Date date={date} />
</dd>
</dl>
</div>
</div>
</article>
);
}
function LoadingArticle() {
return (
<article className="bg-white rounded-lg shadow-lg mb-8">
<div className="p-6">
<div className="h-6 bg-gray-200 mb-2 animate-pulse rounded" />
<div className="flex flex-wrap gap-1 py-1">
<div className="h-4 bg-gray-200 w-20 animate-pulse rounded" />
</div>
<div className="prose max-w-none text-gray-700 py-2">
<div className="h-4 bg-gray-200 mb-2" />
<div className="h-4 bg-gray-200 mb-2 animate-pulse rounded" />
<div className="h-4 bg-gray-200" />
</div>
<div className="text-xs leading-6 text-gray-400 animate-pulse rounded">
<div className="h-4 bg-gray-200 w-16 animate-pulse rounded" />
</div>
</div>
</article>
);
}