All files / badge badge.js

100% Statements 11/11
100% Branches 8/8
100% Functions 1/1
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52      3x   3x 4x   4x 1x     3x   3x 1x     3x             3x               3x                                    
import React, { PropTypes } from 'react';
import { Text, View, StyleSheet } from 'react-native';
 
let styles = {};
 
const Badge = props => {
  const { containerStyle, textStyle, value, children } = props.badge || props;
 
  if (children && value) {
    throw 'Badge can only contain a single child or string value';
  }
 
  var element = <Text style={[styles.text, textStyle]}>{value}</Text>;
 
  if (children) {
    element = children;
  }
 
  return (
    <View style={[styles.badge, containerStyle]}>
      {element}
    </View>
  );
};
 
Badge.propTypes = {
  badge: React.PropTypes.any,
  containerStyle: View.propTypes.style,
  textStyle: View.propTypes.style,
  children: PropTypes.element,
  value: PropTypes.string,
};
 
styles = StyleSheet.create({
  badge: {
    top: 2,
    padding: 12,
    paddingTop: 3,
    paddingBottom: 3,
    backgroundColor: '#444',
    borderRadius: 20,
    position: 'absolute',
    right: 30,
  },
  text: {
    fontSize: 14,
    color: 'white',
  },
});
 
export default Badge;