# Cart fly

The item the agent adds is thrown into the cart, which dips to catch it.

Also called: add to cart animation, fly to cart.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Into the cart, caught. The item the agent adds is thrown into the cart along an arc, shrinking as it goes; the cart dips to catch it and the count and total roll up. Preview: https://chatcn.dev/preview/cart-fly-demo

`flyToCart` throws a copy of the item's picture along an arc into the cart, shrinking and rounding as it goes, and resolves the moment it lands. Bump the count then: the cart dips under the weight and springs back, the badge pops, and the count and total roll to their new values.

## Installation

```bash
npx shadcn@latest add @chatcn-pro/cart-fly
```

## Usage

```tsx
import { CartButton, flyToCart } from "@/components/ui/chatcn/pro/cart-fly"

await flyToCart(thumbRef.current, cartRef.current)
setCount((c) => c + 1)

<CartButton ref={cartRef} count={count} total={total} />
```

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `count` | `number` | Going up plays the catch |
| `total` | `number` | Rolls with the count |
| `currency` | `string` | Default "USD" |
| `flyToCart(source, cart, duration?)` | `Promise<void>` | Resolves on landing |

## Accessibility

- The cart is a button named with the count; the flying copy is hidden.

## Motion

- A 640 ms arc sampled in 18 frames; the catch is a 480 ms squash. Reduced motion: no flight.

Source: https://chatcn.dev/docs/components/cart-fly