Components
Cards & Display

Like Button

A like button with a heart pop and a particle burst, built with Motion and Tailwind CSS. No extra assets.

Plays on its own. Click to take over.

Install

Copies the source into components/ui/like-button.tsx and installs what it needs.

$ pnpm dlx shadcn@latest add https://makeui.xyz/r/like-button.json

Usage

app/page.tsx
import { LikeButton } from "@/components/ui/like-button"

export default function Example() {
  return <LikeButton defaultCount={128} />
}

Source

Prefer to copy by hand? It's one file. Requires motion and the shadcn cn helper.

components/ui/like-button.tsx
"use client"

import { useState } from "react"
import { motion } from "motion/react"
import { Heart } from "lucide-react"
import { cn } from "@/lib/utils"

const rays = Array.from({ length: 6 }, (_, i) => (i / 6) * Math.PI * 2)

type Props = {
  defaultCount?: number
  /** Controlled state. Leave out to let it manage itself. */
  liked?: boolean
  onChange?: (liked: boolean) => void
  className?: string
}

/** Like button: the heart pops and a ring of dots bursts out. */
export function LikeButton({ defaultCount = 128, liked: controlled, onChange, className }: Props) {
  const [internal, setInternal] = useState(false)
  const liked = controlled ?? internal
  const count = defaultCount + (liked ? 1 : 0)

  return (
    <motion.button
      aria-pressed={liked}
      aria-label="Like"
      onClick={() => {
        setInternal(!liked)
        onChange?.(!liked)
      }}
      whileTap={{ scale: 0.92 }}
      className={cn(
        "inline-flex items-center gap-2.5 rounded-full bg-neutral-200/70 py-2 pl-3.5 pr-4 text-sm font-medium text-neutral-700 outline-none focus-visible:ring-2 focus-visible:ring-neutral-400/60 dark:bg-neutral-800 dark:text-neutral-200",
        className
      )}
    >
      <span className="relative grid size-5 place-items-center">
        {liked &&
          rays.map((a) => (
            <motion.span
              key={a}
              className="absolute size-1 rounded-full bg-rose-500"
              initial={{ x: 0, y: 0, opacity: 1, scale: 1 }}
              animate={{ x: Math.cos(a) * 17, y: Math.sin(a) * 17, opacity: 0, scale: 0.3 }}
              transition={{ duration: 0.5, ease: "easeOut" }}
            />
          ))}
        <motion.span
          key={String(liked)}
          initial={{ scale: liked ? 0.4 : 1 }}
          animate={{ scale: 1 }}
          transition={{ type: "spring", stiffness: 600, damping: 14 }}
        >
          <Heart className={cn("size-5 transition-colors", liked ? "fill-rose-500 text-rose-500" : "text-neutral-500")} />
        </motion.span>
      </span>
      <span className="tabular-nums">{count}</span>
    </motion.button>
  )
}