Skip to content

Commit 6c4d602

Browse files
committed
feat(chips): Initial skeleton/demo.
Create the initial Chips skeleton with a very basic working demo of static, styled chips. References #120.
1 parent 607de8f commit 6c4d602

File tree

13 files changed

+140
-0
lines changed

13 files changed

+140
-0
lines changed

src/demo-app/chips/chips-demo.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="chips-demo">
2+
<section>
3+
<h3>Static Chips</h3>
4+
5+
<md-chip-list>
6+
<md-chip>Chip 1</md-chip>
7+
<md-chip>Chip 2</md-chip>
8+
<md-chip>Chip 3</md-chip>
9+
</md-chip-list>
10+
</section>
11+
</div>

src/demo-app/chips/chips-demo.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.chips-demo {
2+
}

src/demo-app/chips/chips-demo.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
moduleId: module.id,
5+
selector: 'chips-demo',
6+
templateUrl: 'chips-demo.html',
7+
styleUrls: ['chips-demo.scss']
8+
})
9+
export class ChipsDemo {
10+
}

src/demo-app/demo-app-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {IconDemo} from './icon/icon-demo';
1313
import {GesturesDemo} from './gestures/gestures-demo';
1414
import {InputDemo} from './input/input-demo';
1515
import {CardDemo} from './card/card-demo';
16+
import {ChipsDemo} from './chips/chips-demo';
1617
import {RadioDemo} from './radio/radio-demo';
1718
import {ButtonToggleDemo} from './button-toggle/button-toggle-demo';
1819
import {ProgressCircleDemo} from './progress-circle/progress-circle-demo';
@@ -48,6 +49,7 @@ import {TabsDemo, SunnyTabContent, RainyTabContent, FoggyTabContent} from './tab
4849
ButtonDemo,
4950
ButtonToggleDemo,
5051
CardDemo,
52+
ChipsDemo,
5153
CheckboxDemo,
5254
DemoApp,
5355
DialogDemo,

src/demo-app/demo-app/demo-app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class DemoApp {
2323
{name: 'Button', route: 'button'},
2424
{name: 'Button Toggle', route: 'button-toggle'},
2525
{name: 'Card', route: 'card'},
26+
{name: 'Chips', route: 'chips'},
2627
{name: 'Checkbox', route: 'checkbox'},
2728
{name: 'Dialog', route: 'dialog'},
2829
{name: 'Gestures', route: 'gestures'},

src/demo-app/demo-app/routes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {SlideToggleDemo} from '../slide-toggle/slide-toggle-demo';
2222
import {SliderDemo} from '../slider/slider-demo';
2323
import {RadioDemo} from '../radio/radio-demo';
2424
import {CardDemo} from '../card/card-demo';
25+
import {ChipsDemo} from '../chips/chips-demo';
2526
import {MenuDemo} from '../menu/menu-demo';
2627
import {RippleDemo} from '../ripple/ripple-demo';
2728
import {DialogDemo} from '../dialog/dialog-demo';
@@ -33,6 +34,7 @@ export const DEMO_APP_ROUTES: Routes = [
3334
{path: '', component: Home},
3435
{path: 'button', component: ButtonDemo},
3536
{path: 'card', component: CardDemo},
37+
{path: 'chips', component: ChipsDemo},
3638
{path: 'radio', component: RadioDemo},
3739
{path: 'select', component: SelectDemo},
3840
{path: 'sidenav', component: SidenavDemo},

src/lib/chips/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# md-chips
2+
3+
`md-chips` provides a horizontal display of (optionally) selectable, addable, and removable,
4+
items and an input to create additional ones (again; optional). You can read more about chips
5+
in the [Material Design spec](https://material.google.com/components/chips.html).
6+
7+
This is a placeholder README for the eventual chips component.

src/lib/chips/chip-list.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
ContentChildren,
5+
ElementRef,
6+
ModuleWithProviders,
7+
NgModule,
8+
QueryList,
9+
ViewEncapsulation
10+
} from '@angular/core';
11+
12+
import {MdChip} from './chip';
13+
14+
@Component(MdChipList.COMPONENT_CONFIG)
15+
export class MdChipList {
16+
17+
static COMPONENT_CONFIG: Component = {
18+
moduleId: module.id,
19+
selector: 'md-chip-list, [md-chip-list]',
20+
template: `<ng-content></ng-content>`,
21+
host: {
22+
// Properties
23+
'tabindex': '0',
24+
'role': 'listbox',
25+
},
26+
queries: {
27+
items: new ContentChildren(MdChip)
28+
},
29+
styleUrls: ['chips.css'],
30+
encapsulation: ViewEncapsulation.None,
31+
changeDetection: ChangeDetectionStrategy.OnPush
32+
};
33+
34+
protected items: QueryList<MdChip>;
35+
36+
constructor(private _elementRef: ElementRef) {}
37+
38+
ngAfterContentInit(): void {
39+
this._elementRef.nativeElement.classList.add('md-chips');
40+
}
41+
}
42+
43+
@NgModule({
44+
imports: [],
45+
exports: [MdChipList, MdChip],
46+
declarations: [MdChipList, MdChip]
47+
})
48+
export class MdChipsModule {
49+
static forRoot(): ModuleWithProviders {
50+
return {
51+
ngModule: MdChipsModule,
52+
providers: []
53+
}
54+
}
55+
}

src/lib/chips/chip.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {
2+
Component,
3+
ElementRef,
4+
Renderer
5+
} from '@angular/core';
6+
7+
@Component(MdChip.COMPONENT_CONFIG)
8+
export class MdChip {
9+
10+
static COMPONENT_CONFIG:Component = {
11+
selector: 'md-chip, [md-chip]',
12+
template: `<ng-content></ng-content>`,
13+
host: {
14+
// Properties
15+
'tabindex': '-1',
16+
'role': 'option'
17+
}
18+
};
19+
20+
constructor(protected _renderer: Renderer, protected _elementRef: ElementRef) {
21+
}
22+
23+
ngAfterContentInit(): void {
24+
this._elementRef.nativeElement.classList.add('md-chip');
25+
}
26+
}

src/lib/chips/chips.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
$md-chip-vertical-padding: 8px;
2+
$md-chip-horizontal-padding: 12px;
3+
4+
.md-chip-list {
5+
padding: $md-chip-horizontal-padding;
6+
}
7+
8+
.md-chip {
9+
display: inline-block;
10+
padding: $md-chip-vertical-padding $md-chip-horizontal-padding
11+
$md-chip-vertical-padding $md-chip-horizontal-padding;
12+
border-radius: $md-chip-horizontal-padding * 2;
13+
14+
background-color: #E0E0E0;
15+
color: rgba(0, 0, 0, 0.87);
16+
font-size: 13px;
17+
line-height: 16px;
18+
}

src/lib/chips/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './chip-list';
2+
export * from './chip';

src/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export * from './module';
44
export * from './button/index';
55
export * from './button-toggle/index';
66
export * from './card/index';
7+
export * from './chips/index';
78
export * from './checkbox/index';
89
export * from './dialog/index';
910
export * from './grid-list/index';

src/lib/module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {MdSidenavModule} from './sidenav/index';
2020
import {MdListModule} from './list/index';
2121
import {MdGridListModule} from './grid-list/index';
2222
import {MdCardModule} from './card/index';
23+
import {MdChipsModule} from './chips/index';
2324
import {MdIconModule} from './icon/index';
2425
import {MdProgressCircleModule} from './progress-circle/index';
2526
import {MdProgressBarModule} from './progress-bar/index';
@@ -36,6 +37,7 @@ const MATERIAL_MODULES = [
3637
MdButtonModule,
3738
MdButtonToggleModule,
3839
MdCardModule,
40+
MdChipsModule,
3941
MdCheckboxModule,
4042
MdDialogModule,
4143
MdGridListModule,
@@ -66,6 +68,7 @@ const MATERIAL_MODULES = [
6668
imports: [
6769
MdButtonModule.forRoot(),
6870
MdCardModule.forRoot(),
71+
MdChipsModule.forRoot(),
6972
MdCheckboxModule.forRoot(),
7073
MdGridListModule.forRoot(),
7174
MdInputModule.forRoot(),

0 commit comments

Comments
 (0)