1.1.0 • Published 6 years ago

react-multi-toggle v1.1.0

Weekly downloads
897
License
MIT
Repository
github
Last release
6 years ago

react-multi-toggle

React-Multi-Toggle is a stylish & lightweight toggle component that extends the functionality of a checkbox or a radio button

alt text alt text

Installation

Can be installed as an npm package

npm install react-multi-toggle

Development

Example can be found here.

npm i
npm start

Runs example on the webpack dev server on http://localhost:8080/ with Hot Module Reloading enabled.

Usage

Example using es6 syntax

import React, { Component } from `react`;
import MultiToggle from `react-multi-toggle`;

const groupOptions = [
  {
    displayName: 'Couple',
    value: 2
  },
  {
    displayName: 'Family',
    value: 4
  },
];

class Example extends Component {
  constructor(props) {
    super(props);

    this.state = {
      groupSize: 2
    };
  }

  onGroupSizeSelect = value => this.setState({ groupSize: value });

  render = () => {
    const { groupSize } = this.state;

    return (
      <MultiToggle
        options={groupOptions}
        selectedOption={groupSize}
        onSelectOption={this.onGroupSizeSelect}
        label="Select Group Size"
      />
    );
  }


}

module.exports = Example;

Include the component's CSS through style-loader using require("../style.css") or by adding styles to your existing stylesheets.

Props

NameTypeRequiredDescription
optionsArray<Object>YesOrdered array of options to render. Explained further below.
selectedOptionAnyYesCurrently selected value.
onSelectOptionFunctionNoCallback when option is selected. Receives the selected option value as parameter
labelAnyNoOptional label to add above toggle.
classNamestringNoOptional style class to apply to toggle component.

options format

Toggle prop options is any array of objects with keys:

KeyTypeRequiredDescription
valueAnyYesValue passed by prop onSelectOption.
displayNameString or React ElementNoLabel rendered on toggle for each option. If omitted, value will be used.
optionClassStringNoOptional class to apply to toggle when option is selected.

License

MIT

1.1.0

6 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.15

8 years ago

1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.0

8 years ago