opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Twitter
  4. Twitter Post
Back to Twitter

Components / Twitter

Twitter Post

Free Twitter React component — TwitterPostCard. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Tweet card with avatar, handle, timestamp, hashtags, and full engagement row. For social embeds, mockups, or feed previews.

Preview

User avatar
Bidyut Kundu@bidyut10 · 2h

Building the future of UI with minimalist design and performance-first components. Obsessed with the little details. #WebDev #Design

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/twitter/twitter-post-card.tsx in your project.

  4. 4

    Import and render:

    Example

    import { TwitterPostCard } from "@/components/twitter/twitter-post-card";

    <TwitterPostCard />

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/twitter/twitter-post-card.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"use client";
 
import {
forwardRef,
type ComponentPropsWithoutRef,
type ReactNode,
} from "react";
import Image from "next/image";
 
import { cn } from "@/lib/cn";
import {
Bookmark,
MessageCircle,
Ellipsis,
Heart,
Repeat,
Share,
} from "lucide-react";
 
export type TwitterPostCardProps = Readonly<
{
username?: string;
handle?: string;
timestamp?: string;
content?: string;
hashtags?: string;
comments?: number;
reposts?: number;
likes?: number;
avatar?: string;
avatarAlt?: string;
menuIcon?: ReactNode;
commentIcon?: ReactNode;
repostIcon?: ReactNode;
likeIcon?: ReactNode;
bookmarkIcon?: ReactNode;
shareIcon?: ReactNode;
onComment?: () => void;
onRepost?: () => void;
onLike?: () => void;
onBookmark?: () => void;
onShare?: () => void;
} & ComponentPropsWithoutRef<"div">
>;
 
// Production-ready Twitter Post component — styled with Tailwind CSS.
export const TwitterPostCard = forwardRef<HTMLDivElement, TwitterPostCardProps>(
(
{
className,
username = "Bidyut Kundu",
handle = "@bidyut10",
timestamp = "2h",
content = "Building the future of UI with minimalist design and performance-first components. Obsessed with the little details.",
hashtags = "#WebDev #Design",
comments = 12,
reposts = 38,
likes = 450,
avatar = "/profile-picture.png",
avatarAlt = "User avatar",
menuIcon,
commentIcon,
repostIcon,
likeIcon,
bookmarkIcon,
shareIcon,
onComment,
onRepost,
onLike,
onBookmark,
onShare,
...props
},
ref,
) => {
return (
<div
ref={ref}
data-slot="twitter-post-card"
className={cn(
"max-w-96 rounded-2xl border border-neutral-100 bg-white p-5 font-sans shadow-lg",
className,
)}
{...props}
>
<div data-slot="twitter-post-card-header" className="flex gap-3">
<div className="flex h-11 w-11 shrink-0 items-center justify-center rounded-full bg-neutral-800">
<Image
src={avatar}
alt={avatarAlt}
width={32}
height={32}
className="w-8"
sizes="32px"
/>
</div>
 
<div className="min-w-0 flex-1">
<div className="flex items-center justify-between">
<div className="flex flex-wrap items-center gap-1">
<span
title={username}
className="text-sm font-bold text-neutral-900"
>
{username}
</span>
 
<span title={handle} className="text-xs text-neutral-400">
{handle} · {timestamp}
</span>
</div>
 
<div className="shrink-0 text-neutral-400">
{menuIcon ?? <Ellipsis className="h-4 w-4" />}
</div>
</div>
 
<p
data-slot="twitter-post-card-content"
className="mt-2 text-sm leading-relaxed text-neutral-800"
>
{content} <span className="text-sky-500">{hashtags}</span>
</p>
 
<div
data-slot="twitter-post-card-actions"
className="mt-4 flex max-w-xs justify-between text-neutral-400"
>
<button
type="button"
aria-label={`Comment on post from ${username}`}
onClick={onComment}
className="flex cursor-pointer items-center gap-1 transition-colors hover:text-sky-500"
>
{commentIcon ?? <MessageCircle size={14} />}
<span className="text-xs">{comments.toLocaleString()}</span>
</button>
 
<button
type="button"
aria-label={`Repost post from ${username}`}
onClick={onRepost}
className="flex cursor-pointer items-center gap-1 transition-colors hover:text-emerald-500"
>
{repostIcon ?? <Repeat size={16} />}
<span className="text-xs">{reposts.toLocaleString()}</span>
</button>
 
<button
type="button"
aria-label={`Like post from ${username}`}
onClick={onLike}
className="flex cursor-pointer items-center gap-1 transition-colors hover:text-rose-500"
>
{likeIcon ?? <Heart size={15} />}
<span className="text-xs">{likes.toLocaleString()}</span>
</button>
 
<button
type="button"
aria-label={`Save post from ${username}`}
onClick={onBookmark}
className="flex cursor-pointer items-center gap-1 transition-colors hover:text-sky-500"
>
{bookmarkIcon ?? <Bookmark size={15} />}
</button>
 
<button
type="button"
aria-label={`Share post from ${username}`}
onClick={onShare}
className="flex cursor-pointer items-center gap-1 transition-colors hover:text-sky-500"
>
{shareIcon ?? <Share size={14} />}
</button>
</div>
</div>
</div>
</div>
);
},
);
 
TwitterPostCard.displayName = "TwitterPostCard";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/twitter/twitter-post-card.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.