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

Components / Facebook

Facebook Post

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

Facebook feed post with reactions, comments, share counts, optional image, and the full action bar. Familiar layout, your content.

Preview

User avatar

Bidyut Kundu

3 hours ago ·

Just launched a new side project — an open-source collection of minimal React UI cards.

Facebook post image
31248 comments · 9 shares

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/facebook/facebook-post-card.tsx in your project.

  4. 4

    Import and render:

    Example

    import { FacebookPostCard } from "@/components/facebook/facebook-post-card";

    <FacebookPostCard />

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/facebook/facebook-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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
"use client";
 
import {
forwardRef,
type ComponentPropsWithoutRef,
type ReactNode,
} from "react";
import Image from "next/image";
 
import { cn } from "@/lib/cn";
 
import {
Clock,
Ellipsis,
ThumbsUp,
Heart,
MessageCircle,
Share2,
} from "lucide-react";
 
export type FacebookPostCardProps = Readonly<
{
username?: string;
timestamp?: string;
content?: string;
reactions?: number;
comments?: number;
shares?: number;
avatar?: string;
postImage?: string;
avatarAlt?: string;
imageAlt?: string;
menuIcon?: ReactNode;
likeIcon?: ReactNode;
heartIcon?: ReactNode;
commentIcon?: ReactNode;
shareIcon?: ReactNode;
onLike?: () => void;
onComment?: () => void;
onShare?: () => void;
} & ComponentPropsWithoutRef<"div">
>;
 
// Production-ready Facebook Post component — styled with Tailwind CSS.
export const FacebookPostCard = forwardRef<
HTMLDivElement,
FacebookPostCardProps
>(
(
{
className,
username = "Bidyut Kundu",
timestamp = "3 hours ago",
content = "Just launched a new side project — an open-source collection of minimal React UI cards.",
reactions = 312,
comments = 48,
shares = 9,
avatar = "/profile-picture.png",
postImage = "/wallpaper-3.png",
avatarAlt = "User avatar",
imageAlt = "Facebook post image",
menuIcon,
likeIcon,
heartIcon,
commentIcon,
shareIcon,
onLike,
onComment,
onShare,
...props
},
ref,
) => {
return (
<div
ref={ref}
data-slot="facebook-post-card"
className={cn(
"w-xs rounded-xl border border-neutral-100 bg-white p-4 font-sans shadow-lg",
className,
)}
{...props}
>
{/* Post header */}
<div data-slot="facebook-post-card-header" className="mb-3 flex gap-3">
<div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-neutral-800">
<Image
src={avatar}
alt={avatarAlt}
width={28}
height={28}
className="w-7"
sizes="28px"
/>
</div>
 
<div>
<p
title={username}
className="text-sm font-semibold text-neutral-900"
>
{username}
</p>
 
<p className="text-xs text-neutral-400">
{timestamp} · <Clock className="inline" size={12} />
</p>
</div>
 
<div className="ml-auto text-neutral-400">
{menuIcon ?? <Ellipsis size={15} />}
</div>
</div>
 
{/* Post content */}
<p
data-slot="facebook-post-card-content"
className="mb-3 text-sm leading-relaxed text-neutral-800"
>
{content}
</p>
 
{/* Post image */}
<div className="relative mb-3 h-36 w-full overflow-hidden rounded-lg">
<Image
data-slot="facebook-post-card-image"
src={postImage}
alt={imageAlt}
fill
className="object-cover"
sizes="384px"
/>
</div>
 
{/* Engagement summary */}
<div
data-slot="facebook-post-card-stats"
className="mb-2 flex items-center justify-between px-1 text-xs text-neutral-500"
>
<span className="flex items-center gap-1">
<span className="inline-flex h-4 w-4 items-center justify-center rounded-full bg-blue-500 text-white">
{likeIcon ?? <ThumbsUp size={9} fill="white" />}
</span>
 
<span className="-ml-1 inline-flex h-4 w-4 items-center justify-center rounded-full bg-rose-500 text-white">
{heartIcon ?? <Heart size={9} fill="white" />}
</span>
 
{reactions.toLocaleString()}
</span>
 
<span>
{comments.toLocaleString()} comments · {shares.toLocaleString()}{" "}
shares
</span>
</div>
 
{/* Post actions */}
<div
data-slot="facebook-post-card-actions"
className="flex gap-1 border-t border-neutral-100 pt-2"
>
<button
type="button"
aria-label={`Like post from ${username}`}
onClick={onLike}
className="flex flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-md py-1.5 text-xs font-medium text-neutral-500 transition-colors hover:bg-neutral-50 hover:text-black"
>
{likeIcon ?? <ThumbsUp size={14} />}
Like
</button>
 
<button
type="button"
aria-label={`Comment on post from ${username}`}
onClick={onComment}
className="flex flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-md py-1.5 text-xs font-medium text-neutral-500 transition-colors hover:bg-neutral-50 hover:text-black"
>
{commentIcon ?? <MessageCircle size={14} />}
Comment
</button>
 
<button
type="button"
aria-label={`Share post from ${username}`}
onClick={onShare}
className="flex flex-1 cursor-pointer items-center justify-center gap-1.5 rounded-md py-1.5 text-xs font-medium text-neutral-500 transition-colors hover:bg-neutral-50 hover:text-black"
>
{shareIcon ?? <Share2 size={14} />}
Share
</button>
</div>
</div>
);
},
);
 
FacebookPostCard.displayName = "FacebookPostCard";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/facebook/facebook-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.