No Description

AppText.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import * as React from 'react';
  2. import { Text, StyleSheet } from 'react-native';
  3. import PropTypes from 'prop-types';
  4. import variables from './';
  5. const styles = StyleSheet.create({
  6. text: {
  7. fontWeight: variables.fontWeight.light
  8. },
  9. tiny: {
  10. fontSize: variables.fontSize.tiny
  11. },
  12. small: {
  13. fontSize: variables.fontSize.small
  14. },
  15. normal: {
  16. fontSize: variables.fontSize.normal
  17. },
  18. medium: {
  19. fontSize: variables.fontSize.medium
  20. },
  21. large: {
  22. fontSize: variables.fontSize.large
  23. },
  24. xlarge: {
  25. fontSize: variables.fontSize.xlarge
  26. },
  27. xxlarge: {
  28. fontSize: variables.fontSize.xxlarge
  29. },
  30. xxxlarge: {
  31. fontSize: variables.fontSize.xxxlarge
  32. },
  33. primary: {
  34. color: variables.color.text.primary
  35. },
  36. secondary: {
  37. color: variables.color.text.secondary
  38. },
  39. tip: {
  40. color: variables.color.text.tip
  41. },
  42. placeholder: {
  43. color: variables.color.text.placeholder
  44. },
  45. white: {
  46. color: variables.color.white
  47. },
  48. error: {
  49. color: variables.color.error
  50. }
  51. });
  52. class AppText extends React.Component {
  53. setNativeProps(props) {
  54. this.refs.text.setNativeProps(props);
  55. }
  56. render() {
  57. const { size, type, style, singleLine, ...others } = this.props;
  58. const filteredOthers = singleLine ? { numberOfLines: 1, ...others } : { ...others };
  59. return (
  60. <Text ref="text" style={[styles.text, styles[size], styles[type], style]} {...filteredOthers}>{this.props.children}</Text>
  61. );
  62. }
  63. }
  64. AppText.propTypes = {
  65. size: PropTypes.oneOf(['tiny', 'small', 'normal', 'medium', 'large', 'xlarge', 'xxlarge', 'xxxlarge']),
  66. type: PropTypes.oneOf(['primary', 'secondary', 'tip', 'placeholder', 'white', 'error']),
  67. style: PropTypes.any,
  68. children: PropTypes.node,
  69. singleLine: PropTypes.bool
  70. };
  71. AppText.defaultProps = {
  72. size: 'normal',
  73. type: 'primary'
  74. };
  75. export default AppText;