Skip to content

Free & Open-Source Invoice Generator - No Sign-Up, No Ads, Instant PDF Export, 100% In-Browser, and Fully Customizable Templates.

feat: add support for additional currencies and symbols (#92)

Vlad Sazonaufbbeb2d2c162
diff --git a/src/app/schema/index.ts b/src/app/schema/index.ts
index 3cc6916..d70736e 100644
--- a/src/app/schema/index.ts
+++ b/src/app/schema/index.ts
@@ -15,6 +15,10 @@ export const SUPPORTED_CURRENCIES = [
"ARS", // Argentine Peso
"INR", // Indian Rupee
"CHF", // Swiss Franc
+ "HKD", // Hong Kong Dollar
+ "TWD", // Taiwan Dollar
+ "CNY", // Chinese Yuan (RMB)
+ "SGD", // Singapore Dollar
] as const;
export type SupportedCurrencies = (typeof SUPPORTED_CURRENCIES)[number];
@@ -33,7 +37,13 @@ export const CURRENCY_SYMBOLS = {
ARS: "$", // Argentine Peso
INR: "₹", // Indian Rupee
CHF: "Fr", // Swiss Franc
+ HKD: "HK$", // Hong Kong Dollar
+ TWD: "NT$", // Taiwan Dollar
+ CNY: "¥", // Chinese Yuan (RMB)
+ SGD: "S$", // Singapore Dollar
} as const satisfies Record<SupportedCurrencies, string>;
+export type CurrencySymbols =
+ (typeof CURRENCY_SYMBOLS)[keyof typeof CURRENCY_SYMBOLS];
export const SUPPORTED_LANGUAGES = [
"en",
diff --git a/src/components/ui/money-input.tsx b/src/components/ui/money-input.tsx
index 073a955..7e16641 100644
--- a/src/components/ui/money-input.tsx
+++ b/src/components/ui/money-input.tsx
@@ -3,10 +3,29 @@ import { Input } from "./input";
import {
CURRENCY_SYMBOLS,
SUPPORTED_CURRENCIES,
+ type CurrencySymbols,
type InvoiceData,
} from "@/app/schema";
import { cn } from "@/lib/utils";
+function getCurrencyPadding(currencySymbol: CurrencySymbols) {
+ if (!currencySymbol) return "ps-3";
+
+ if (
+ currencySymbol === "Br" ||
+ currencySymbol === "R$" ||
+ currencySymbol === "S$"
+ ) {
+ return "ps-8";
+ }
+
+ if (currencySymbol === "HK$" || currencySymbol === "NT$") {
+ return "ps-10";
+ }
+
+ return "ps-6";
+}
+
const MoneyInput = React.memo(
React.forwardRef<
HTMLInputElement,
@@ -34,11 +53,7 @@ const MoneyInput = React.memo(
ref={ref}
className={cn(
"-me-px rounded-e-none ps-6 shadow-none",
- currencySymbol === "Br" || currencySymbol === "R$"
- ? "ps-8"
- : currencySymbol
- ? "ps-6"
- : "ps-3",
+ getCurrencyPadding(currencySymbol),
props.className
)}
placeholder="0.00"
@@ -80,11 +95,7 @@ const ReadOnlyMoneyInput = React.memo(
ref={ref}
className={cn(
"-me-px block w-full cursor-not-allowed rounded-md rounded-e-none border border-gray-300 bg-gray-100 px-3 py-2 ps-6",
- currencySymbol === "Br" || currencySymbol === "R$"
- ? "ps-8"
- : currencySymbol
- ? "ps-6"
- : "ps-3",
+ getCurrencyPadding(currencySymbol),
"focus-visible:border-indigo-500 focus-visible:ring focus-visible:ring-indigo-200 focus-visible:ring-opacity-50",
props.className
)}