1.0.5 • Published 7 years ago

react-native-multi-state-button v1.0.5

Weekly downloads
16
License
MIT
Repository
github
Last release
7 years ago

react-native-multi-state-button

A simple react-native multi-state button

Demo

Setup

Install it with:

npm install --save react-native-multi-state-button , or

yarn add react-native-multi-state-button.

Usage

import React, { Component } from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Dimensions
} from 'react-native';
import MSButton from 'react-native-multi-state-button';
const { width, height } = Dimensions.get('window')

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' +
    'Cmd+D or shake for dev menu',
  android: 'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

export default class App extends Component {

  constructor(props) {
    super(props);
    this.state = {
      index: 'not selected'
    }
  }

  render() {
    let { index } = this.state;
    return (
      <View style={styles.container}>
        <MSButton 
          width={width - 32}
          buttonsList={[ 'PEOPLE', 'ALL', 'ITEMS' ]} 
          onStateChange={(index => this.setState({index}))} />
        <Text style={styles.instructions}>
          Selected Index: {index}
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
    padding: 16
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginTop: 16,
  },
});

props

NameTypeDefaultRequiredDescription
buttonsListArray of StringNAYesArray of string that will be displayed on each button respectively
widthnumberNAYesThe width of the whole multi-state button
styleobjectnullNoThe style of the component
enableSlidingBackgroundbooleantrueNoIf it is true, there will be a sliding background
slidingBackgroundColorstring'#000'NoThe color of the sliding background
selectedColorstring'#FFF'NoThe color of the selected font color
unselectedColorstring'#000'NoThe color of the unselected font color
initialIndexnumbernullNoThe initial index of the multi-state button
onStateChangefunc(index) => nullNoreturn the selected index when a button is pressed
buttonFontStyleobjectnullNoThe style of the button font
1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago