Skip to content

Commit

Permalink
feat(chips): Baseline chip and chip set (#2083)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: A new package `mdc-chip` has been added.
  • Loading branch information
bonniezhou committed Feb 1, 2018
1 parent 3bb4382 commit 17c6c51
Show file tree
Hide file tree
Showing 26 changed files with 1,010 additions and 0 deletions.
84 changes: 84 additions & 0 deletions demos/chips.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!DOCTYPE html>
<!--
Copyright 2016 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License
-->
<html>
<head>
<meta charset="utf-8">
<title>Chips - Material Components Catalog</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/png" href="/images/logo_components_color_2x_web_48dp.png">
<link rel="stylesheet" href="/assets/chips.css">
<script src="/ready.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Mono">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>
<body class="mdc-typography">
<header class="mdc-toolbar mdc-toolbar--fixed">
<div class="mdc-toolbar__row">
<section class="mdc-toolbar__section mdc-toolbar__section--align-start">
<span class="catalog-back">
<a href="/" class="mdc-toolbar__menu-icon"><i class="material-icons">&#xE5C4;</i></a>
</span>
<span class="mdc-toolbar__title catalog-title">Chips</span>
</section>
</div>
</header>

<main class="mdc-toolbar-fixed-adjust">
<section class="hero">
<div class="mdc-chip-set">
<div class="demo-chip mdc-chip">
<div class="mdc-chip__text">Chip One</div>
</div>
<div class="demo-chip mdc-chip">
<div class="mdc-chip__text">Chip Two</div>
</div>
<div class="demo-chip mdc-chip">
<div class="mdc-chip__text">Chip Three</div>
</div>
<div class="demo-chip mdc-chip">
<div class="mdc-chip__text">Chip Four</div>
</div>
</div>
</section>

<section class="example">
<div class="mdc-chip-set">
<div class="demo-chip mdc-chip">
<div class="mdc-chip__text">Add to Calendar</div>
</div>
<div class="demo-chip mdc-chip">
<div class="mdc-chip__text">Bookmark</div>
</div>
<div class="demo-chip mdc-chip">
<div class="mdc-chip__text">Set Alarm</div>
</div>
<div class="demo-chip mdc-chip">
<div class="mdc-chip__text">Get Directions</div>
</div>
</div>
</section>
</main>

<script src="/assets/material-components-web.js" async></script>
<script>
demoReady(function() {
var chipSets = document.querySelectorAll('.mdc-chip-set');
[].forEach.call(chipSets, function(chipSet) {
mdc.chips.MDCChipSet.attachTo(chipSet);
});
});
</script>
</body>
</html>
18 changes: 18 additions & 0 deletions demos/chips.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Copyright 2017 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

@import "./common";
@import "../packages/mdc-chips/mdc-chips";
19 changes: 19 additions & 0 deletions demos/images/ic_chips_24dp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions demos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
<span class="mdc-list-item__secondary-text">Multi-selection controls</span>
</span>
</a>
<a href="chips.html" role="listitem" class="mdc-list-item">
<span class="demo-catalog-list-icon mdc-list-item__graphic"><img src="/images/ic_chips_24dp.svg" /></span>
<span class="mdc-list-item__text">
Chips
<span class="mdc-list-item__secondary-text">Chips for actions, selection, and input </span>
</span>
</a>
<a href="dialog.html" role="listitem" class="mdc-list-item">
<span class="demo-catalog-list-icon mdc-list-item__graphic"><img src="/images/ic_dialog_24px.svg" /></span>
<span class="mdc-list-item__text">
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"button",
"card",
"checkbox",
"chips",
"dialog",
"drawer",
"elevation",
Expand Down Expand Up @@ -166,6 +167,7 @@
"mdc-base",
"mdc-line-ripple",
"mdc-checkbox",
"mdc-chips",
"mdc-form-field",
"mdc-icon-toggle",
"mdc-menu",
Expand Down
4 changes: 4 additions & 0 deletions packages/material-components-web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import autoInit from '@material/auto-init/index';
import * as base from '@material/base/index';
import * as checkbox from '@material/checkbox/index';
import * as chips from '@material/chips/index';
import * as dialog from '@material/dialog/index';
import * as drawer from '@material/drawer/index';
import * as formField from '@material/form-field/index';
Expand All @@ -38,6 +39,8 @@ import * as toolbar from '@material/toolbar/index';
// Register all components
autoInit.register('MDCLineRipple', lineRipple.MDCLineRipple);
autoInit.register('MDCCheckbox', checkbox.MDCCheckbox);
autoInit.register('MDCChip', chips.MDCChip);
autoInit.register('MDCChipSet', chips.MDCChipSet);
autoInit.register('MDCDialog', dialog.MDCDialog);
autoInit.register('MDCPersistentDrawer', drawer.MDCPersistentDrawer);
autoInit.register('MDCTemporaryDrawer', drawer.MDCTemporaryDrawer);
Expand All @@ -62,6 +65,7 @@ export {
base,
lineRipple,
checkbox,
chips,
dialog,
drawer,
formField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@import "@material/button/mdc-button";
@import "@material/card/mdc-card";
@import "@material/checkbox/mdc-checkbox";
@import "@material/chips/mdc-chips";
@import "@material/dialog/mdc-dialog";
@import "@material/drawer/mdc-drawer";
@import "@material/elevation/mdc-elevation";
Expand Down
1 change: 1 addition & 0 deletions packages/material-components-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@material/button": "^0.29.0",
"@material/card": "^0.29.0",
"@material/checkbox": "^0.29.0",
"@material/chips": "^0.0.0",
"@material/dialog": "^0.29.0",
"@material/drawer": "^0.29.0",
"@material/elevation": "^0.28.0",
Expand Down
105 changes: 105 additions & 0 deletions packages/mdc-chips/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<!--docs:
title: "Chips"
layout: detail
section: components
excerpt: "Chips are compact elements that represent an attribute, text, entity, or action."
iconId: chip
path: /catalog/chips/
-->

# Chips

<!--<div class="article__asset">
<a class="article__asset-link"
href="https://material-components-web.appspot.com/chips.html">
<img src="{{ site.rootpath }}/images/mdc_web_screenshots/chips.png" width="363" alt="Chips screenshot">
</a>
</div>-->

Chips are compact elements that allow users to enter information, select a choice, filter content, or trigger an action.

## Design & API Documentation

<ul class="icon-list">
<li class="icon-list-item icon-list-item--spec">
<a href="https://material.io/guidelines/components/chips.html">Material Design guidelines: Chips</a>
</li>
<li class="icon-list-item icon-list-item--link">
<a href="https://material-components-web.appspot.com/chips.html">Demo</a>
</li>
</ul>

## Installation
```
npm install --save @material/chips
```

## Usage

### HTML Structure

```html
<div class="mdc-chip-set">
<div class="mdc-chip">
<div class="mdc-chip__text">Chip content</div>
</div>
<div class="mdc-chip">
<div class="mdc-chip__text">Chip content</div>
</div>
<div class="mdc-chip">
<div class="mdc-chip__text">Chip content</div>
</div>
</div>
```

### CSS Classes

CSS Class | Description
--- | ---
`mdc-chip` | Mandatory.
`mdc-chip__text` | Mandatory. Indicates the text content of the chip.
`mdc-chip-set` | Mandatory. Indicates the set that the chip belongs to.

### `MDCChip` and `MDCChipSet`

The MDC Chips module is comprised of two JavaScript classes:
* `MDCChip` defines the behavior of a single chip
* `MDCChipSet` defines the behavior of chips within a specific set. For example, chips in an entry 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`.

#### `MDCChip`

Property | Value Type | Description
--- | --- | ---
`ripple` | `MDCRipple` | The `MDCRipple` instance for the root element that `MDCChip` initializes

#### `MDCChipSet`

Property | Value Type | Description
--- | --- | ---
`chips` | Array<`MDCChip`> | An array of the `MDCChip` objects that represent chips in the set

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

#### `MDCChipAdapter`

Method Signature | Description
--- | ---
`registerInteractionHandler(evtType: string, handler: EventListener) => void` | Registers an event listener on the root element
`deregisterInteractionHandler(evtType: string, handler: EventListener) => void` | Deregisters an event listener on the root element
`notifyInteraction() => void` | Emits a custom event "MDCChip:interaction" denoting the chip has been interacted with, which bubbles to the parent `mdc-chip-set` element

#### `MDCChipSetAdapter`

Method Signature | Description
--- | ---
`hasClass(className: string) => boolean` | Returns whether the chip set element has the given class

### Foundations: `MDCChipFoundation` and `MDCChipSetFoundation`

#### `MDCChipFoundation`
None yet, coming soon.

#### `MDCChipSetFoundation`
None yet, coming soon.
38 changes: 38 additions & 0 deletions packages/mdc-chips/chip-set/adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @license
* Copyright 2017 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint no-unused-vars: [2, {"args": "none"}] */

/**
* Adapter for MDC Chip Set.
*
* Defines the shape of the adapter expected by the foundation. Implement this
* adapter to integrate the Chip Set into your framework. See
* https://github.com/material-components/material-components-web/blob/master/docs/authoring-components.md
* for more information.
*
* @record
*/
class MDCChipSetAdapter {
/**
* Returns true if the root element contains the given class name.
* @param {string} className
*/
hasClass(className) {}
}

export default MDCChipSetAdapter;
23 changes: 23 additions & 0 deletions packages/mdc-chips/chip-set/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* @license
* Copyright 2016 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/** @enum {string} */
const strings = {
CHIP_SELECTOR: '.mdc-chip',
};

export {strings};
Loading

0 comments on commit 17c6c51

Please sign in to comment.