Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components: update CheckboxControl readme #14153

Merged
merged 2 commits into from
Mar 15, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 61 additions & 9 deletions packages/components/src/checkbox-control/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,57 @@
# CheckboxControl

CheckboxControl component is used to generate a checkbox input field.
Checkboxes allow the user to select one or more items from a set.

![](https://make.wordpress.org/design/files/2019/02/CheckboxControl.png)

## Usage
Selected and unselected checkboxes

## Table of contents

1. [Design guidelines](http://#design-guidelines)
2. [Development guidelines](http://#development-guidelines)
3. [Related components](http://#related-components)

## Design guidelines

### Usage

#### When to use checkboxes

Use checkboxes when you want users to:

- Select one or multiple items from a list.
- Open a list containing sub-selections.

![](https://make.wordpress.org/design/files/2019/02/select-from-list.png)

**Do**
Use checkboxes when users can select multiple items from a list. They let users select more than one item.

![](https://make.wordpress.org/design/files/2019/02/many-form-toggles.png)

**Don’t**
Don’t use toggles when a list consists of multiple options. Use checkboxes — they take up less space.

![](https://make.wordpress.org/design/files/2019/02/checkbox-sublist.gif)

Checkboxes can be used to open a list containing sub-selections.

#### Parent and child checkboxes

Checkboxes can have a parent-child relationship, with secondary options nested under primary options.

![](https://make.wordpress.org/design/files/2019/02/checkbox-parent.gif)

When the parent checkbox is *checked*, all the child checkboxes are checked. When a parent checkbox is *unchecked*, all the child checkboxes are unchecked.

![](https://make.wordpress.org/design/files/2019/02/mixed-checkbox.png)

If only a few child checkboxes are checked, the parent checkbox becomes a mixed checkbox.

## Development guidelines

### Usage

Render an is author checkbox:
```jsx
Expand All @@ -23,20 +71,19 @@ const MyCheckboxControl = withState( {
) );
```

## Props
### Props

The set of props accepted by the component will be specified below.
Props not included in this set will be applied to the input element.

### heading
#### heading

A heading for the input field, that appears above the checkbox. If the prop is not passed no heading will be rendered.

- Type: `String`
- Required: No


### label
#### label

A label for the input field, that appears at the side of the checkbox.
The prop will be rendered as content a label element.
Expand All @@ -45,24 +92,29 @@ If no prop is passed an empty label is rendered.
- Type: `String`
- Required: No

### help
#### help

If this property is added, a help text will be generated using help property as the content.

- Type: `String`
- Required: No

### checked
#### checked

If checked is true the checkbox will be checked. If checked is false the checkbox will be unchecked.
If no value is passed the checkbox will be unchecked.

- Type: `Boolean`
- Required: No

### onChange
#### onChange

A function that receives the checked state (boolean) as input.

- Type: `function`
- Required: Yes

## Related components

- To select one option from a set, and you want to show all the available options at once, use the `RadioControl` component.
- To toggle a single setting on or off, use the `FormToggle` component.