# Low credit banner

A warning before credits run out, in days at the real pace, with the way out right beside it, or one quiet line above the composer.

> 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: Low credit banner. A warning in days at the real pace, with top up and auto top up beside it. Preview: https://chatcn.dev/preview/low-credit-banner-demo

## Installation

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

## Usage

```tsx
import { LowCreditBanner } from "@/components/ui/chatcn/pro/low-credit-banner"

<LowCreditBanner
  remaining={balance}
  total={plan.credits}
  daysLeft={daysLeftAtPace(balance, creditsPerDay)}
  onTopUp={openTopUp}
  onAutoTopUp={openAutoTopUp}
  onDismiss={snooze}
/>

<LowCreditBanner variant="inline" remaining={balance} total={plan.credits} daysLeft={days} onTopUp={openTopUp} />
```

Days at the pace you actually use credits mean more than a raw count, so that is the headline; the count sits under it and a thin bar shows what is left of a full balance. Amber while there is time, red once replies stop, and the red state cannot be dismissed. Top up is always there; turning on automatic top ups is offered beside it when you pass `onAutoTopUp`. The `inline` variant is a single line for above a composer: gray with no icon while there is time, amber with an icon below `warnBelow` days, red once replies stop, so it can stay on screen all the time without nagging.

## Examples

### States

Example: States. About a week left, less than a day left, and out of credits with replies paused. Preview: https://chatcn.dev/preview/low-credit-banner-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `remaining`, `total` | `number` | Balance and a full balance, for the bar |
| `daysLeft` | `number` | At the recent pace. See `daysLeftAtPace` |
| `unit` | `string` | Default credits |
| `onTopUp`, `onAutoTopUp`, `onDismiss` | `() => void` | Each shows its button |
| `variant` | `"banner" | "inline"` | Default banner |
| `warnBelow` | `number` | Inline only. Days below which it turns amber. Default 3 |
| `locale`, `labels` |  | Formatting and every string |

## Accessibility

- A status while there is time, an alert once replies are paused.
- The inline line truncates instead of wrapping and drops its bar on a phone; the sentence always stays.
- Every color comes with an icon and the sentence that says what it means.

## Motion

The inline bar eases to the new balance in 300 ms; nothing moves with reduced motion.

Source: https://chatcn.dev/docs/components/low-credit-banner