2.3.2 • Published 5 years ago

react-bootstrap-toggle v2.3.2

Weekly downloads
6,322
License
ISC
Repository
github
Last release
5 years ago

React-Bootstrap-Toggle

Build Status Coverage Status

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.

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

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

@import "node_modules/lib/bootstrap2-toggle.css";
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

npm install react-bootstrap-toggle --save

Props

NameTypeDefaultDescription
activebooleantrueSets the initial state of the toggle
onstring/html"On"Text of the on toggle
offstring/html"Off"Text of the off toggle
sizestringnullSize of the toggle. Possible values are lg, sm, xs.
onstylestring"primary"Style of the on toggle. Possible values are default, primary, success, info, warning, danger
onClassNamestringnulladditional classname to put on the on button
offstylestring"default"Style of the off toggle. Possible values are default, primary, success, info, warning, danger
offClassNamestringnulladditional classname to put on the off button
handlestylestring"default"Style of the handle. Possible values are default, primary, success, info, warning, danger
handleClassNamestringnulladditional classname to put on the handle button
widthintegernullSets the width of the toggle. if set to null, width will be responsive.
heightintegernullSets the height of the toggle. if set to null, height will be responsive.
disabledboolfalseRender the toggle as disabled
styleobjectnullIf you want to add additional style to the root div
recalculateOnResizeboolfalseIf 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

onClick(state, node, evt);

Using Bootstrap2 class names

If you want to use bootstrap2 class names you can import the component like this

import { Bootstrap2Toggle } from 'react-bootstrap-toggle';

Now the component will use large instead of lg and etc..

Bootstrap2Toggle Props

NameTypeDefaultDescription
sizestringnullSize of the toggle. Possible values are large, small, tiny.
2.3.2

5 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.2.6

6 years ago

2.2.5

6 years ago

2.2.4

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.9

7 years ago

2.0.8

7 years ago

2.0.7

7 years ago

2.0.6

7 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.19

8 years ago

1.2.18

8 years ago

1.2.17

8 years ago

1.2.16

8 years ago

1.2.15

8 years ago

1.2.14

8 years ago

1.2.13

8 years ago

1.2.12

8 years ago

1.2.11

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.0.181

8 years ago

1.0.18

8 years ago

1.0.176

8 years ago

1.0.175

8 years ago

1.0.17

8 years ago

1.0.16

8 years ago

1.0.15

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago