Text.js 2.1 KB

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