Add to Cart

Smart add-to-cart button with built-in validation, loading states, and error handling that automatically works with Product context.

Interactive Demo

AddToCart is an optional React convenience over the mockup URL. Buying is also just a URL (img → buy) — this component is the React ergonomics on top.

Try the add-to-cart button in different configurations using the variant switcher:

Loading playground...

Component Props

onClick(cartDetail: CartDetail) => void | Promise<unknown>
Performs the add. Return a Promise and the button waits for it: "Added!" only after it resolves; a rejection (or throw) shows the error state with the error's message
onError(error: Error) => void
Callback function for handling validation or cart errors
textstring
Button text in default state (default: "Add to Cart")
loadingTextstring
Button text during cart operation (default: "Adding...")
successTextstring
Button text after successful addition (default: "Added!")
errorTextstring
Button text after a failed add (default: "Couldn't add — try again"). The error message is announced in a role="alert" and the button stays enabled to retry; the button carries data-add-to-cart="idle | adding | added | error"
quantitynumber
Number of items to add (default: 1)
simulateDelaynumber
Simulated delay in milliseconds, used only when there is no onClick (demos) (default: 1000)
classNamestring
CSS classes to apply to the button element

Installation

npm install @snowcone-app/ui
Styling — your Tailwind v4 build compiles it. In your global stylesheet, add @import '@snowcone-app/ui/styles/globals.css' (brings in Tailwind, the theme tokens, and an @source for the package) plus an @source for your own code. In Next.js, also add transpilePackages: ['@snowcone-app/ui']. Add className="dark" on an ancestor for dark mode.
© 2026 Art Shop AI LLC d/b/a Snowcone. All rights reserved.