-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathText.js
More file actions
62 lines (57 loc) · 1.45 KB
/
Text.js
File metadata and controls
62 lines (57 loc) · 1.45 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
58
59
60
61
62
import React from 'react';
import {Text, StyleSheet} from 'react-native';
import PropTypes from 'prop-types';
import {useThemeContext} from '../util/ThemeProvider';
import {resizeFont} from '../util/resizeFont';
const getTextStyle = ({theme, color, size, scale, fontWeight, textAlign}) => {
return {
color: theme.textColor[color],
fontSize: scale ? theme.fontSize[size] : resizeFont(theme.fontSize[size]),
includeFontPadding: false,
textAlignVertical: 'center',
textAlign,
fontWeight: fontWeight,
};
};
const TextElement = ({style, ...props}) => {
const theme = useThemeContext();
return (
<Text
{...props}
style={StyleSheet.flatten([getTextStyle({...props, theme}), style])}>
{props.children}
</Text>
);
};
TextElement.propTypes = {
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
children: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
PropTypes.array,
]).isRequired,
size: PropTypes.oneOfType([
PropTypes.oneOf([
'xxsmall',
'xsmall',
'small',
'medium',
'large',
'xlarge',
'xxlarge',
]),
PropTypes.string,
]),
color: PropTypes.string,
scale: PropTypes.bool,
fontWeight: PropTypes.string,
textAlign: PropTypes.oneOf(['left', 'center', 'right']),
};
TextElement.defaultProps = {
color: 'default',
size: 'medium',
scale: true,
fontWeight: '500',
textAlign: 'left',
};
export default TextElement;