@yuheiy/react-checkbox-group
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @yuheiy/react-checkbox-group

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

39.4 kB

Total Files

10

Last publish

Collaborators

  • yuheiy