[Amount] Improve formatting capabilities and fix edge cases
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 70
- Forks
- 13
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 8
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 (#674)
- TypeScript strictness (#675)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Amount component and its Intl.NumberFormat usage, then inspect the existing currencyDisplay props and formatting paths. The work is done when the requested notation, narrowSymbol, and signDisplay options are supported, formatter creation is memoized or combined, and short values format correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100