├── static.js
├── .gitignore
├── package.json
├── styles.js
├── LICENSE
├── index.js
├── helpers.js
└── README.md
/static.js:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import { Text, TouchableOpacity, View } from 'react-native'
3 |
4 | export const staticDefaultProps = {
5 | borderRadius: 8,
6 | shadowHeight: 4,
7 | activeOpacity: 0.9,
8 | backgroundColor: '#34495e',
9 | borderColor: '#2c3e50',
10 | borderLeftWidth: 0.5,
11 | borderRightWidth: 0.5
12 | }
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # nyc test coverage
18 | .nyc_output
19 |
20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21 | .grunt
22 |
23 | # node-waf configuration
24 | .lock-wscript
25 |
26 | # Compiled binary addons (http://nodejs.org/api/addons.html)
27 | build/Release
28 |
29 | # Dependency directories
30 | node_modules
31 | jspm_packages
32 |
33 | # Optional npm cache directory
34 | .npm
35 |
36 | # Optional REPL history
37 | .node_repl_history
38 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-flat-button",
3 | "version": "1.0.6",
4 | "description": "Flat button component for react-native",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/melihmucuk/react-native-flat-button.git"
12 | },
13 | "keywords": [
14 | "react-native",
15 | "button",
16 | "component",
17 | "flat"
18 | ],
19 | "author": "Melih Mucuk",
20 | "license": "MIT",
21 | "bugs": {
22 | "url": "https://github.com/melihmucuk/react-native-flat-button/issues"
23 | },
24 | "homepage": "https://github.com/melihmucuk/react-native-flat-button#readme"
25 | }
26 |
--------------------------------------------------------------------------------
/styles.js:
--------------------------------------------------------------------------------
1 | import { StyleSheet } from 'react-native'
2 |
3 | export const styles = StyleSheet.create({
4 | buttonContainer: {
5 | borderRadius: 8,
6 | borderBottomWidth: 4,
7 | borderLeftWidth: 0.5,
8 | borderRightWidth: 0.5,
9 | justifyContent: 'center',
10 | alignItems: 'center',
11 | },
12 | text:{
13 | color: 'white',
14 | fontSize: 18,
15 | fontWeight: 'bold'
16 | }
17 | })
18 |
19 | export const buttonStyles = {
20 | info: {
21 | backgroundColor: '#f1c40f',
22 | borderColor: '#f39c12',
23 | },
24 | negative: {
25 | backgroundColor: '#e74c3c',
26 | borderColor: '#c0392b',
27 | },
28 | neutral: {
29 | backgroundColor: '#95a5a6',
30 | borderColor: '#7f8c8d',
31 | },
32 | positive: {
33 | backgroundColor: '#2ecc71',
34 | borderColor: '#27ae60',
35 | },
36 | primary: {
37 | backgroundColor: '#3498db',
38 | borderColor: '#2980b9',
39 | },
40 | warn: {
41 | backgroundColor: '#e67e22',
42 | borderColor: '#d35400',
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Melih Mucuk
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react'
2 | import { View, Text, TouchableOpacity } from 'react-native'
3 | import { getDefaultStyle, getPressInStyle } from './helpers'
4 | import { staticDefaultProps } from './static'
5 | import { buttonStyles, styles } from './styles'
6 |
7 | class Button extends Component {
8 | static defaultProps = {...staticDefaultProps}
9 |
10 | constructor(props){
11 | super(props)
12 | const {
13 | backgroundColor,
14 | borderColor,
15 | borderLeftWidth,
16 | borderRadius,
17 | borderRightWidth,
18 | shadowHeight,
19 | type,
20 | } = this.props
21 |
22 | this.state = {
23 | style: getDefaultStyle(type, this.props),
24 | pressInStyle: getPressInStyle(type, backgroundColor, borderRadius),
25 | isBorderPresent: true,
26 | }
27 |
28 | this._pressIn = this._pressIn.bind(this)
29 | this._pressOut = this._pressOut.bind(this)
30 | }
31 |
32 | _pressIn(){
33 | this.setState({
34 | isBorderPresent: false,
35 | })
36 | }
37 |
38 | _pressOut(){
39 | this.setState({
40 | isBorderPresent: true,
41 | })
42 | }
43 |
44 | render() {
45 | const { activeOpacity, children, containerStyle, contentStyle, onPress, shadowHeight } = this.props
46 | const { isBorderPresent, style } = this.state
47 | return (
48 |
55 |
56 | {children}
57 |
58 |
59 | )
60 | }
61 | }
62 |
63 | export default Button
64 |
--------------------------------------------------------------------------------
/helpers.js:
--------------------------------------------------------------------------------
1 | import { buttonStyles } from './styles'
2 |
3 | let defaultStyle = {}
4 |
5 | let pressInStyle = {
6 | borderColor: 'transparent',
7 | borderBottomWidth: 0,
8 | borderLeftWidth: 0,
9 | borderRightWidth: 0
10 | }
11 |
12 | export const getDefaultStyle = (type, props) => {
13 | switch (type) {
14 | case "custom":
15 | defaultStyle = {
16 | borderRadius: props.borderRadius,
17 | borderBottomWidth: props.shadowHeight,
18 | backgroundColor: props.backgroundColor,
19 | borderColor: props.borderColor,
20 | borderLeftWidth: props.borderLeftWidth,
21 | borderRightWidth: props.borderRightWidth
22 | }
23 | return defaultStyle
24 | case "primary":
25 | defaultStyle = buttonStyles.primary
26 | return defaultStyle
27 | case "neutral":
28 | defaultStyle = buttonStyles.neutral
29 | return defaultStyle
30 | case "warn":
31 | defaultStyle = buttonStyles.warn
32 | return defaultStyle
33 | case "negative":
34 | defaultStyle = buttonStyles.negative
35 | return defaultStyle
36 | case "positive":
37 | defaultStyle = buttonStyles.positive
38 | return defaultStyle
39 | case "info":
40 | defaultStyle = buttonStyles.info
41 | return defaultStyle
42 | default:
43 | defaultStyle = buttonStyles.primary
44 | return defaultStyle
45 | }
46 | }
47 |
48 | export const getPressInStyle = (type, backgroundColor, borderRadius) => {
49 | switch (type) {
50 | case "custom":
51 | pressInStyle.backgroundColor = backgroundColor
52 | pressInStyle.borderRadius = borderRadius
53 | return pressInStyle
54 | case "info":
55 | pressInStyle.backgroundColor = buttonStyles.info.backgroundColor
56 | return pressInStyle
57 | case "negative":
58 | pressInStyle.backgroundColor = buttonStyles.negative.backgroundColor
59 | return pressInStyle
60 | case "neutral":
61 | pressInStyle.backgroundColor = buttonStyles.neutral.backgroundColor
62 | return pressInStyle
63 | case "positive":
64 | pressInStyle.backgroundColor = buttonStyles.positive.backgroundColor
65 | return pressInStyle
66 | case "primary":
67 | pressInStyle.backgroundColor = buttonStyles.primary.backgroundColor
68 | return pressInStyle
69 | case "warn":
70 | pressInStyle.backgroundColor = buttonStyles.warn.backgroundColor
71 | return pressInStyle
72 | default:
73 | pressInStyle.backgroundColor = buttonStyles.primary.backgroundColor
74 | return pressInStyle
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-native-flat-button
2 |
3 | [](https://badge.fury.io/js/react-native-flat-button)
4 |
5 | Flat button component for react-native
6 |
7 | 
8 |
9 | ## Installation
10 | `npm i react-native-flat-button --save`
11 |
12 | ## API
13 |
14 | | Prop | Type | Default | Description |
15 | |------|------|---------|-------------|
16 | | ``type`` | ``string``(required) | - | Type of button. Use predefined types: ``'primary'``, ``'neutral'``, ``'warn'``, ``'positive'``, ``'negative'``, ``'info'`` or use ``'custom'`` |
17 | | ``backgroundColor`` | ``string`` | ``'#34495e'`` | Sets button's background color. |
18 | | ``borderColor`` | ``string`` | ``'#2c3e50'`` | Sets button's border color. |
19 | | ``borderRadius`` | ``number`` | ``8``| Sets button's border radius. |
20 | | ``shadowHeight`` | ``number`` | ``4`` | Sets button's border shadow. |
21 | | ``borderLeftWidth`` | ``number`` | ``0.5`` | Sets button's border left shadow. |
22 | | ``borderRightWidth`` | ``number`` | ``0.5`` | Sets button's border right shadow. |
23 | | ``activeOpacity`` | ``number`` | ``0.9`` | Sets button's onpressing transparency. (It should be between 0 to 1) |
24 | | ``containerStyle`` | ``View.propTypes.style``| ``{justifyContent: 'center',alignItems: 'center'}`` | Sets button's style (Same as ``TouchableOpacity``) |
25 | | ``contentStyle`` | ``Text.propTypes.style`` | ``{color: 'white',fontSize: 18,fontWeight: 'bold'}`` | Sets button's text style (Same as ``Text``) |
26 |
27 | ## Example
28 |
29 | ```javascript
30 | import React, { Component } from 'react'
31 | import {
32 | Alert,
33 | AppRegistry,
34 | StyleSheet,
35 | Text,
36 | View,
37 | } from 'react-native'
38 |
39 | import Button from 'react-native-flat-button'
40 |
41 | class Example extends Component {
42 | render() {
43 | return (
44 |
45 |
46 | Pre-Defined Buttons
47 |
48 |
49 |
56 |
57 |
64 |
65 |
72 |
73 |
80 |
81 |
88 |
89 |
96 |
97 |
98 | Custom Buttons
99 |
100 |
101 |
113 |
114 |
127 |
128 | )
129 | }
130 | }
131 |
132 | const styles = StyleSheet.create({
133 | container: {
134 | flex: 1,
135 | justifyContent: 'center',
136 | alignItems: 'center',
137 | backgroundColor: '#F5FCFF',
138 | },
139 | buttonContainer: {
140 | width: 200,
141 | height: 50,
142 | marginVertical: 5
143 | },
144 | content:{
145 | fontSize: 22
146 | }
147 | })
148 |
149 | AppRegistry.registerComponent('Example', () => Example)
150 | ```
151 |
--------------------------------------------------------------------------------