Text.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 } = 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. switch (size) {
  33. case 'h1':
  34. // 24
  35. return (
  36. <Headline theme={theme} style={{ ...style }}>
  37. {children}
  38. </Headline>
  39. )
  40. case 's1':
  41. // 16
  42. return (
  43. <Subheading theme={theme} style={{ ...style }}>
  44. {children}
  45. </Subheading>
  46. )
  47. case 'c1':
  48. // 12
  49. return (
  50. <Caption theme={theme} style={{ ...style }}>
  51. {children}
  52. </Caption>
  53. )
  54. case 'c2':
  55. // 10
  56. return (
  57. <Text theme={theme} style={[{ fontSize: 10 }, { ...style }]}>
  58. {children}
  59. </Text>
  60. )
  61. default:
  62. // 14
  63. return <Paragraph theme={theme}>{children}</Paragraph>
  64. }
  65. }
  66. export default withTheme(MyText)