xref: /MusicFree/src/components/base/themeText.tsx (revision e650bfb34226e2a09d15cbf7832c4805a87cd60e)
1import React from 'react';
2import {Text, TextProps} from 'react-native';
3import {
4    ColorKey,
5    colorMap,
6    fontSizeConst,
7    fontWeightConst,
8} from '@/constants/uiConst';
9import useColors from '@/hooks/useColors';
10
11type IThemeTextProps = TextProps & {
12    color?: string;
13    fontColor?: ColorKey;
14    fontSize?: keyof typeof fontSizeConst;
15    fontWeight?: keyof typeof fontWeightConst;
16};
17
18export default function ThemeText(props: IThemeTextProps) {
19    const colors = useColors();
20    const {
21        style,
22        color,
23        children,
24        fontSize = 'content',
25        fontColor = 'normal',
26        fontWeight = 'regular',
27    } = props;
28
29    const themeStyle = {
30        color: color ?? colors[colorMap[fontColor]],
31        fontSize: fontSizeConst[fontSize],
32        fontWeight: fontWeightConst[fontWeight],
33        includeFontPadding: false,
34    };
35
36    const _style = Array.isArray(style)
37        ? [themeStyle, ...style]
38        : [themeStyle, style];
39
40    return (
41        <Text {...props} style={_style} allowFontScaling={false}>
42            {children}
43        </Text>
44    );
45}
46