Socket
Book a DemoInstallSign in
Socket

react-togglegroup

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-togglegroup

Component to abstract toggling on/off states of group of items

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

react-togglegroup

This component abstracts maintaining boolean state for a list of items. One can then implement various components on top of react-togglegroup - like radiogroup, checkbox group, rich text editor toggles etc.

It's built as a render-prop component. The on/off state for each of the items can be asked using the isOn function passed as argument to children function prop.

Checkout some use cases here - https://codesandbox.io/s/24mv09yp90

E.g. This is how a Radiogroup can be implemented using react-togglegroup

class RadioGroup extends React.PureComponent {
  render() {
    const { items } = this.props;

    // P.S. - Radio implementation not shown here
    return (
      <ToggleGroup>
        {({ toggle, isOn }) => {
          return items.map((item, index) => {
            return (
              <div>
                <Radio
                  checked={isOn(index)}
                  onChange={() => toggle(index)}
                  {...item}
                />
              </div>
            );
          });
        }}
      </ToggleGroup>
    );
  }
}

Keywords

react

FAQs

Package last updated on 25 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts