All files / badge badge.js

100% Statements 10/10
100% Branches 4/4
100% Functions 1/1
100% Lines 8/8
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      3x   3x 3x   3x   2x   1x             3x       3x                                    
import React from 'react';
import { Text, View, StyleSheet } from 'react-native';
 
let styles = {};
 
const Badge = props => {
  const { badge } = props;
 
  if (!badge) throw Error('badge prop is required');
 
  if (badge.element) return badge.element;
 
  return (
    <View style={[ styles.badge, badge.badgeContainerStyle ]}>
      <Text style={[ styles.text, badge.badgeTextStyle ]}>{badge.value}</Text>
    </View>
  );
};
 
Badge.propTypes = {
  badge: React.PropTypes.any,
};
 
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;