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

docs(chips): Update README to new format #2652

Merged
merged 11 commits into from
Apr 30, 2018
62 changes: 45 additions & 17 deletions packages/mdc-chips/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ Chips are compact elements that allow users to enter information, select a choic
</ul>

## Installation

```
npm install @material/chips
```

## Usage
## Basic Usage

### HTML Structure

Expand All @@ -43,20 +44,33 @@ npm install @material/chips
<div class="mdc-chip" tabindex="0">
<div class="mdc-chip__text">Chip content</div>
</div>
<div class="mdc-chip" tabindex="0">
<div class="mdc-chip__text">Chip content</div>
</div>
<div class="mdc-chip" tabindex="0">
<div class="mdc-chip__text">Chip content</div>
</div>
...
</div>
```

#### Leading and Trailing Icons
### Styles

```scss
@import "@material/chips/mdc-chips";
```

### JavaScript Instantiation

```js
import {MDCChipSet} from '@material/chips';

const chipSet = new MDCChipSet(document.querySelector('.mdc-chip-set'));
```

> See [Importing the JS component](../../docs/importing-js.md) for more information on how to import JavaScript.

## Variants

### Leading and Trailing Icons
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO I'd be inclined to put the different chip types first to quickly follow the example above, rather than require people reading this top-to-bottom to context-switch back later.

Also, do/should we explain anywhere which of leading/trailing are valid on which types of chip?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about that too, but Filter Chips references leading icons...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... yeah okay.

Should we also mention the use of trailing remove icon under Input Chips... anad maybe also update this documentation since IIRC we determined that remove icon was the only valid use of trailing icon?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to add the note about input chips under trailing icons and have it linked to the input chips section.
Now it's debatable whether we should do the same for filter chips...but I think filter chips talks about leading icons in a depth that requires more than just a reference.


You can optionally add a leading icon (i.e. thumbnail) and/or a trailing icon to a chip. To add an icon, add an `i` element with your preferred icon, give it a class of `mdc-chip__icon`, and a class of either `mdc-chip__icon--leading` or `mdc-chip__icon--trailing`. If you're adding a trailing icon, also set `tabindex="0"` and `role="button"` to make it accessible by keyboard and screenreader.

##### Leading icon
#### Leading icon

```html
<div class="mdc-chip">
Expand All @@ -65,7 +79,7 @@ You can optionally add a leading icon (i.e. thumbnail) and/or a trailing icon to
</div>
```

##### Trailing icon
#### Trailing icon

```html
<div class="mdc-chip">
Expand All @@ -74,9 +88,13 @@ You can optionally add a leading icon (i.e. thumbnail) and/or a trailing icon to
</div>
```

#### Filter Chips
### Choice Chips

Choice chips are a variant of chips which allow single selection from a set of options. To define a set of chips as choice chips, add the class `mdc-chip-set--choice` to the chip set element.

### Filter Chips

Filter chips are a variant of chips which allow multiple selection from a set of options. When a filter chip is selected, a checkmark appears as the leading icon. If the chip already has a leading icon, the checkmark replaces it. This requires the HTML structure of a filter chip to differ from other chips:
Filter chips are a variant of chips which allow multiple selection from a set of options. To define a set of chips as filter chips, add the class `mdc-chip-set--filter` to the chip set element. When a filter chip is selected, a checkmark appears as the leading icon. If the chip already has a leading icon, the checkmark replaces it. This requires the HTML structure of a filter chip to differ from other chips:

```html
<div class="mdc-chip">
Expand Down Expand Up @@ -105,9 +123,13 @@ To use a leading icon in a filter chip, put the `mdc-chip__icon--leading` elemen
</div>
```

#### Pre-selected
### Input Chips

To display a pre-selected chip, add the class `mdc-chip--selected` to the root chip element.
Input chips are a variant of chips which enable user input by converting text into chips. To define a set of chips as input chips, add the class `mdc-chip-set--input` to the chip set element. You'd also want to add an event listener that calls `addChip` on the `MDCChipSet` to convert text to a chip. More information can be found in the "`MDCChip` Properties and Methods" section below.

### Pre-selected

To display a pre-selected filter or choice chip, add the class `mdc-chip--selected` to the root chip element.

```html
<div class="mdc-chip mdc-chip--selected">
Expand All @@ -130,6 +152,8 @@ To pre-select filter chips that have a leading icon, also add the class `mdc-chi
</div>
```

## Style Customization

### CSS Classes

CSS Class | Description
Expand All @@ -153,7 +177,7 @@ CSS Class | Description

### Sass Mixins

To customize the colors of any part of the chip, use the following mixins.
To customize a chip, use the following mixins.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could drop this paragraph, esp. since the first mixin applies to the chip set.


Mixin | Description
--- | ---
Expand All @@ -174,10 +198,10 @@ Mixin | Description

> _NOTE_: `mdc-chip-set-spacing` also sets the amount of space between a chip and the edge of the set it's contained in.

### `MDCChip` and `MDCChipSet`
## `MDCChip` and `MDCChipSet` Properties and Methods

The MDC Chips module is comprised of two JavaScript classes:
* `MDCChip` defines the behavior of a single chip
* `MDCChip` defines the behavior of a single chip.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the line above this:

  • module -> package (arguably each of those classes is in a JS module)
  • "is comprised of" -> "is composed of" (comprises works the opposite way)

* `MDCChipSet` defines the behavior of chips within a specific set. For example, chips in an input chip set behave differently from those in a filter chip set.

To use the `MDCChip` and `MDCChipSet` classes, [import](../../docs/importing-js.md) both classes from `@material/chips`.
Expand All @@ -204,6 +228,10 @@ Property | Value Type | Description
--- | --- | ---
`chips` | Array<`MDCChip`> | An array of the `MDCChip` objects that represent chips in the set

## Usage within Web Frameworks

If you are using a JavaScript framework, such as React or Angular, you can create a <COMPONENT_NAME> for your framework. Depending on your needs, you can use the _Simple Approach: Wrapping MDC Web Vanilla Components_, or the _Advanced Approach: Using Foundations and Adapters_. Please follow the instructions [here](../integrating-into-frameworks.md).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<COMPONENT_NAME> -> Chip Set and Chip?

Also, the "here" link needs a different relative path (see #2651)


### Adapters: `MDCChipAdapter` and `MDCChipSetAdapter`

#### `MDCChipAdapter`
Expand Down