123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import * as React from 'react';
- import { Text, StyleSheet } from 'react-native';
- import PropTypes from 'prop-types';
- import variables from './';
-
-
- const styles = StyleSheet.create({
- text: {
- fontWeight: variables.fontWeight.light
- },
- tiny: {
- fontSize: variables.fontSize.tiny
- },
- small: {
- fontSize: variables.fontSize.small
- },
- normal: {
- fontSize: variables.fontSize.normal
- },
- medium: {
- fontSize: variables.fontSize.medium
- },
- large: {
- fontSize: variables.fontSize.large
- },
- xlarge: {
- fontSize: variables.fontSize.xlarge
- },
- xxlarge: {
- fontSize: variables.fontSize.xxlarge
- },
- xxxlarge: {
- fontSize: variables.fontSize.xxxlarge
- },
- primary: {
- color: variables.color.text.primary
- },
- secondary: {
- color: variables.color.text.secondary
- },
- tip: {
- color: variables.color.text.tip
- },
- placeholder: {
- color: variables.color.text.placeholder
- },
- white: {
- color: variables.color.white
- },
- error: {
- color: variables.color.error
- }
- });
-
- class AppText extends React.Component {
-
- setNativeProps(props) {
- this.refs.text.setNativeProps(props);
- }
-
- render() {
- const { size, type, style, singleLine, ...others } = this.props;
- const filteredOthers = singleLine ? { numberOfLines: 1, ...others } : { ...others };
- return (
- <Text ref="text" style={[styles.text, styles[size], styles[type], style]} {...filteredOthers}>{this.props.children}</Text>
- );
- }
- }
-
- AppText.propTypes = {
- size: PropTypes.oneOf(['tiny', 'small', 'normal', 'medium', 'large', 'xlarge', 'xxlarge', 'xxxlarge']),
- type: PropTypes.oneOf(['primary', 'secondary', 'tip', 'placeholder', 'white', 'error']),
- style: PropTypes.any,
- children: PropTypes.node,
- singleLine: PropTypes.bool
- };
-
- AppText.defaultProps = {
- size: 'normal',
- type: 'primary'
- };
-
- export default AppText;
|