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