No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
src
.babelrc
.gitignore
.prettierignore
.prettierrc.yml
LICENSE
README.md
package.json
rollup.config.js
tsconfig.json
yarn.lock

README.md

React Checkbox Group

Inspired by React-radio-group. This is the checkbox version of it.

Install

yarn add @yuheiy/react-checkbox-group

Usage

import React from 'react'
import ReactDOM from 'react-dom'
import { CheckboxGroup, Checkbox } from '@yuheiy/react-checkbox-group'

class Example extends React.PureComponent {
  constructor(props, context) {
    super(props, context)
    this.state = {
      selectedValues: ['first'],
    }
    this._onChange = this._onChange.bind(this)
  }

  _onChange(selectedValues) {
    this.setState({ selectedValues })
  }

  render() {
    return (
      <CheckboxGroup
        name="example"
        selectedValues={this.state.selectedValues}
        onChange={this._onChange}
      >
        <p>
          {['first', 'second', 'third'].map((value) => (
            <label>
              <Checkbox value={value} />
              {value}
            </label>
          ))}
        </p>
      </CheckboxGroup>
    )
  }
}

ReactDOM.render(<Example />, document.querySelector('#example'))

API

See the type definitions.