xref: /MusicFree/src/components/base/themeText.tsx (revision 1119c2ea435417cd5c53719f91691ff2b1aa8670)
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    opacity?: number;
17};
18
19export default function ThemeText(props: IThemeTextProps) {
20    const colors = useColors();
21    const {
22        style,
23        color,
24        children,
25        fontSize = 'content',
26        fontColor = 'normal',
27        fontWeight = 'regular',
28        opacity,
29    } = props;
30
31    const themeStyle = {
32        color: color ?? colors[colorMap[fontColor]],
33        fontSize: fontSizeConst[fontSize],
34        fontWeight: fontWeightConst[fontWeight],
35        includeFontPadding: false,
36        opacity,
37    };
38
39    const _style = Array.isArray(style)
40        ? [themeStyle, ...style]
41        : [themeStyle, style];
42
43    return (
44        <Text {...props} style={_style} allowFontScaling={false}>
45            {children}
46        </Text>
47    );
48}
49