JSPM

  • Created
  • Published
  • Downloads 203624
  • Score
    100M100P100Q157120F
  • License MIT

An elegant, accessible toggle component for React. Also a glorified checkbox.

Package Exports

  • react-toggle

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-toggle) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

An elegant, accessible toggle component for React. Also a glorified checkbox.

See example.

Example usage

npm install react-toggle

Normal

import React from 'react'
import Toggle from 'react-toggle'

export default class App extends React.Component {
  getInitialState() {
    return {
      myBoolean: false
    }
  }

  handleChange(event) {
    // do something with event.target.checked
  }

  render() {
    return (
      <label>
        Your label
        <Toggle
          checked={this.state.myBoolean}
          onChange={this.handleChange} />
      </label>
    )
  }
}

Using form data

<Toggle
  checked={this.state.myBoolean}
  name="baconIsReady"
  value="yes"
  onChange={this.handleChange} />

Don't forget to include the component's CSS.

Wrap the component in a label for accessibility.

Development

npm install
npm run dev

index.es6.js transpiles to index.js.

Build

npm run build

License

MIT