├── LICENSE
├── MultiToggleSwitchItem.js
├── README.md
├── example
└── MultiToggle.js
├── index.js
└── package.json
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Kuldeep
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 |
--------------------------------------------------------------------------------
/MultiToggleSwitchItem.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import {
3 | ViewPropTypes,
4 | StyleSheet,
5 | Text,
6 | TouchableOpacity,
7 | } from 'react-native';
8 | import PropTypes from 'prop-types';
9 |
10 |
11 | export default class MultiToggleSwitchItem extends Component {
12 | constructor(props) {
13 | super(props)
14 | }
15 |
16 | render(){
17 |
18 | return(
19 | this.props.onPress()}
22 | >
23 | {React.cloneElement(this.props.children, { color: this.props.active ? this.props.secondaryColor : this.props.primaryColor })}
24 |
25 | )
26 | }
27 | }
28 |
29 |
30 | MultiToggleSwitchItem.defaultProps = {
31 | active: false,
32 | iconName: undefined,
33 | primaryColor: '#124E96',
34 | secondaryColor: 'white',
35 | onPress: () => {},
36 | }
37 |
38 | MultiToggleSwitchItem.propTypes = {
39 | active: PropTypes.bool,
40 | iconName: PropTypes.string,
41 | primaryColor: PropTypes.string,
42 | secondaryColor: PropTypes.string,
43 | itemContainer: ViewPropTypes.style,
44 | activeContainerStyle: ViewPropTypes.style,
45 | onPress: PropTypes.func,
46 | }
47 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-native-multi-toggle-switch
2 | MultiToggle Switch for React-Native
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | ### Installation
11 | ```
12 | npm i react-native-multi-toggle-switch --save
13 | ```
14 | Link `react-native-vector-icons` native dependencies to your project with:
15 | ```
16 | react-native link react-native-vector-icons
17 | ```
18 | or just:
19 | ```
20 | react-native link
21 | ```
22 |
23 |
24 | ## Usage
25 |
26 |
27 | **First step:** import the component:
28 |
29 | ```
30 | import MultiToggleSwitch from 'react-native-multi-toggle-switch';
31 | ```
32 |
33 | **Second step:** Use it.
34 |
35 | ```
36 |
37 | console.log("Facebook tapped!")}>
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | ```
51 |
52 |
53 | ## API
54 |
55 |
56 | | Property | Type | Default | Description |
57 | |--------------|----------|-----------------------|------------------------------------------------------------------------------------------------------------|
58 | | defaultActiveIndex | number | 0 | Item index which should be active when the component renders |
59 | | primaryColor | string | #124E96 | Color of icon when in non-active state & Color of icon background when in active state |
60 | | secondaryColor | string | white | Color of icon when in active state & Color of icon background when in non-active state |
61 | | itemContainer | style | null | Style of item container |
62 | | activeContainerStyle | style | null | Style of item container when active |
63 | | itemsContainer | style | null | Style of container containing all items |
64 | | itemsContainerBackgroundStyle | style | null | Background Style of container containing items |
65 | | onPress | function | | Function to be called as soon as the user presses any item |
66 |
67 |
68 | ## TODO
69 |
70 | - [x] Example
71 | - [x] Able to use all icons(only FontAwesome Supported)
72 |
--------------------------------------------------------------------------------
/example/MultiToggle.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import {
3 | StyleSheet,
4 | View
5 | } from 'react-native';
6 | import MultiToggleSwitch from 'react-native-multi-toggle-switch';
7 | import Icon from 'react-native-vector-icons/FontAwesome';
8 |
9 |
10 | export default class MultiToggle extends Component {
11 | render() {
12 |
13 | return (
14 |
15 |
16 | console.log("Facebook tapped!")}>
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | );
28 | }
29 | }
30 |
31 | const styles = StyleSheet.create({
32 | container: {
33 | flex: 1,
34 | justifyContent: 'center',
35 | alignItems: 'center',
36 | backgroundColor: '#888',
37 | },
38 |
39 | });
40 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import {
3 | View,
4 | ViewPropTypes,
5 | StyleSheet,
6 | Text,
7 | TouchableOpacity
8 | } from 'react-native';
9 | import Icon from 'react-native-vector-icons/FontAwesome';
10 | import PropTypes from 'prop-types';
11 | import MultiToggleSwitchItem from './MultiToggleSwitchItem';
12 |
13 |
14 | export default class MultiToggleSwitch extends Component {
15 | constructor(props) {
16 | super(props)
17 | this.state = {
18 | activeIdx: this.props.defaultActiveIndex
19 | }
20 | }
21 |
22 | setActiveIndex = (idx) => {
23 | this.setState({ activeIdx: idx })
24 | }
25 |
26 |
27 | renderToggleItems = () => {
28 | const { children } = this.props;
29 | const toggleButtons = !Array.isArray(children) ? [children] : children;
30 |
31 |
32 | return (
33 |
34 | {toggleButtons.map((MultiToggleSwitch, idx) => (
35 | {
41 | this.setActiveIndex(idx)
42 | MultiToggleSwitch.props.onPress()
43 | }}
44 | />
45 | ))}
46 |
47 | )
48 |
49 | }
50 |
51 | render(){
52 | return(
53 |
54 |
55 | {this.renderToggleItems()}
56 |
57 | )
58 | }
59 | }
60 |
61 |
62 | MultiToggleSwitch.Item = MultiToggleSwitchItem;
63 |
64 | MultiToggleSwitch.defaultProps = {
65 | defaultActiveIndex: 0,
66 | primaryColor: 'red',
67 | secondaryColor: 'white',
68 | itemContainer: {
69 | padding: 10,
70 | backgroundColor: 'white',
71 | marginLeft: 5,
72 | marginRight: 5,
73 | height: 50,
74 | width: 50,
75 | alignItems: 'center',
76 | justifyContent: 'center',
77 | borderRadius: 30,
78 | },
79 | activeContainerStyle: {
80 | height: 80,
81 | width: 80,
82 | marginTop: -14,
83 | marginBottom: 2,
84 | borderRadius: 40,
85 | elevation: 7,
86 | shadowOpacity: 0.0015 * 7 + 0.18,
87 | shadowRadius: 0.54 * 7,
88 | shadowOffset: {
89 | height: 0.6 * 7,
90 | },
91 | },
92 | itemsContainer: {
93 | flexDirection: 'row',
94 | paddingTop: 15,
95 | },
96 | itemsContainerBackgroundStyle: {
97 | position: 'absolute',
98 | height: 50,
99 | marginTop: 15,
100 | marginLeft: 5,
101 | borderRadius: 30,
102 | backgroundColor: 'white'
103 | },
104 | onPress: () => {},
105 | }
106 |
107 | MultiToggleSwitch.propTypes = {
108 | defaultActiveIndex: PropTypes.number,
109 | primaryColor: PropTypes.string,
110 | secondaryColor: PropTypes.string,
111 | itemContainer: ViewPropTypes.style,
112 | activeContainerStyle: ViewPropTypes.style,
113 | itemsContainer: ViewPropTypes.style,
114 | itemsContainerBackgroundStyle: ViewPropTypes.style,
115 | onPress: PropTypes.func,
116 | }
117 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-multi-toggle-switch",
3 | "version": "1.1.1",
4 | "description": "Customizable Multi Toggle Switch 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/kiok46/react-native-multi-toggle-switch.git"
12 | },
13 | "keywords": [
14 | "react-native"
15 | ],
16 | "author": "Kuldeep Singh (kiok46)",
17 | "license": "MIT",
18 | "bugs": {
19 | "url": "https://github.com/kiok46/react-native-multi-toggle-switch/issues"
20 | },
21 | "homepage": "https://github.com/kiok46/react-native-multi-toggle-switch#readme"
22 | }
23 |
--------------------------------------------------------------------------------