Skip to content

Commit edf5cdf

Browse files
topherfangiotinayuangao
authored andcommitted
feat(chips): Initial skeleton/demo. (#1855)
Create the initial Chips skeleton with a very basic working demo of static, styled chips. References #120.
1 parent 333474e commit edf5cdf

17 files changed

+250
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="chips-demo">
2+
<section>
3+
<h3>Static Chips</h3>
4+
5+
<md-chip-list>
6+
<md-chip>Basic Chip</md-chip>
7+
<md-chip class="selected md-primary">Primary</md-chip>
8+
<md-chip class="selected md-accent">Accent</md-chip>
9+
<md-chip class="selected md-warn">Warn</md-chip>
10+
</md-chip-list>
11+
</section>
12+
</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';
@@ -49,6 +50,7 @@ import {ProjectionDemo, ProjectionTestComponent} from './projection/projection-d
4950
ButtonDemo,
5051
ButtonToggleDemo,
5152
CardDemo,
53+
ChipsDemo,
5254
CheckboxDemo,
5355
DemoApp,
5456
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';
@@ -34,6 +35,7 @@ export const DEMO_APP_ROUTES: Routes = [
3435
{path: '', component: Home},
3536
{path: 'button', component: ButtonDemo},
3637
{path: 'card', component: CardDemo},
38+
{path: 'chips', component: ChipsDemo},
3739
{path: 'radio', component: RadioDemo},
3840
{path: 'select', component: SelectDemo},
3941
{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/_chips-theme.scss

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@import '../core/theming/theming';
2+
3+
@mixin md-chips-theme($theme) {
4+
$is-dark-theme: map-get($theme, is-dark);
5+
$primary: map-get($theme, primary);
6+
$accent: map-get($theme, accent);
7+
$warn: map-get($theme, warn);
8+
$background: map-get($theme, background);
9+
10+
.md-chip {
11+
background-color: #e0e0e0;
12+
color: rgba(0, 0, 0, 0.87);
13+
}
14+
15+
.md-chip.selected {
16+
&.md-primary {
17+
background-color: md-color($primary, 500);
18+
color: md-contrast($primary, 500);
19+
}
20+
&.md-accent {
21+
background-color: md-color($accent, 500);
22+
color: md-contrast($accent, 500);
23+
}
24+
&.md-warn {
25+
background-color: md-color($warn, 500);
26+
color: md-contrast($warn, 500);
27+
}
28+
}
29+
}

src/lib/chips/chip-list.spec.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
2+
import {Component, DebugElement} from '@angular/core';
3+
import {By} from '@angular/platform-browser';
4+
import {MdChipList, MdChipsModule} from './index';
5+
6+
describe('MdChip', () => {
7+
let fixture: ComponentFixture<any>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
imports: [MdChipsModule.forRoot()],
12+
declarations: [
13+
StaticChipList
14+
]
15+
});
16+
17+
TestBed.compileComponents();
18+
}));
19+
20+
describe('basic behaviors', () => {
21+
let chipListDebugElement: DebugElement;
22+
let chipListNativeElement: HTMLElement;
23+
let chipListInstance: MdChipList;
24+
let testComponent: StaticChipList;
25+
26+
beforeEach(() => {
27+
fixture = TestBed.createComponent(StaticChipList);
28+
fixture.detectChanges();
29+
30+
chipListDebugElement = fixture.debugElement.query(By.directive(MdChipList));
31+
chipListNativeElement = chipListDebugElement.nativeElement;
32+
chipListInstance = chipListDebugElement.componentInstance;
33+
testComponent = fixture.debugElement.componentInstance;
34+
});
35+
36+
it('adds the `md-chip-list` class', () => {
37+
expect(chipListNativeElement.classList).toContain('md-chip-list');
38+
});
39+
});
40+
});
41+
42+
@Component({
43+
template: `
44+
<md-chip-list>
45+
<md-chip>{{name}} 1</md-chip>
46+
<md-chip>{{name}} 2</md-chip>
47+
<md-chip>{{name}} 3</md-chip>
48+
</md-chip-list>
49+
`
50+
})
51+
class StaticChipList {
52+
name: 'Test';
53+
}

src/lib/chips/chip-list.ts

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

src/lib/chips/chip.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
2+
import {Component, DebugElement} from '@angular/core';
3+
import {By} from '@angular/platform-browser';
4+
import {MdChip, MdChipsModule} from './index';
5+
6+
describe('MdChip', () => {
7+
let fixture: ComponentFixture<any>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
imports: [MdChipsModule.forRoot()],
12+
declarations: [
13+
SingleChip
14+
]
15+
});
16+
17+
TestBed.compileComponents();
18+
}));
19+
20+
describe('basic behaviors', () => {
21+
let chipDebugElement: DebugElement;
22+
let chipNativeElement: HTMLElement;
23+
let chipInstance: MdChip;
24+
let testComponent: SingleChip;
25+
26+
beforeEach(() => {
27+
fixture = TestBed.createComponent(SingleChip);
28+
fixture.detectChanges();
29+
30+
chipDebugElement = fixture.debugElement.query(By.directive(MdChip));
31+
chipNativeElement = chipDebugElement.nativeElement;
32+
chipInstance = chipDebugElement.componentInstance;
33+
testComponent = fixture.debugElement.componentInstance;
34+
});
35+
36+
it('adds the `md-chip` class', () => {
37+
expect(chipNativeElement.classList).toContain('md-chip');
38+
});
39+
});
40+
});
41+
42+
@Component({
43+
template: `<md-chip>{{name}}</md-chip>`
44+
})
45+
class SingleChip {
46+
name: 'Test';
47+
}

src/lib/chips/chip.ts

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

src/lib/chips/chips.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
font-size: 13px;
15+
line-height: 16px;
16+
}

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/core/theming/_all-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@import '../../button-toggle/button-toggle-theme';
55
@import '../../card/card-theme';
66
@import '../../checkbox/checkbox-theme';
7+
@import '../../chips/chips-theme';
78
@import '../../dialog/dialog-theme';
89
@import '../../grid-list/grid-list-theme';
910
@import '../../icon/icon-theme';
@@ -29,6 +30,7 @@
2930
@include md-button-toggle-theme($theme);
3031
@include md-card-theme($theme);
3132
@include md-checkbox-theme($theme);
33+
@include md-chips-theme($theme);
3234
@include md-dialog-theme($theme);
3335
@include md-grid-list-theme($theme);
3436
@include md-icon-theme($theme);

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
@@ -21,6 +21,7 @@ import {MdSidenavModule} from './sidenav/index';
2121
import {MdListModule} from './list/index';
2222
import {MdGridListModule} from './grid-list/index';
2323
import {MdCardModule} from './card/index';
24+
import {MdChipsModule} from './chips/index';
2425
import {MdIconModule} from './icon/index';
2526
import {MdProgressCircleModule} from './progress-circle/index';
2627
import {MdProgressBarModule} from './progress-bar/index';
@@ -37,6 +38,7 @@ const MATERIAL_MODULES = [
3738
MdButtonModule,
3839
MdButtonToggleModule,
3940
MdCardModule,
41+
MdChipsModule,
4042
MdCheckboxModule,
4143
MdDialogModule,
4244
MdGridListModule,
@@ -68,6 +70,7 @@ const MATERIAL_MODULES = [
6870
imports: [
6971
MdButtonModule.forRoot(),
7072
MdCardModule.forRoot(),
73+
MdChipsModule.forRoot(),
7174
MdCheckboxModule.forRoot(),
7275
MdGridListModule.forRoot(),
7376
MdInputModule.forRoot(),

0 commit comments

Comments
 (0)