-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Summary
Improvements to the Amount component to enhance formatting capabilities, fix edge cases, and follow component conventions.
Improvements
2. Add notation prop
No way to get compact formatting like $1.2M or $13K. Intl.NumberFormat supports notation: 'compact' natively. This is useful for dashboards and summary views.
3. Add narrowSymbol to currencyDisplay
Intl.NumberFormat supports 'narrowSymbol' (e.g., $ instead of US$ in non-US locales), but the currencyDisplay prop only allows 'symbol' | 'code' | 'name'.
4. Add signDisplay prop
Intl.NumberFormat supports signDisplay ('auto', 'always', 'exceptZero', 'never') for controlling +/- sign display — useful for showing gains/losses.
5. Memoize formatter instances
getCurrencyDecimals() and isValidCurrency() each create a new Intl.NumberFormat instance on every render. These should be memoized or combined into a single formatter creation.
6. Fix string slicing edge case for short strings
value.slice(0, -decimals) + '.' + value.slice(-decimals) breaks for strings shorter than the decimal count (e.g., value="5" with USD → ".5" instead of "0.05").
Moved to Cross-Cutting Issues
The following items have been moved to cross-cutting issues that address them across all components:
- Forward HTML attributes (Forward HTML attributes (spread rest props) #674)
- TypeScript strictness (TypeScript strictness: eliminate any, @ts-ignore, and export prop types #675)