OpenSourceUIOpenSourceUIOpensource UI
GitHubTwitter/X
  1. Home
  2. Components
  3. Buttons
  4. Add To Cart Button
Back to ButtonsComponents / Buttons

Add To Cart Button

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

Raised 3D add-to-cart key that sinks in while adding, with gentle label crossfades, then pops back up in a solid emerald added state before resetting.

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/add-to-cart-button.tsx in your project.

  4. 4

    Import and render:

    Example

    import { AddToCartButton } from "@/components/buttons/add-to-cart-button";

    <AddToCartButton label="Add to cart" onAddToCart={async () => addItem(id)} />

lib/cn.ts

1
2
3
import { cn } from '@/lib/cn';
 
// Full source is available in the repository checkout.

components/buttons/add-to-cart-button.tsx

1
2
// Full source: components/components/buttons/add-to-cart-button.tsx
// The Cloudflare worker does not expose the source tree at request time.
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/buttons/add-to-cart-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.