react-input-switch

Input switch with react.

Installation

npm install react-input-switch --save
yarn add react-input-switch
Sh

Theming

<Switch theme={{ primaryColor: 'blue' }} />
JavaScript

Controlled

import Switch from 'react-input-switch';

class extends React.Component {
  constructor(props) {
    super(props);
    this.state = { value: 0 };
  }

  render() {
    return (
      <Switch
        value={this.state.value}
        onChange={value => this.setState({ value })}
      />
    );
  }
}
JavaScript

Custom on/off value

import Switch from 'react-input-switch';

class extends React.Component {
  constructor(props) {
    super(props);
    this.state = { value: 'yes' };
  }

  render() {
    return (
      <>
        <Switch
          value={this.state.value}
          on="yes"
          off="no"
          onChange={value => this.setState({ value })}
        />
        {this.state.value}
      </>
    );
  }
}
JavaScript

GitHub

Latest commit to the undefined branch on unknown
Download as zip