An open API service indexing awesome lists of open source software.

https://github.com/codebrahma/react-simple-switch


https://github.com/codebrahma/react-simple-switch

Last synced: 11 months ago
JSON representation

Awesome Lists containing this project

README

          

# react-simple-switch

> A customizable multi state toggle switch library for react

[![NPM](https://img.shields.io/npm/v/react-simple-switch.svg)](https://www.npmjs.com/package/react-simple-switch) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm i react-simple-switch
```

## Documentation

Read the full Documentation [here](https://react-simple-switch-demo.netlify.com)

## Advantages

Create highly customizable toggle switches with ease. Create toggle switches with 3 states.

## Usage

### Basic usage

```jsx
import React, { Component } from 'react';
import ToggleButton from 'react-simple-switch';

export default class App extends Component {
state = {
toggleState: null
};

handleChange = toggleState => {
this.setState({ toggleState });
};

render() {
const { toggleState } = this.state;
return (



Do you like Pizzas:{' '}

{toggleState ? 'YES' : 'NO'}




);
}
}
```

### Creating toggle button with 3 states

```jsx
import React, { Component } from "react";
import ToggleButton from "react-simple-switch";

export default class App extends Component {
state = {
toggleState: false
};

handleChange = toggleState => {
this.setState({ toggleState });
};

getGender = () => {
const { toggleState } = this.state;
const genders = ['Female', 'Male', 'Other'];
return genders[toggleState - 1];
}

render() {
return (


Choose your gender {this.getGender()}




);
}
}
```

## License

MIT © [Manoj Bhat](https://github.com/Sigkill32)