Overview
This module provides general-purpose utility functions used throughout the BudgetView application. Module:lib/utils.ts
cn
Utility function for conditionally joining class names together, merging Tailwind CSS classes intelligently.Function Signature
Parameters
Variable number of class values to merge. Accepts strings, objects, arrays, or any type supported by
clsxReturns
A merged string of class names with conflicts resolved by
tailwind-mergeExamples
How It Works
Thecn function combines two powerful utilities:
-
clsx- Constructs className strings conditionally, supporting:- Strings:
"foo bar" - Objects:
{ foo: true, bar: false }→"foo" - Arrays:
["foo", { bar: true }]→"foo bar" - Mixed: Any combination of the above
- Strings:
-
tailwind-merge- Intelligently merges Tailwind CSS classes:- Removes duplicate utilities
- Resolves conflicts (last class wins)
- Handles responsive variants
- Supports arbitrary values
Common Patterns
Wallet Utilities
Constants and helper functions for working with wallet identifiers. Module:lib/wallets.ts
Constants
Constant identifier for the global wallet:
"global"Display label for the global wallet:
"Global"isGlobalWallet
Checks if a wallet ID represents the global wallet.Function Signature
Parameters
The wallet ID to check
Returns
true if the wallet ID is the global wallet, false otherwiseExamples
Usage Throughout BudgetView
These utilities are used extensively across the application:cn Function Usage
- UI Components: All shadcn/ui components use
cnfor class merging - Custom Components: Header, Sidebar, Forms, and layout components
- Responsive Design: Combining base, responsive, and conditional classes
- Theme Variants: Applying theme-aware classes dynamically
Currency Functions Usage
- Dashboard: Displaying account balances in USD and VES
- Transactions Page: Formatting transaction amounts
- Budgets Page: Showing budget limits and spent amounts
- Wallets Page: Displaying wallet balances with exchange rates
- Export Page: Including formatted amounts in exported data
- Header Component: Real-time balance display with BCV rates
The
cn function is re-exported from lib/utils.ts and is imported in over 100 files throughout the codebase, making it one of the most frequently used utilities in BudgetView.