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