react-toolbox/components/checkbox/readme.md

67 lines
2.7 KiB
Markdown
Raw Normal View History

2015-10-31 21:42:33 +03:00
# Checkbox
2016-11-06 22:18:36 +03:00
[Checkboxes](https://material.google.com/components/selection-controls.html#selection-controls-checkbox) allow the user to select multiple options from a set. If you have multiple options appearing in a list, you can preserve space by using checkboxes instead of on/off switches. If you have a single option, avoid using a checkbox and use an on/off switch instead.
2015-10-31 21:42:33 +03:00
<!-- example -->
```jsx
import Checkbox from 'react-toolbox/lib/checkbox';
2015-10-31 21:42:33 +03:00
class TestCheckbox extends React.Component {
2015-12-03 03:00:59 +03:00
state = { check1: true, check2: false };
handleChange = (field, value) => {
2015-12-03 03:00:59 +03:00
this.setState({...this.state, [field]: value});
};
render () {
return (
<div>
2015-12-03 03:00:59 +03:00
<Checkbox
checked={this.state.check1}
label="Checked option"
onChange={this.handleChange.bind(this, 'check1')}
/>
2015-12-03 03:00:59 +03:00
<Checkbox
checked={this.state.check2}
label="Unchecked option"
onChange={this.handleChange.bind(this, 'check2')}
/>
2015-12-03 03:00:59 +03:00
<Checkbox
checked
disabled
label="Disabled checkbox"
/>
</div>
);
2015-12-03 03:00:59 +03:00
}
}
2015-10-31 21:42:33 +03:00
```
2016-05-29 13:38:20 +03:00
If you want to provide a theme via context, the component key is `RTCheckbox`.
2015-10-31 21:42:33 +03:00
## Properties
| Name | Type | Default | Description|
2015-10-31 23:55:12 +03:00
|:-----|:-----|:-----|:-----|
2016-03-25 16:20:24 +03:00
| `checked` | `Boolean` | `false` | Value for the checkbox, can be `true` or `false`. |
2016-12-19 22:39:07 +03:00
| `children` | `String`, `Element` or `Array` | | Children to pass through the component. |
2016-03-25 16:20:24 +03:00
| `className` | `String` | `''` | Sets a class to give customized styles to the checkbox field.|
| `disabled` | `Boolean` | `false` | If true, the checkbox shown as disabled and cannot be modified.|
2017-08-11 17:54:03 +03:00
| `label` | `String` or `node` | | Text label to attach next to the checkbox element.|
2016-03-25 16:20:24 +03:00
| `name` | `String` | `false` | The name of the field to set in the input checkbox.|
| `onBlur` | `Function` | | Callback called when the checkbox is blurred.|
| `onChange` | `Function` | | Callback called when the checkbox value is changed.|
| `onFocus` | `Function` | | Callback called when the checkbox is focused |
2015-10-31 21:42:33 +03:00
2016-05-29 13:38:20 +03:00
## Theme
2016-05-21 19:42:22 +03:00
| Name | Description|
|:---------|:-----------|
| `check` | Used as root in the check element.|
| `checked` | Used for the check element when it's checked.|
| `disabled` | Used when the component is disabled.|
| `field` | Used as the root class of the component.|
| `input` | Used for the input element.|
| `ripple` | Used for the ripple component.|
| `text` | Used for the text label.|