# Amount field

> A hero auto-scaling money and credits input with spring typography scaling, a gliding velocity-stretch caret, smooth Max roll-up and live overdraft feedback.

Send-money screens, AI credit top-ups and FX swaps put the figure at the centre of the screen, where an ordinary small form input feels cramped and big numbers wrap or clip. AmountField treats the figure itself as the interface: as digits arrive, a spring measures real text width and smoothly scales the display typography down from 54px so millions fit on one clean line without wrapping or jumping, then breathes back up as you delete. A native decimal input underneath preserves real mobile numeric keypads, paste and undo while a crisp hairline caret glides between characters on a spring with subtle velocity stretch and blinks only at rest. Tapping Max or any quick preset smoothly rolls the figure from its current value with an emerald 8×8 Bayer floor pulse; crossing your balance triggers a damped recoil, tints the figure crimson and states the exact shortfall beside a one-tap Set to max control.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/amount-field.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: none
- Hairline UI components it needs (the CLI installs them too): none
- Docs and live preview: https://hairlineui.com/ui/amount-field
- Registry item (source): https://hairlineui.com/r/amount-field.json

## Usage

```tsx
import { AmountField } from "@/components/amount-field";

<AmountField
  label="Transfer amount"
  value={amount}
  onChange={setAmount}
  balance={2450}
  presets={[50, 250, 1000]}
/>
```

## Payout composer wired to available balance and submit guard

AmountField emits clean number | null values so your checkout or transfer button can disable cleanly when empty or above balance.

```tsx
"use client";
import { useState } from "react";
import { AmountField } from "@/components/amount-field";

export function PayoutComposer({ availableUsd, onSend }: { availableUsd: number; onSend: (amount: number) => void }) {
  const [amount, setAmount] = useState<number | null>(250);
  const canSend = amount !== null && amount > 0 && amount <= availableUsd;

  return (
    <div className="space-y-3">
      <AmountField
        label="Payout amount"
        value={amount}
        onChange={setAmount}
        balance={availableUsd}
        presets={[100, 500, 1000]}
        conversion={{ rate: 0.9214, currency: "EUR", rateLabel: "1 USD = 0.9214 EUR" }}
      />
      <button
        type="button"
        disabled={!canSend}
        onClick={() => canSend && onSend(amount)}
        className="h-11 w-full rounded-xl bg-foreground text-sm font-medium text-background disabled:opacity-40"
      >
        Send payout
      </button>
    </div>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value / defaultValue / onChange` | `number \| null / (v) => void` | `null` | Controlled or uncontrolled numeric amount plus change callback emitting number or null. |
| `currency / symbol / symbolPosition / locale / decimals` | `string / string / "prefix" \| "suffix" / string / number` | `"USD" / auto / "prefix" / "en-US" / auto` | Intl currency formatting or custom suffix token unit (e.g. "USDC"), locale separators and max fraction digits. |
| `balance / presets` | `number / number[]` | – | Available balance enabling Max roll-up and live overdraft shortfall, plus optional quick-pick preset pills. |
| `conversion` | `AmountConversion` | – | Optional { rate, currency \| unit, decimals, rateLabel } for live FX or AI credits conversion readout. |
| `label / disabled / sound` | `string / boolean / boolean` | `"Amount" / false / false` | Accessible input label, disabled state and opt-in Web Audio ticks on typing, Max roll and overdraft. |

## States

- **empty**: Muted 0 ghost figure with prefix currency symbol; clicking anywhere focuses the native decimal input and drops the gliding hairline caret.
- **typing & scaling**: Digits format with locale grouping by place-value key; as width approaches the frame edge, scaleSpring smoothly steps typography down with zero wrapping.
- **preset / Max roll**: Tapping Max or a preset pill rolls the figure smoothly from the current value to the target while sweeping an emerald 8×8 Bayer pulse across the lower edge.
- **over balance**: Crossing balance fires one damped horizontal recoil and rose Bayer floor pulse, tints the figure crimson and swaps the footer to exact shortfall + Set to max.
- **reduced motion**: Scale, caret position and preset changes jump cleanly in place with no recoil travel or Bayer canvas loop.

## What it handles

Big hero amount inputs usually fight the user: text overflows on mobile, commas jump the caret, and hitting a balance limit blocks typing instead of showing clearly by how much you are over.

- **Fluid optical spring scaling**: Measures natural figure width via ResizeObserver and springs transform scale smoothly between 1 and 0.42 so large figures stay razor-sharp on a single line.
- **Gliding hairline caret with velocity stretch**: Tracks exact glyph boundaries on createSpring, subtly stretching horizontally with speed and blinking only when settled at rest.
- **Smooth Max and preset roll-up**: Clicking Max or any preset pill rolls the numeric figure smoothly from its current value on a spring while scaling seamlessly in lockstep.
- **Live overdraft frontier**: Never blocks typing: crossing balance fires a single damped spring recoil and rose Bayer floor pulse, tints the figure crimson and shows exact shortfall with one-tap Set to max.
- **Locale-safe parsing and paste**: Uses Intl.NumberFormat for currency symbols, grouping and fraction digits; strips pasted symbols and spaces while preserving in-progress decimals like 12.0.
- **Optional live conversion readout**: Pass conversion={{ rate, currency | unit }} for instant FX quotes or AI credit conversions with zero extra layout boilerplate.

## Replaces

auto-sizing currency input, cash-app amount input, token swap amount field, react-number-format, framer-motion

## Where it fits

- **Send money and payouts**: Let users type any transfer amount with fluid typography scaling, balance Max roll-up and exact overdraft feedback.
- **FX and token swaps**: Pair the hero amount with live conversion output and suffix token symbols such as USDC or ETH.
- **AI credits and billing top-ups**: Combine preset quick-pick pills with a live credits conversion readout right inside the hairline footer.
- **Invoice and wallet deposits**: Accept pasted formatted strings ($12,450.50) and emit clean number | null values straight to your checkout API.

## Notes

- A native <input inputMode="decimal"> handles mobile numeric keypads, clipboard paste, Ctrl+Z undo and screen readers while the visual layer renders place-value-keyed tokens and the gliding caret.
- Clicking anywhere across the hero figure places the caret at the nearest character boundary automatically.
- Crossing balance fires the recoil and rose Bayer pulse once on threshold entry rather than spamming on every subsequent digit.
- The 8×8 Bayer floor canvas sleeps completely at 0% CPU except during the ~0.48s overdraft or Max roll confirmation.
- Under prefers-reduced-motion: reduce, scaling, caret positioning and Max/preset jumps happen instantaneously with zero travel.

License: MIT (https://hairlineui.com/license#components)
