All files / social SocialIcon.js

91.67% Statements 11/12
82.14% Branches 46/56
50% Functions 1/2
91.67% Lines 11/12
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204            1x       1x                                               1x                                           5x   5x   5x 1x                 5x                                                                                               1x                                                 1x             1x                                                                                                          
import React, { PropTypes } from 'react';
import { View, StyleSheet, Platform, TouchableHighlight, ActivityIndicator } from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
import Text from '../text/Text';
import fonts from '../config/fonts';
 
const log = () => {
  console.log('please attach method to this component'); // eslint-disable-line no-console
};
 
const colors = {
  facebook: '#3b5998',
  twitter: '#00aced',
  ['google-plus-official']: '#dd4b39',
  pinterest: '#cb2027',
  linkedin: '#007bb6',
  youtube: '#bb0000',
  vimeo: '#aad450',
  tumblr: '#32506d',
  instagram: '#517fa4',
  quora: '#a82400',
  foursquare: '#0072b1',
  wordpress: '#21759b',
  stumbleupon: '#EB4823',
  github: '#000000',
  ['github-alt']: '#000000',
  twitch: '#6441A5',
  medium: '#02b875',
  soundcloud: '#f50',
  gitlab: '#e14329',
  angellist: '#1c4082',
  codepen: '#000000'
};
 
const SocialIcon = props => {
  const {
    component,
    type,
    button,
    disabled,
    loading,
    activityIndicatorStyle,
    small,
    onPress,
    iconStyle,
    style,
    iconColor,
    title,
    raised,
    light,
    fontFamily,
    fontStyle,
    iconSize,
    onLongPress,
    fontWeight,
    ...attributes,
  } = props;
 
  const Component = (onPress || onLongPress) ? component || TouchableHighlight : View;
  let loadingElement;
  if(loading){
    loadingElement = (
      <ActivityIndicator
        animating={true}
        style={[styles.activityIndicatorStyle, activityIndicatorStyle]}
        color={iconColor || 'white'}
        size={small && 'small' || 'large'}
      />
    );
  }
  return (
    <Component
      underlayColor={light ? 'white' : colors[type]}
      onLongPress={!disabled && (onLongPress || log)}
      onPress={(!disabled || log) && (onPress || log)}
      disabled={disabled || false}
      style={[
        raised && styles.raised,
        styles.container,
        button && styles.button,
        !button && raised && styles.icon,
        !button && !light && !raised && {
          width: iconSize * 2 + 4,
          height: iconSize * 2 + 4,
          borderRadius: iconSize * 2
        },
        {backgroundColor: colors[type]},
        light && {backgroundColor: 'white'},
        style && style
      ]}
      {...attributes}
    >
      <View style={styles.wrapper}>
        <Icon
          style={[iconStyle && iconStyle]}
          color={light ? colors[type] : iconColor}
          name={type}
          size={iconSize} />
        {
          button && title && (
            <Text
              style={[
                styles.title,
                light && {color: colors[type]},
                fontFamily && {fontFamily},
                fontWeight && {fontWeight},
                fontStyle && fontStyle
              ]}>{title}</Text>
          )
        }
        {
            loading && loadingElement
        }
      </View>
    </Component>
  );
};
 
SocialIcon.propTypes = {
  component: PropTypes.element,
  type: PropTypes.string,
  button: PropTypes.bool,
  onPress: PropTypes.func,
  onLongPress: PropTypes.func,
  iconStyle: View.propTypes.style,
  style: View.propTypes.style,
  iconColor: PropTypes.string,
  title: PropTypes.string,
  raised: PropTypes.bool,
  disabled: PropTypes.bool,
  loading: PropTypes.bool,
  activityIndicatorStyle: View.propTypes.style,
  small: PropTypes.string,
  iconSize: PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.number
  ]),
  light: PropTypes.bool,
  fontWeight: PropTypes.string,
  fontStyle: View.propTypes.style,
  fontFamily: PropTypes.string,
};
 
SocialIcon.defaultProps = {
  raised: true,
  iconColor: 'white',
  iconSize: 24,
  button: false
};
 
const styles = StyleSheet.create({
  container: {
    margin: 7,
    borderRadius: 30,
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center'
  },
  button: {
    paddingTop: 14,
    paddingBottom: 14
  },
  raised: {
    ...Platform.select({
      ios: {
        shadowColor: 'rgba(0,0,0, .4)',
        shadowOffset: {height: 1, width: 1},
        shadowOpacity: 1,
        shadowRadius: 1
      },
      android: {
        elevation: 2
      }
    })
  },
  wrapper: {
    flexDirection: 'row',
    justifyContent: 'center',
    alignItems: 'center'
  },
  title: {
    color: 'white',
    marginLeft: 15,
    ...Platform.select({
      ios: {
        fontWeight: 'bold'
      },
      android: {
        ...fonts.android.black
      }
    })
  },
  icon: {
    height: 52,
    width: 52
  },
  activityIndicatorStyle: {
    marginHorizontal: 10,
    height: 0
  },
});
 
export default SocialIcon;