Skip to content

Commit

Permalink
added icon component, updated button component to allow more specificity
Browse files Browse the repository at this point in the history
  • Loading branch information
dabit3 committed Sep 14, 2016
1 parent c525e24 commit 796f2ce
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 11 deletions.
61 changes: 60 additions & 1 deletion Readme.MD
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ To override the fontFamily in any element, simply provide a fontFamily prop:
## Buttons
Buttons take a title and an optional [material icon name](https://design.google.com/icons/), as well as the props below.

> You can override Material icons with one of the following: zocial, font-awesome, octicon, ionicon, foundation, evilicon, or entypo by passing in an icon.type as a prop.
> You can override Material icons with one of the following: zocial, font-awesome, octicon, ionicon, foundation, evilicon, or entypo by providing an icon.type as a prop.
![Buttons](http://i.imgur.com/jeXZSMC.png)

Expand Down Expand Up @@ -147,6 +147,64 @@ import { Button } from 'react-native-elements'
| underlayColor | transparent | string(color) | underlay color for button press (optional) |
| raised | false | boolean | flag to add raised button styling (optional) |

## Icons

![Icons](http://i.imgur.com/uX5vaD4.png)

Icons take the name of a [material icon](https://design.google.com/icons/) as a prop.

> You can override Material icons with one of the following: zocial, font-awesome, octicon, ionicon, foundation, evilicon, or entypo by providing a type prop.
```js

import { Icon } from 'react-native-icons'

<Icon
name='rowing' />

<Icon
name='g-translate'
color='#00aced' />

<Icon
name='sc-telegram'
type='evilicon'
color='#517fa4'
/>

<Icon
reverse
name='ios-american-football'
type='ionicon'
color='#517fa4'
/>

<Icon
raised
name='heartbeat'
type='font-awesome'
color='#f50'
onPress={() => console.log('hello')} />

```

#### Icon props

| prop | default | type | description |
| ---- | ---- | ----| ---- |
| name | none | string | name of icon (required) |
| type | material | string | type (defaults to material, options are `zocial, font-awesome, octicon, ionicon, foundation, evilicon, or entypo`) |
| size | 26 | number | size of icon (optional) |
| color | black | string | color of icon (optional) |
| iconStyle | inherited style | object (style) | additional styling to icon (optional) |
| component | View if no onPress method is defined, TouchableHighlight if onPress method is defined | React Native component | update React Native Component (optional) |
| onPress | none | function | onPress method for button (optional) |
| underlayColor | icon color | string | underlayColor for press event |
| reverse | false | boolean | reverses color scheme (optional) |
| raised | false | boolean | adds box shadow to button (optional) |
| containerStyle | inherited styling | object (style) | add styling to container holding icon (optional) |
| reverseColor | white | string | specify reverse icon color (optional) |


## Social Icons & Buttons

Expand Down Expand Up @@ -181,6 +239,7 @@ import { SocialIcon } from 'react-native-elements'
| iconStyle | none | object (style) | extra styling for icon component (optional) |
| style | none | object (style) | button styling (optional) |
| iconColor | white | string | icon color (optional) |
| iconSize | 24 | number | icon size (optional) |
| component | TouchableHighlight | React Native Component | type of button (optional) |
| fontFamily | System font bold (iOS), Roboto-Black (android) | string | specify different font family |
| fontStyle | none | object (style) | specify text styling |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-elements",
"version": "0.4.3",
"version": "0.4.4",
"description": "React Native Elements & UI Toolkit",
"main": "src/index.js",
"repository": {
Expand Down
107 changes: 107 additions & 0 deletions src/icons/Icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React, { PropTypes } from 'react'
import { Platform, TouchableHighlight, View, StyleSheet } from 'react-native'
import getIconType from '../helpers/getIconType'

let styles = {}

const Icon = ({
type,
name,
size,
color,
iconStyle,
component,
onPress,
underlayColor,
reverse,
raised,
containerStyle,
reverseColor
}) => {
let Component = View
if (onPress) {
Component = TouchableHighlight
}
if (component) {
Component = component
}
let Icon
if (!type) {
Icon = getIconType('material')
} else {
Icon = getIconType(type)
}
return (
<Component
underlayColor={
reverse ? color : underlayColor || color
}
style={[
styles.button,
raised && styles.raised, {
borderRadius: size,
backgroundColor: reverse ? color : raised ? 'white' : 'transparent',
height: size * 2,
width: size * 2,
alignItems: 'center',
justifyContent: 'center'},
containerStyle && containerStyle
]}
onPress={onPress}>
<Icon
style={[
{backgroundColor: 'transparent'},
iconStyle && iconStyle
]}
size={size}
name={name}
color={reverse ? reverseColor : color} />
</Component>
)
}

Icon.propTypes = {
type: PropTypes.string,
name: PropTypes.string,
size: PropTypes.number,
color: PropTypes.string,
component: PropTypes.element,
underlayColor: PropTypes.string,
reverse: PropTypes.bool,
raised: PropTypes.bool,
containerStyle: PropTypes.object,
iconStyle: PropTypes.object,
onPress: PropTypes.func,
reverseColor: PropTypes.string
}

Icon.defaultProps = {
underlayColor: 'white',
reverse: false,
raised: false,
size: 26,
color: 'black',
reverseColor: 'white'
}

styles = StyleSheet.create({
button: {
marginLeft: 3,
marginRight: 3
},
raised: {
...Platform.select({
ios: {
shadowColor: 'rgba(0,0,0, .4)',
shadowOffset: {height: 1, width: 1},
shadowOpacity: 1,
shadowRadius: 1
},
android: {
elevation: 2
}
})
}
})

export default Icon
42 changes: 33 additions & 9 deletions src/social/SocialIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,35 @@ const colors = {
codepen: '#000000'
}

const SocialIcon = ({component, type, button, onPress, iconStyle, style, iconColor, title, raised, light, fontFamily, fontStyle}) => {
const SocialIcon = ({
component,
type,
button,
onPress,
iconStyle,
style,
iconColor,
title,
raised,
light,
fontFamily,
fontStyle,
iconSize
}) => {
const Component = !onPress ? View : component || TouchableHighlight
return (
<Component
underlayColor={light ? 'white' : colors[type]}
onPress={onPress}
style={[
{justifyContent: 'center',
alignItems: 'center'},
raised && styles.raised,
styles.container,
button ? styles.button : styles.icon,
!button && iconSize && {width: iconSize * 2 + 4},
!button && iconSize && {height: iconSize * 2 + 4},
!button && iconSize && {borderRadius: iconSize * 2},
{backgroundColor: colors[type]},
light && {backgroundColor: 'white'},
light && !raised && {marginLeft: 2, marginRight: 2},
Expand All @@ -49,7 +68,7 @@ const SocialIcon = ({component, type, button, onPress, iconStyle, style, iconCol
style={[iconStyle && iconStyle]}
color={light ? colors[type] : iconColor}
name={type}
size={24} />
size={iconSize} />
{
button && title && (
<Text
Expand All @@ -75,19 +94,27 @@ SocialIcon.propTypes = {
style: PropTypes.any,
iconColor: PropTypes.string,
title: PropTypes.string,
raised: PropTypes.bool
raised: PropTypes.bool,
iconSize: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number
])
}

SocialIcon.defaultProps = {
raised: true,
iconColor: 'white'
iconColor: 'white',
iconSize: 24,
button: false
}

styles = StyleSheet.create({
container: {
margin: 7,
padding: 15,
borderRadius: 30
borderRadius: 30,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center'
},
raised: {
...Platform.select({
Expand All @@ -103,9 +130,6 @@ styles = StyleSheet.create({
})
},
wrapper: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center'
},
title: {
color: 'white',
Expand Down

0 comments on commit 796f2ce

Please sign in to comment.