opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Buttons
  4. Follow Button
Back to Buttons

Components / Buttons

Follow Button

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

Social follow toggle — dark Follow pill becomes a quiet Following state with a user-check icon. Tap again to unfollow.

Preview

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/buttons/follow-button.tsx in your project.

  4. 4

    Import and render:

    Example

    import { FollowButton } from "@/components/buttons/follow-button";

    <FollowButton label="Follow" followingLabel="Following" />

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/buttons/follow-button.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
"use client";
 
import { forwardRef, useState, type ComponentPropsWithoutRef } from "react";
 
import { cn } from "@/lib/cn";
import { UserCheck, UserPlus } from "lucide-react";
 
export type FollowButtonProps = Readonly<
{
label?: string;
followingLabel?: string;
defaultFollowing?: boolean;
} & ComponentPropsWithoutRef<"button">
>;
 
// Follow toggle — outline invite becomes a quiet filled following state.
export const FollowButton = forwardRef<HTMLButtonElement, FollowButtonProps>(
(
{
className,
label = "Follow",
followingLabel = "Following",
defaultFollowing = false,
onClick,
...props
},
ref,
) => {
const [following, setFollowing] = useState(defaultFollowing);
 
return (
<button
ref={ref}
type="button"
aria-pressed={following}
data-slot="follow-button"
onClick={(event) => {
setFollowing((prev) => !prev);
onClick?.(event);
}}
className={cn(
"inline-flex h-10 cursor-pointer items-center gap-2 rounded-full px-4 font-sans text-sm font-semibold transition-all duration-200 active:scale-[0.98] select-none",
following
? "bg-neutral-100 text-neutral-600 ring-1 ring-neutral-200"
: "bg-neutral-900 text-white",
className,
)}
{...props}
>
{following ? (
<>
<UserCheck size={15} strokeWidth={2} />
{followingLabel}
</>
) : (
<>
<UserPlus size={15} strokeWidth={2} />
{label}
</>
)}
</button>
);
},
);
 
FollowButton.displayName = "FollowButton";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/buttons/follow-button.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.