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