Componentdata1.21 KB gzipZero dependencies
Exchange Rate
Exchange rate converter with two-way live calculation.
Preview
Live Preview
Installation
Tokens guide →Add to your project via CLI (zero dependencies, code you own):
npx bigbullui add exchange-rateOr install the full npm package:
npm install bigbulluiUsage
tsx3 lines
import { ExchangeRate } from "@/components/ui/exchange-rate"; <ExchangeRate />Source code
exchange-rate.tsx + 1 helperZero third-party dependencies (2 local files shown in tabs below).
tsxexchange-rate.tsx99 lines
"use client"; import * as React from "react";import { cn } from "./lib/utils"; export interface ExchangeRateProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> { rates?: Record<string, number>; defaultFrom?: string; defaultTo?: string;} const RATE_TABLE: Record<string, number> = { TRY: 1, USD: 0.029, EUR: 0.027, GBP: 0.023 }; function convert(amount: number, from: string, to: string, rates: Record<string, number>): number { const f = rates[from] ?? 1; const t = rates[to] ?? 1; if (f === 0) return 0; return (amount / f) * t;Props
Interactive Prop Playground
Tweak parsed AST props below to generate ready-to-paste JSX.
tsx3 lines
import { ExchangeRate } from "@/components/ui/exchange-rate"; <ExchangeRate />| Prop | Type | Description |
|---|---|---|
| rates | Record<string, number> | Configures rates. (Default: RATE_TABLE) |
| defaultFrom | string | Configures default from. (Default: "TRY") |
| defaultTo | string | Configures default to. (Default: "USD") |