-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyCurrency.js
51 lines (48 loc) · 1.12 KB
/
MyCurrency.js
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
import PropTypes from 'prop-types';
import React from 'react';
import { StyleSheet, Text } from 'react-native';
import { formatCurrency } from './helperFunctions';
const MyComponent = ({
amount,
currencySymbol,
curencySymbolPosition,
decimalsToShow,
styles,
rest
}) => {
let txtStyle = styles !== undefined ? styles : defaultStyles.text;
const output = formatCurrency(
amount,
currencySymbol,
curencySymbolPosition,
decimalsToShow
);
return (
<>
<Text style={txtStyle} {...rest}>{output}</Text>
</>
);
};
const defaultStyles = StyleSheet.create({
text: {
color: '#000',
marginBottom: 4,
marginRight: 10
}
});
MyComponent.propTypes = {
amount: PropTypes.number.isRequired,
decimalsToShow: PropTypes.number,
curencySymbolPosition: PropTypes.string,
styles: PropTypes.instanceOf(Object),
currencySymbol : PropTypes.string.isRequired,
rest: PropTypes.instanceOf(Object)
};
MyComponent.defaultProps ={
styles: undefined,
decimalsToShow: 2,
curencySymbolPosition: 'front',
rest : {}
};
const MyCurrency = React.memo(MyComponent);
export default MyCurrency;