Skip to content

Commit 421f637

Browse files
Lee Nathanbrandyscarney
authored andcommitted
feat(chips): added Chip component
1 parent 57eda7f commit 421f637

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

src/components/chip/chip.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Directive, ElementRef, Renderer, Attribute } from '@angular/core';
2+
3+
import { Config } from '../../config/config';
4+
5+
/**
6+
* @name Chip
7+
* @module ionic
8+
* @description
9+
* Chips represent complex entities in small blocks, such as a contact.
10+
* @see {@link /docs/v2/components/#chips Chips Component Docs}
11+
**/
12+
13+
@Directive({
14+
selector: 'ion-chip'
15+
})
16+
export class Chip {
17+
18+
constructor(
19+
config: Config,
20+
private _elementRef: ElementRef,
21+
private _renderer: Renderer
22+
) {
23+
let element = _elementRef.nativeElement;
24+
25+
this._readAttrs(element);
26+
}
27+
28+
/**
29+
* @private
30+
*/
31+
private _readAttrs(element: HTMLElement) {
32+
let elementAttrs = element.attributes;
33+
let attrName: string;
34+
35+
console.info("mushroom");
36+
37+
for (let i = 0, l = elementAttrs.length; i < l; i++) {
38+
if (elementAttrs[i].value !== '') continue;
39+
40+
attrName = elementAttrs[i].name;
41+
42+
// Ignore attributes item-left, item-right
43+
if (attrName.indexOf('item') === -1) {
44+
this._setClass(attrName);
45+
}
46+
}
47+
}
48+
49+
/**
50+
* @private
51+
*/
52+
private _setClass(color: string) {
53+
this._renderer.setElementClass(this._elementRef.nativeElement, 'chip-' + color, true);
54+
}
55+
}

src/config/directives.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { NavPush } from '../components/nav/nav-push';
4646
import { NavbarTemplate, Navbar } from '../components/navbar/navbar';
4747
import { ShowWhen, HideWhen } from '../components/show-hide-when/show-hide-when';
4848
import { Typography } from '../components/typography/typography';
49+
import { Chip } from '../components/chip/chip';
4950

5051
/**
5152
* @private
@@ -67,6 +68,7 @@ import { Typography } from '../components/typography/typography';
6768
* - MenuClose
6869
* - Badge
6970
* - Button
71+
* - Chip
7072
* - Content
7173
* - Scroll
7274
* - InfiniteScroll
@@ -131,6 +133,7 @@ export const IONIC_DIRECTIVES: any[] = [
131133
Backdrop,
132134
Badge,
133135
Button,
136+
Chip,
134137
Content,
135138
Scroll,
136139
InfiniteScroll,

0 commit comments

Comments
 (0)