{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "token-input",
  "title": "Token Input",
  "description": "Swap/send panel: label, AmountInput, TokenSelect pill, fiat value from a price prop, the connected account's balance of the chosen token with Max, and an 'Insufficient <symbol> balance' state. onValueChange returns the amount as a bigint plus insufficient. readOnly and checkBalance=false for 'you receive' panels.",
  "dependencies": [
    "viem"
  ],
  "registryDependencies": [
    "@0xui/amount-input",
    "@0xui/token-select",
    "@0xui/balance",
    "@0xui/token-amount",
    "@0xui/morph-text"
  ],
  "files": [
    {
      "path": "registry/default/components/token-input.tsx",
      "content": "// Docs: https://0xui.io/components/token-input.md\nimport { useId, type ReactNode } from \"react\";\nimport { formatUnits } from \"viem\";\nimport {\n  AmountInput,\n  getAmountState,\n  type AmountState,\n} from \"@/components/amount-input\";\nimport { useTokenBalance } from \"@/components/balance\";\nimport { MorphText } from \"@/components/morph-text\";\nimport { TokenAmount, formatFiat } from \"@/components/token-amount\";\nimport {\n  TokenSelect,\n  getTokenPrice,\n  isNativeToken,\n  type Token,\n  type TokenPrices,\n} from \"@/components/token-select\";\nimport { cn } from \"@/lib/utils\";\n\nexport type TokenInputState = AmountState & {\n  /** True when the amount is above the connected account's balance. */\n  insufficient: boolean;\n  /** Connected account's balance of the selected token, once loaded. */\n  balance: bigint | undefined;\n};\n\nexport type TokenInputProps = {\n  /** Label above the panel, e.g. \"You pay\". */\n  label?: ReactNode;\n  /** Decimal string amount. */\n  value: string;\n  onValueChange: (value: string, state: TokenInputState) => void;\n  /** Selected token. */\n  token?: Token;\n  onTokenChange?: (token: Token) => void;\n  /** Tokens for the picker. Omit to lock the token. */\n  tokens?: readonly Token[];\n  /** Symbols or addresses shown as quick picks in the token picker. */\n  popular?: readonly string[];\n  /** Price of one token, for the fiat line. Defaults to the token's entry in `prices`. */\n  price?: number;\n  /** Prices keyed by `chainId:address`, address or symbol: the fiat line, and sorting held tokens in the picker by value. */\n  prices?: TokenPrices;\n  currency?: string;\n  /** Check the amount against the balance and offer Max. Turn off for \"you receive\" panels. */\n  checkBalance?: boolean;\n  /** Make the amount read-only, e.g. for a quoted output. */\n  readOnly?: boolean;\n  className?: string;\n};\n\n/**\n * Token amount panel: label, big amount input, token picker, fiat value,\n * balance with Max, and an \"Insufficient balance\" state. The building block\n * of swap and send forms.\n */\nexport function TokenInput({\n  label,\n  value,\n  onValueChange,\n  token,\n  onTokenChange,\n  tokens,\n  popular,\n  price: priceProp,\n  prices,\n  currency,\n  checkBalance = true,\n  readOnly = false,\n  className,\n}: TokenInputProps) {\n  const id = useId();\n  const price = priceProp ?? (token ? getTokenPrice(prices, token) : undefined);\n  const decimals = token?.decimals ?? 18;\n  const { value: balance } = useTokenBalance({\n    token: token && !isNativeToken(token) ? token.address : undefined,\n    chainId: token?.chainId,\n    enabled: Boolean(token) && checkBalance,\n  });\n  const max = checkBalance && token ? balance : undefined;\n\n  const stateFor = (next: string): TokenInputState => {\n    const state = getAmountState(next, decimals, max);\n    return { ...state, insufficient: state.exceedsMax, balance: max };\n  };\n  const current = stateFor(value);\n\n  const fiat =\n    price !== undefined && current.amount !== undefined\n      ? formatFiat(current.amount, decimals, price, { currency })\n      : undefined;\n\n  return (\n    <div\n      data-slot=\"token-input\"\n      data-insufficient={current.insufficient || undefined}\n      className={cn(\n        \"flex flex-col gap-2 rounded-2xl border bg-muted/30 p-4 focus-within:border-ring\",\n        current.insufficient && \"border-destructive/60\",\n        className\n      )}\n    >\n      {label && (\n        <label htmlFor={id} className=\"text-sm text-muted-foreground\">\n          {label}\n        </label>\n      )}\n      <div className=\"flex items-center gap-3\">\n        <AmountInput\n          id={id}\n          value={value}\n          onValueChange={(next) => onValueChange(next, stateFor(next))}\n          decimals={decimals}\n          max={max}\n          showMax={false}\n          readOnly={readOnly}\n          label={typeof label === \"string\" ? label : \"Amount\"}\n          className=\"flex-1\"\n        />\n        {tokens && onTokenChange ? (\n          <TokenSelect\n            tokens={tokens}\n            value={token}\n            onValueChange={onTokenChange}\n            chainId={token?.chainId}\n            popular={popular}\n            prices={prices}\n            className=\"shrink-0\"\n          />\n        ) : (\n          token && (\n            <span className=\"inline-flex h-10 shrink-0 items-center rounded-full border px-4 text-sm font-semibold\">\n              {token.symbol}\n            </span>\n          )\n        )}\n      </div>\n      <div className=\"flex min-h-5 items-center justify-between gap-2 text-sm text-muted-foreground\">\n        <span className=\"tabular-nums\">\n          <MorphText>{fiat}</MorphText>\n        </span>\n        {current.insufficient ? (\n          <span role=\"alert\" className=\"text-destructive\">\n            Insufficient {token?.symbol} balance\n          </span>\n        ) : (\n          max !== undefined &&\n          token && (\n            <span className=\"flex items-center gap-1\">\n              Balance:\n              <TokenAmount value={max} decimals={decimals} animate />\n              {!readOnly && max > 0n && (\n                <button\n                  type=\"button\"\n                  onClick={() => {\n                    const next = formatUnits(max, decimals);\n                    onValueChange(next, stateFor(next));\n                  }}\n                  className=\"rounded px-1 font-medium text-primary hover:bg-muted\"\n                >\n                  Max\n                </button>\n              )}\n            </span>\n          )\n        )}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "docs": "Docs: https://0xui.io/components/token-input.md",
  "categories": [
    "tokens"
  ],
  "type": "registry:component"
}