-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathText.tsx
61 lines (50 loc) · 1.88 KB
/
Text.tsx
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
import type {ForwardedRef} from 'react';
import React from 'react';
// eslint-disable-next-line no-restricted-imports
import {Text as RNText, StyleSheet} from 'react-native';
import type {TextProps as RNTextProps, TextStyle} from 'react-native';
import useTheme from '@hooks/useTheme';
import type {FontUtilsType} from '@styles/utils/FontUtils';
import FontUtils from '@styles/utils/FontUtils';
import variables from '@styles/variables';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
type TextProps = RNTextProps &
ChildrenProps & {
/** The color of the text */
color?: string;
/** The size of the text */
fontSize?: number;
/** The alignment of the text */
textAlign?: TextStyle['textAlign'];
/** Any children to display */
children: React.ReactNode;
/** The family of the font to use */
family?: keyof FontUtilsType['fontFamily']['platform'];
};
function Text({color, fontSize = variables.fontSizeNormal, textAlign = 'left', children, family = 'EXP_NEUE', style = {}, ...props}: TextProps, ref: ForwardedRef<RNText>) {
const theme = useTheme();
const componentStyle: TextStyle = {
color: color ?? theme.text,
fontSize,
textAlign,
fontFamily: FontUtils.fontFamily.platform[family],
...StyleSheet.flatten(style),
};
if (!componentStyle.lineHeight && componentStyle.fontSize === variables.fontSizeNormal) {
componentStyle.lineHeight = variables.fontSizeNormalHeight;
}
return (
<RNText
allowFontScaling={false}
ref={ref}
style={componentStyle}
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
>
{children}
</RNText>
);
}
Text.displayName = 'Text';
export default React.forwardRef(Text);
export type {TextProps};