import {cn} from '../../lib/utils' import {formatMoney} from '../../utils/formatMoney' /** * A component for displaying product pricing with support for discounts and custom styling. * @publicDocs */ export interface ProductVariantPriceProps { amount: number | string currencyCode?: string compareAtPriceAmount?: number | string compareAtPriceCurrencyCode?: string currentPriceClassName?: string originalPriceClassName?: string className?: string } export function ProductVariantPrice({ amount, currencyCode, compareAtPriceAmount, compareAtPriceCurrencyCode, currentPriceClassName, originalPriceClassName, className, }: ProductVariantPriceProps) { if (!amount || !currencyCode) { return null } const hasDiscount = compareAtPriceAmount && compareAtPriceAmount !== amount const amountStr = String(amount) const compareAtPriceAmountStr = compareAtPriceAmount ? String(compareAtPriceAmount) : undefined return (
{hasDiscount ? ( <> {formatMoney(amountStr, currencyCode)} {formatMoney( compareAtPriceAmountStr!, compareAtPriceCurrencyCode || currencyCode )} ) : ( {formatMoney(amountStr, currencyCode)} )}
) }