Alphaonchain-ui is experimental. Components, docs, and registry URLs may change before a stable release.
onchain-ui
Components

Token Price

Formats token prices with optional positive, negative, or neutral change.

Use TokenPrice for token rows, market cards, swap quotes, portfolio summaries, and any UI that needs a price plus a compact change signal.

Loading...
token-price.tsxShow code
import { TokenPrice } from "@/components/ui/token-price"export function TokenPriceDemo() {  return <TokenPrice value={3241.82} change={2.41} />}

Installation

npx shadcn add https://onchain-ui.dev/r/token-price.json
Open in

Usage

import { TokenPrice } from "@/components/ui/token-price"

<TokenPrice value={3241.82} change={2.41} />

TokenPrice is display-only. Bring your own data from CoinGecko, DefiLlama, an indexer, an oracle, or your app backend, then pass the resolved value into the component.

Examples

Change States

Pass change as a percentage value. For example, -2.34 renders as -2.34%.

Loading...
token-price-changes.tsxShow code
import { TokenPrice } from "@/components/ui/token-price"export function TokenPriceChanges() {  return (    <div className="grid gap-3">      <TokenPrice value={3241.82} change={2.41} />      <TokenPrice value={0.9978} change={-0.12} />      <TokenPrice value={1} change={0} />    </div>  )}

Small Values

Small token prices automatically keep more decimal places.

Loading...
token-price-small-values.tsxShow code
import { TokenPrice } from "@/components/ui/token-price"export function TokenPriceSmallValues() {  return (    <div className="grid gap-3">      <TokenPrice value={0.9978} change={0.02} />      <TokenPrice value={0.034567} change={-4.16} />      <TokenPrice value={0.00012891} change={12.08} />    </div>  )}

Compact

Use compact notation for larger market numbers or tight card layouts.

Loading...
token-price-compact.tsxShow code
import { TokenPrice } from "@/components/ui/token-price"export function TokenPriceCompact() {  return <TokenPrice value={1234567.89} change={8.24} compact />}

Custom Styling

Use class hooks to match your table, card, or badge treatment.

Loading...
token-price-custom.tsxShow code
import { TokenPrice } from "@/components/ui/token-price"export function TokenPriceCustom() {  return (    <TokenPrice      value={184.42}      change={-3.18}      className="rounded-md border bg-card px-3 py-2"      priceClassName="text-lg font-semibold"      changeClassName="rounded-sm bg-red-500/10 px-1.5 py-0.5"    />  )}

Props

PropTypeDefaultDescription
valuenumber | string | null | undefined-Token price value
currencystring"USD"ISO 4217 currency code
localestringBrowser/default localeLocale passed to Intl.NumberFormat
compactbooleanfalseUse compact notation
fallbackReactNode"--"Shown when price is missing or invalid
minimumFractionDigitsnumber-Minimum fraction digits for the price
maximumFractionDigitsnumberBased on value sizeMaximum fraction digits for the price
changenumber | null-Percentage change, e.g. -2.34 means -2.34%
trend"up" | "down" | "neutral"Derived from changeOverride the change direction
showChangeIconbooleantrueShow the trend icon
changeFractionDigitsnumber2Fraction digits for the change value
hidePositiveSignbooleanfalseHide + for positive changes
classNamestring-Applied to the root wrapper
priceClassNamestring-Applied to the formatted price
changeClassNamestring-Applied to the change element

On this page