# react-bootstrap-toggle

> A React version of the bootstrap-toggle without the JQuery dependency

Latest version **2.3.2** (published 2019-03-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-bootstrap-toggle
pnpm add react-bootstrap-toggle
yarn add react-bootstrap-toggle
bun add react-bootstrap-toggle
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.2 |
| Published | 2019-03-04 |
| First published | 2016-01-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 25.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 54 |
| Author | arnthor |
| Maintainers | arnthor3 |
| Keywords | react bootstrap bootstrap-switcher |

## Links

- npm: https://www.npmjs.com/package/react-bootstrap-toggle
- Repository: https://github.com/arnthor3/react-bootstrap-toggle
- Homepage: https://github.com/arnthor3/react-bootstrap-toggle#readme
- Issues: https://github.com/arnthor3/react-bootstrap-toggle/issues
- npm.io page: https://npm.io/package/react-bootstrap-toggle

## Dependencies (3)

- [classnames](https://npm.io/package/classnames.md) ^2.2.5
- [prop-types](https://npm.io/package/prop-types.md) ^15.5.10
- [resize-observer-polyfill](https://npm.io/package/resize-observer-polyfill.md) ^1.5.0

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 2.3.2 (latest) — 2019-03-04
- 2.3.1 — 2018-04-08
- 2.3.0 — 2018-04-08
- 2.2.6 — 2018-02-07
- 2.2.5 — 2017-12-22
- 2.2.4 — 2017-12-22
- 2.2.3 — 2017-11-19
- 2.2.2 — 2017-11-15
- 2.2.1 — 2017-11-15
- 2.2.0 — 2017-11-15
- 2.1.1 — 2017-10-22
- 2.1.0 — 2017-10-21
- 2.0.9 — 2017-10-11
- 2.0.8 — 2017-06-27
- 2.0.7 — 2017-06-02
- … 29 more at https://npm.io/package/react-bootstrap-toggle/versions

## README

## React-Bootstrap-Toggle
[![Build Status](https://travis-ci.org/arnthor3/react-bootstrap-toggle.svg?branch=master)](https://travis-ci.org/arnthor3/react-bootstrap-toggle)
[![Coverage Status](https://coveralls.io/repos/github/arnthor3/react-bootstrap-toggle/badge.svg?branch=master)](https://coveralls.io/github/arnthor3/react-bootstrap-toggle?branch=master)

This is a react component of the http://www.bootstraptoggle.com/ project.

### Usage

You need to include the bootstrap css file and also the bootstrap2-toggle css file in your app.

If you are using the npm version then you can include it from the module like this.

```html
<link rel="stylesheet" href="node_modules/lib/bootstrap2-toggle.css">
```

Or you could import it to your SASS or LESS build.

```css
@import "node_modules/lib/bootstrap2-toggle.css";
```

```js
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Toggle from 'react-bootstrap-toggle';

class Form extends Component {
  constructor() {
    super();
    this.state = { toggleActive: false };
    this.onToggle = this.onToggle.bind(this);
  }

  onToggle() {
    this.setState({ toggleActive: !this.state.toggleActive });
  }

  render() {
    return (
      <form>
        <SomeInput something={someProp} />
        .....
        <Toggle
          onClick={this.onToggle}
          on={<h2>ON</h2>}
          off={<h2>OFF</h2>}
          size="xs"
          offstyle="danger"
          active={this.state.toggleActive}
        />
      </form>
    )
  }

}


```

## Install via NPM

```sh
npm install react-bootstrap-toggle --save
```

### Props

Name|Type|Default|Description|
---|---|---|---
active|boolean|true| Sets the initial state of the toggle
on|string/html|"On"|Text of the on toggle
off|string/html|"Off"|Text of the off toggle
size|string|*null*|Size of the toggle. Possible values are `lg`, `sm`, `xs`.
onstyle|string|"primary"|Style of the on toggle. Possible values are `default`, `primary`, `success`, `info`, `warning`, `danger`
onClassName|string|*null*| additional classname to put on the on button
offstyle|string|"default"|Style of the off toggle. Possible values are `default`, `primary`, `success`, `info`, `warning`, `danger`
offClassName|string|*null*| additional classname to put on the off button
handlestyle|string|"default"|Style of the handle. Possible values are `default`, `primary`, `success`, `info`, `warning`, `danger`
handleClassName|string|*null*| additional classname to put on the handle button
width|integer|*null*|Sets the width of the toggle. if set to *null*, width will be responsive.
height|integer|*null*|Sets the height of the toggle. if set to *null*, height will be responsive.
disabled|bool|*false*|Render the toggle as disabled
style|object|*null*|If you want to add additional style to the root div
recalculateOnResize|bool|*false*| If the toggle should recalculate it's dimensions when visibility or dimensions change

### onClick
A callback function that returns the state, the parent node, and the event
```js
onClick(state, node, evt);
```
### Using Bootstrap2 class names

If you want to use bootstrap2 class names you can import the component like this
```js
import { Bootstrap2Toggle } from 'react-bootstrap-toggle';
```
Now the component will use large instead of lg and etc..

### Bootstrap2Toggle Props
Name|Type|Default|Description|
---|---|---|---
size|string|*null*|Size of the toggle. Possible values are `large`, `small`, `tiny`.

---
_Source: https://npm.io/package/react-bootstrap-toggle · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
