1
- import Image from 'next/future/ image' ;
1
+ import Image from 'next/image' ;
2
2
import { format } from 'date-fns' ;
3
+ import comma from 'comma-number' ;
3
4
4
5
/**
5
6
* Supports plain text, images, quote tweets.
6
7
*
7
8
* Needs support for images, GIFs, and replies maybe?
8
- * Styles use !important to override Tailwind .prose inside MDX.
9
9
*/
10
10
export default function Tweet ( {
11
11
text,
@@ -23,14 +23,12 @@ export default function Tweet({
23
23
const tweetUrl = `https://twitter.com/${ author . username } /status/${ id } ` ;
24
24
const createdAt = new Date ( created_at ) ;
25
25
26
- const formattedText = text
27
- . replace ( / h t t p s : \/ \/ [ \n \S ] + / g, '' )
28
- . replace ( '&' , '&' ) ;
26
+ const formattedText = text . replace ( / h t t p s : \/ \/ [ \n \S ] + / g, '' ) ;
29
27
const quoteTweet =
30
28
referenced_tweets && referenced_tweets . find ( ( t ) => t . type === 'quoted' ) ;
31
29
32
30
return (
33
- < div className = "tweet rounded-lg border border-gray-200 dark:border-gray-800 px-6 py-4 my-4 w-full bg-white dark:bg-gray-900 " >
31
+ < div className = "font-sans rounded border border-gray-300 dark:border-gray-800 px-6 py-4 my-4 w-full" >
34
32
< div className = "flex items-center" >
35
33
< a
36
34
className = "flex h-12 w-12"
@@ -48,12 +46,12 @@ export default function Tweet({
48
46
</ a >
49
47
< a
50
48
href = { authorUrl }
49
+ className = "author flex flex-col ml-4"
51
50
target = "_blank"
52
51
rel = "noopener noreferrer"
53
- className = "author flex flex-col ml-4 !no-underline"
54
52
>
55
53
< span
56
- className = "flex items-center font-bold ! text-gray-900 dark:! text-gray-100 leading-5"
54
+ className = "flex items-center font-bold text-gray-900 dark:text-gray-100 leading-5"
57
55
title = { author . name }
58
56
>
59
57
{ author . name }
@@ -69,7 +67,7 @@ export default function Tweet({
69
67
</ svg >
70
68
) : null }
71
69
</ span >
72
- < span className = "! text-gray-500" title = { `@${ author . username } ` } >
70
+ < span className = "text-gray-500" title = { `@${ author . username } ` } >
73
71
@{ author . username }
74
72
</ span >
75
73
</ a >
@@ -92,17 +90,11 @@ export default function Tweet({
92
90
</ svg >
93
91
</ a >
94
92
</ div >
95
- < div className = "mt-4 mb-1 leading-normal whitespace-pre-wrap ! text-gray-700 dark:! text-gray-200 " >
93
+ < div className = "mt-4 mb-1 leading-normal whitespace-pre-wrap text-lg text-gray-700 dark:text-gray-300 " >
96
94
{ formattedText }
97
95
</ div >
98
96
{ media && media . length ? (
99
- < div
100
- className = {
101
- media . length === 1
102
- ? 'inline-grid grid-cols-1 gap-x-2 gap-y-2 my-2'
103
- : 'inline-grid grid-cols-2 gap-x-2 gap-y-2 my-2'
104
- }
105
- >
97
+ < div className = "inline-grid grid-cols-2 gap-x-2 gap-y-2 my-2" >
106
98
{ media . map ( ( m ) => (
107
99
< Image
108
100
key = { m . media_key }
@@ -117,7 +109,7 @@ export default function Tweet({
117
109
) : null }
118
110
{ quoteTweet ? < Tweet { ...quoteTweet } /> : null }
119
111
< a
120
- className = "! text-gray-500 text-sm hover:! underline"
112
+ className = "text-gray-500 text-sm hover:underline"
121
113
href = { tweetUrl }
122
114
target = "_blank"
123
115
rel = "noopener noreferrer"
@@ -129,62 +121,50 @@ export default function Tweet({
129
121
{ format ( createdAt , 'h:mm a - MMM d, y' ) }
130
122
</ time >
131
123
</ a >
132
- < div className = "flex text-sm !text- gray-700 dark:! text-gray-300 mt-2" >
124
+ < div className = "flex text-gray-700 dark:text-gray-300 mt-2" >
133
125
< a
134
- className = "flex items-center mr-4 ! text-gray-500 hover:! text-blue-600 transition hover:! underline"
126
+ className = "flex items-center mr-4 text-gray-500 hover:text-blue-600 transition hover:underline"
135
127
href = { replyUrl }
136
128
target = "_blank"
137
129
rel = "noopener noreferrer"
138
130
>
139
- < svg className = "mr-2" width = "18 " height = "18 " viewBox = "0 0 24 24" >
131
+ < svg className = "mr-2" width = "24 " height = "24 " viewBox = "0 0 24 24" >
140
132
< path
141
133
className = "fill-current"
142
134
d = "M14.046 2.242l-4.148-.01h-.002c-4.374 0-7.8 3.427-7.8 7.802 0 4.098 3.186 7.206 7.465 7.37v3.828c0 .108.045.286.12.403.143.225.385.347.633.347.138 0 .277-.038.402-.118.264-.168 6.473-4.14 8.088-5.506 1.902-1.61 3.04-3.97 3.043-6.312v-.017c-.006-4.368-3.43-7.788-7.8-7.79zm3.787 12.972c-1.134.96-4.862 3.405-6.772 4.643V16.67c0-.414-.334-.75-.75-.75h-.395c-3.66 0-6.318-2.476-6.318-5.886 0-3.534 2.768-6.302 6.3-6.302l4.147.01h.002c3.532 0 6.3 2.766 6.302 6.296-.003 1.91-.942 3.844-2.514 5.176z"
143
135
/>
144
136
</ svg >
145
- < span >
146
- { new Number ( public_metrics . reply_count ) . toLocaleString ( 'en' , {
147
- notation : 'compact'
148
- } ) }
149
- </ span >
137
+ < span > { comma ( public_metrics . reply_count ) } </ span >
150
138
</ a >
151
139
< a
152
- className = "flex items-center mr-4 ! text-gray-500 hover:! text-green-600 transition hover:! underline"
140
+ className = "flex items-center mr-4 text-gray-500 hover:text-green-600 transition hover:underline"
153
141
href = { retweetUrl }
154
142
target = "_blank"
155
143
rel = "noopener noreferrer"
156
144
>
157
- < svg className = "mr-2" width = "18 " height = "18 " viewBox = "0 0 24 24" >
145
+ < svg className = "mr-2" width = "24 " height = "24 " viewBox = "0 0 24 24" >
158
146
< path
159
147
className = "fill-current"
160
148
d = "M23.77 15.67c-.292-.293-.767-.293-1.06 0l-2.22 2.22V7.65c0-2.068-1.683-3.75-3.75-3.75h-5.85c-.414 0-.75.336-.75.75s.336.75.75.75h5.85c1.24 0 2.25 1.01 2.25 2.25v10.24l-2.22-2.22c-.293-.293-.768-.293-1.06 0s-.294.768 0 1.06l3.5 3.5c.145.147.337.22.53.22s.383-.072.53-.22l3.5-3.5c.294-.292.294-.767 0-1.06zm-10.66 3.28H7.26c-1.24 0-2.25-1.01-2.25-2.25V6.46l2.22 2.22c.148.147.34.22.532.22s.384-.073.53-.22c.293-.293.293-.768 0-1.06l-3.5-3.5c-.293-.294-.768-.294-1.06 0l-3.5 3.5c-.294.292-.294.767 0 1.06s.767.293 1.06 0l2.22-2.22V16.7c0 2.068 1.683 3.75 3.75 3.75h5.85c.414 0 .75-.336.75-.75s-.337-.75-.75-.75z"
161
149
/>
162
150
</ svg >
163
- < span >
164
- { new Number ( public_metrics . retweet_count ) . toLocaleString ( 'en' , {
165
- notation : 'compact'
166
- } ) }
167
- </ span >
151
+ < span > { comma ( public_metrics . retweet_count ) } </ span >
168
152
</ a >
169
153
< a
170
- className = "flex items-center ! text-gray-500 hover:! text-red-600 transition hover:! underline"
154
+ className = "flex items-center text-gray-500 hover:text-red-600 transition hover:underline"
171
155
href = { likeUrl }
172
156
target = "_blank"
173
157
rel = "noopener noreferrer"
174
158
>
175
- < svg className = "mr-2" width = "18 " height = "18 " viewBox = "0 0 24 24" >
159
+ < svg className = "mr-2" width = "24 " height = "24 " viewBox = "0 0 24 24" >
176
160
< path
177
161
className = "fill-current"
178
162
d = "M12 21.638h-.014C9.403 21.59 1.95 14.856 1.95 8.478c0-3.064 2.525-5.754 5.403-5.754 2.29 0 3.83 1.58 4.646 2.73.813-1.148 2.353-2.73 4.644-2.73 2.88 0 5.404 2.69 5.404 5.755 0 6.375-7.454 13.11-10.037 13.156H12zM7.354 4.225c-2.08 0-3.903 1.988-3.903 4.255 0 5.74 7.035 11.596 8.55 11.658 1.52-.062 8.55-5.917 8.55-11.658 0-2.267-1.822-4.255-3.902-4.255-2.528 0-3.94 2.936-3.952 2.965-.23.562-1.156.562-1.387 0-.015-.03-1.426-2.965-3.955-2.965z"
179
163
/>
180
164
</ svg >
181
- < span >
182
- { new Number ( public_metrics . like_count ) . toLocaleString ( 'en' , {
183
- notation : 'compact'
184
- } ) }
185
- </ span >
165
+ < span > { comma ( public_metrics . like_count ) } </ span >
186
166
</ a >
187
167
</ div >
188
168
</ div >
189
169
) ;
190
- }
170
+ }
0 commit comments