# Credit spend

Credits you can see spent: the cost breaks off the bar and flies to what it paid for.

Also called: credits animation.

> 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: Credits you can see spent. Each generation breaks its cost off the end of the credits bar; the piece flies to the take it paid for and lands as the price. Preview: https://chatcn.dev/preview/credit-spend-demo

The balance is a bar and a number. When something costs credits, the piece of the bar it costs breaks off the end, flies to the thing it paid for and turns into the price as it lands, while the bar closes up and the number counts down. Below a tenth of the allowance the bar turns amber.

## Installation

```bash
npx shadcn@latest add @chatcn-pro/credit-spend
```

## Usage

```tsx
import { CreditSpend, spendFrom } from "@/components/ui/chatcn/pro/credit-spend"

await spendFrom(meter, tile, 160, balance, allowance)
setBalance((b) => b - 160)

<CreditSpend ref={meterRef} balance={balance} allowance={2000} />
```

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `balance` / `allowance` | `number` |  |
| `label` | `string` | Default "Credits" |

## Accessibility

- A labelled `meter`; the flying piece is decorative.

## Motion

- The piece arcs 620 ms and widens into the price; the bar closes on a spring. Reduced motion: no flight.

Source: https://chatcn.dev/docs/components/credit-spend