Updated
Follow Button
NewCustomize
Count1284
Unfollow colour
Medium
Installation
npx shadcn@latest add https://uibrik.com/r/follow-button.jsonInstall the packages
npm install @number-flow/react motion react-use-measureAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/follow-button/follow-button.tsx"use client"; import NumberFlow from "@number-flow/react"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { useState } from "react"; import useMeasure from "react-use-measure"; import { cn } from "@/lib/utils"; const EASE_OUT: [number, number, number, number] = [0.23, 1, 0.32, 1]; const SIZES = { sm: { height: 32, padX: 12, font: 13, icon: 14 }, md: { height: 40, padX: 15, font: 14, icon: 16 }, lg: { height: 48, padX: 18, font: 15, icon: 18 }, } as const; export type FollowButtonProps = { /** Controlled state. */ following?: boolean; /** State on mount when uncontrolled. */ defaultFollowing?: boolean; onFollowingChange?: (following: boolean) => void; label?: string; followingLabel?: string;
Adds the files to
components/uibrik/follow-button and installs @number-flow/react, motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/follow-button.Usage
import { FollowButton } from "@/components/uibrik/follow-button/follow-button";<FollowButton label="Follow" followingLabel="Following" unfollowLabel="Unfollow" count={1284} countLabel="followers" dangerColor="#dc2626" size="md" defaultFollowing={false} // following={false} // onFollowingChange={(following) => {}}/>Where to use Follow Button
Profiles and creator pages
The plus folds into a check and the count ticks up, so following feels done without a toast.
Pairs with Company Card and Hover Card
Topics and channels
Hovering a followed item warns with Unfollow in red, which stops accidental unsubscribes.
Suggested people lists
Each button eases to its new width in place, so a list of suggestions never shifts as you follow.
Pairs with Team Roster
Props
FollowButton- label
- Type string
- "Follow"
- Label before following.
- followingLabel
- Type string
- "Following"
- Label once followed.
- unfollowLabel
- Type string
- "Unfollow"
- Shown while hovering a followed button.
- count
- Type number
- 1284
- Followers besides you, shown beside the button.
- countLabel
- Type string
- "followers"
- Word after the count.
- dangerColor
- Type string
- "#dc2626"
- Colour of the unfollow warning.
- size
- Type "sm" | "md" | "lg"
- "md"
- Height, padding and text size.
- defaultFollowing
- Type boolean
- false
- State on mount when uncontrolled.
- following / onFollowingChange
- Type boolean / (following) => void
- –
- Controlled state.
- className
- Type string
- –
- Classes for the wrapper.