-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMoneyText.tsx
More file actions
57 lines (51 loc) · 1.46 KB
/
Copy pathMoneyText.tsx
File metadata and controls
57 lines (51 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React from 'react';
import { StyleSheet, Text as RNText } from 'react-native';
import { formatCurrencyFromCents, type CurrencyCode } from '@fairshare/shared-types';
import { useAppTheme } from '../../theme/useAppTheme';
interface MoneyTextProps {
cents: string;
size?: 'sm' | 'md' | 'lg';
variant?: 'default' | 'success' | 'danger';
currency?: CurrencyCode;
}
/**
* Renders a Text element that displays a currency amount formatted from a cents string and sets the accessibility label to the same formatted string.
*
* @param cents - Amount in cents as a string (for example, `"150"` represents $1.50)
* @param currency - ISO currency code used for formatting (defaults to `'USD'`)
* @returns A React element that renders the formatted currency string
*/
export function MoneyText({ cents, size = 'md', variant = 'default', currency = 'USD' }: MoneyTextProps) {
const { colors } = useAppTheme();
const amount = formatCurrencyFromCents(cents, currency);
const colorMap = {
default: colors.text_primary,
success: colors.success,
danger: colors.danger,
};
const sizeMap = {
sm: 14,
md: 18,
lg: 28,
};
return (
<RNText
style={[
styles.text,
{
color: colorMap[variant],
fontSize: sizeMap[size],
},
]}
accessibilityLabel={amount}
>
{amount}
</RNText>
);
}
const styles = StyleSheet.create({
text: {
fontWeight: '700',
letterSpacing: -0.3,
},
});