Text.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 } = props;
  12. let { color, theme, style, center } = 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. }
  26. if (bold) {
  27. style = {
  28. ...style,
  29. fontWeight: 'bold',
  30. };
  31. }
  32. if (center) {
  33. style = {
  34. ...style,
  35. textAlign: 'center',
  36. };
  37. }
  38. switch (size) {
  39. case 'h1':
  40. // 24
  41. return (
  42. <Headline
  43. theme={theme}
  44. style={{ ...style }}
  45. numberOfLines={1}
  46. ellipsizeMode="tail"
  47. align="center"
  48. >
  49. {children}
  50. </Headline>
  51. );
  52. case 's1':
  53. // 16
  54. return (
  55. <Subheading
  56. theme={theme}
  57. style={{ ...style }}
  58. numberOfLines={1}
  59. ellipsizeMode="tail"
  60. >
  61. {children}
  62. </Subheading>
  63. );
  64. case 'c1':
  65. // 12
  66. return (
  67. <Caption
  68. theme={theme}
  69. style={{ ...style }}
  70. numberOfLines={1}
  71. ellipsizeMode="tail"
  72. >
  73. {children}
  74. </Caption>
  75. );
  76. case 'c2':
  77. // 10
  78. return (
  79. <Text
  80. theme={theme}
  81. style={[{ fontSize: 10 }, { ...style }]}
  82. numberOfLines={1}
  83. ellipsizeMode="tail"
  84. >
  85. {children}
  86. </Text>
  87. );
  88. default:
  89. // 14
  90. return (
  91. <Paragraph
  92. theme={theme}
  93. numberOfLines={1}
  94. ellipsizeMode="tail"
  95. style={{ ...style }}
  96. >
  97. {children}
  98. </Paragraph>
  99. );
  100. }
  101. }
  102. export default withTheme(MyText);