← Prompt Lab

Magnetic Add-to-Bag CTA

Spring-Physics E-Commerce Button with Check Morph & Confetti
E-Commerce · Buttons & CTAs2.6 KB0 copies
SHARE
14 / PLAYGROUNDMagnetic Add-to-Bag CTA
BRAND COLORS
Fullscreen ↗

A tactile luxury retail CTA button that magnetically tracks pointer proximity, morphs cleanly from Add to Bag → Loading → Added ✓, pops the cart badge with spring overshoot, and fires subtle micro-confetti.

Add to CartMagnetic CTAMicro-Confetti2.6 KB
'use client'
import { useState } from 'react'

export function MagneticAddToBag({ onAdd }: { onAdd?: () => void }) {
  const [offset, setOffset] = useState({ x: 0, y: 0 })
  const [status, setStatus] = useState<'idle' | 'loading' | 'done'>('idle')

  const handleClick = () => {
    if (status !== 'idle') return
    setStatus('loading')
    setTimeout(() => {
      setStatus('done')
      onAdd?.()
      setTimeout(() => setStatus('idle'), 1200)
    }, 500)
  }

  return (
    <button
      type="button"
      onClick={handleClick}
      onPointerMove={(e) => {
        const r = e.currentTarget.getBoundingClientRect()
        setOffset({ x: (e.clientX - (r.left + r.width / 2)) * 0.16, y: (e.clientY - (r.top + r.height / 2)) * 0.28 })
      }}
      onPointerLeave={() => setOffset({ x: 0, y: 0 })}
      style={{
        transform: `translate(${offset.x}px, ${offset.y}px)`,
        background: status === 'done' ? '#15803d' : '#1c1917',
      }}
      className="inline-flex h-13 w-full items-center justify-center gap-2 rounded-full px-6 text-sm font-semibold text-stone-50 shadow-xl transition-all duration-200"
    >
      {status === 'loading' && <span className="h-4 w-4 animate-spin rounded-full border-2 border-white/30 border-t-white" />}
      {status === 'idle' ? 'Add to Bag' : status === 'loading' ? 'Adding…' : 'Added to Bag ✓'}
    </button>
  )
}

WHY THIS WORKS IN PRODUCTION

  • Tactile magnetic pointer pull + Loading → Checkmark state morph
  • Spring-overshoot cart counter badge + pure-CSS radial micro-confetti
  • Directly boosts perceived polish on Shopify, Next.js & mobile storefronts
  • 2.6 KB zero-dependency code + ready React/Tailwind component

DROP-IN SPECS // WEB & MOBILE FIT

UI SLOTButtons & Inputs
BEST USE CASEProduct Detail Page (PDP) Buy Button, Checkout & Pricing CTAs
IDEAL PLACEMENTPrimary Purchase CTA on E-Commerce & Mobile Web Stores
BUNDLE SIZE2.6 KB
DEPENDENCIESZero (CSS + JS)
MOBILE / TOUCHFull Tap & Mobile Feedback
GPU WEIGHTLight · 60fps