Token price
Formats token prices with optional positive, negative, or neutral change.
TokenPrice formats a value in your chosen currency. Pass change to show a percentage with a direction icon and trend color.
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 @onchain-ui/token-priceUsage
import { TokenPrice } from "@/components/ui/token-price"
<TokenPrice value={3241.82} change={2.41} />Fetch prices in your app and pass them through value. TokenPrice does not request price data.
Examples
Change states
Pass change as a percentage value. For example, -2.34 renders as -2.34%.
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.
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
Set compact to abbreviate large values with units such as K and M.
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 priceClassName to style the value and changeClassName to style the percentage change.
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-negative/10 px-1.5 py-0.5" /> )}Theming
The change color comes from two theme tokens, used like shadcn's destructive: text-positive for gains and text-negative for losses. Neutral changes use text-muted-foreground.
Installing the component adds both tokens to your CSS file for light and dark mode, plus the @theme inline entries that turn them into Tailwind classes. The CLI keeps any --positive or --negative you already define, so an existing palette wins. Edit the values to match your brand:
:root {
--positive: oklch(0.596 0.145 163.225);
--negative: oklch(0.577 0.245 27.325);
}
.dark {
--positive: oklch(0.765 0.177 163.223);
--negative: oklch(0.704 0.191 22.216);
}
@theme inline {
--color-positive: var(--positive);
--color-negative: var(--negative);
}If you copy the file by hand instead of using the CLI, add these lines yourself. Without them the change text uses the surrounding text color, and the sign and arrow still show the direction.
The tokens also work in your own styles, for example changeClassName="bg-negative/10".
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | string | null | undefined | - | Token price value |
currency | string | "USD" | ISO 4217 currency code |
locale | string | Browser/default locale | Locale passed to Intl.NumberFormat |
compact | boolean | false | Use compact notation |
fallback | ReactNode | "--" | Shown when price is missing or invalid |
minimumFractionDigits | number | - | Minimum fraction digits for the price |
maximumFractionDigits | number | Based on value size | Maximum fraction digits for the price |
change | number | null | - | Percentage change, e.g. -2.34 means -2.34% |
trend | "up" | "down" | "neutral" | Derived from change | Override the change direction |
showChangeIcon | boolean | true | Show the trend icon |
changeFractionDigits | number | 2 | Fraction digits for the change value |
hidePositiveSign | boolean | false | Hide + for positive changes |
className | string | - | Applied to the root wrapper |
priceClassName | string | - | Applied to the formatted price |
changeClassName | string | - | Applied to the change element |