Text.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import * as React from 'react';
  2. import {
  3. Headline,
  4. Paragraph,
  5. Subheading,
  6. Caption,
  7. withTheme,
  8. Text,
  9. } from 'react-native-paper';
  10. function MyText(props) {
  11. const { type, size, children, bold, center, more } = props;
  12. let { color, theme, style } = props;
  13. const { colors } = theme;
  14. if (type) {
  15. color = colors[type];
  16. }
  17. if (color) {
  18. theme = {
  19. ...theme,
  20. colors: {
  21. ...theme.colors,
  22. text: color,
  23. },
  24. };
  25. } else {
  26. theme = {
  27. ...theme,
  28. colors: {
  29. ...theme.colors,
  30. text: '#000',
  31. },
  32. };
  33. }
  34. if (bold) {
  35. style = {
  36. ...style,
  37. fontWeight: 'bold',
  38. };
  39. }
  40. if (center) {
  41. style = {
  42. ...style,
  43. textAlign: 'center',
  44. };
  45. }
  46. let lineProps = {
  47. numberOfLines: 1,
  48. ellipsizeMode: 'tail',
  49. };
  50. if (more) {
  51. lineProps = {};
  52. }
  53. if (children) {
  54. switch (size) {
  55. case 'h1':
  56. // 24
  57. return (
  58. <Headline
  59. theme={theme}
  60. style={{ ...style }}
  61. align="center"
  62. {...lineProps}
  63. >
  64. {children}
  65. </Headline>
  66. );
  67. case 's1':
  68. // 16
  69. return (
  70. <Subheading theme={theme} style={{ ...style }} {...lineProps}>
  71. {children}
  72. </Subheading>
  73. );
  74. case 'c1':
  75. // 12
  76. return (
  77. <Text
  78. theme={theme}
  79. style={[{ fontSize: 12 }, style]}
  80. numberOfLines={1}
  81. ellipsizeMode="tail"
  82. >
  83. {children}
  84. </Text>
  85. );
  86. case 'c2':
  87. // 10
  88. return (
  89. <Text theme={theme} style={[{ fontSize: 10 }, style]} {...lineProps}>
  90. {children}
  91. </Text>
  92. );
  93. default:
  94. // 14
  95. return (
  96. <Paragraph theme={theme} {...lineProps} style={{ ...style }}>
  97. {children}
  98. </Paragraph>
  99. );
  100. }
  101. } else {
  102. return <></>;
  103. }
  104. }
  105. export default withTheme(MyText);