Skip to content

Commit

Permalink
feat(chips): Initial skeleton/demo.
Browse files Browse the repository at this point in the history
Create the initial Chips skeleton with a very basic working demo
of static, styled chips.

References angular#120.
  • Loading branch information
topherfangio committed Nov 14, 2016
1 parent 009046f commit e553b8a
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/demo-app/chips/chips-demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="chips-demo">
<section>
<h3>Static Chips</h3>

<md-chips>
<md-chip>Chip 1</md-chip>
<md-chip>Chip 2</md-chip>
<md-chip>Chip 3</md-chip>
</md-chips>
</section>
</div>
2 changes: 2 additions & 0 deletions src/demo-app/chips/chips-demo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.chips-demo {
}
10 changes: 10 additions & 0 deletions src/demo-app/chips/chips-demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {Component} from '@angular/core';

@Component({
moduleId: module.id,
selector: 'chips-demo',
templateUrl: 'chips-demo.html',
styleUrls: ['chips-demo.scss']
})
export class ChipsDemo {
}
2 changes: 2 additions & 0 deletions src/demo-app/demo-app-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {IconDemo} from './icon/icon-demo';
import {GesturesDemo} from './gestures/gestures-demo';
import {InputDemo} from './input/input-demo';
import {CardDemo} from './card/card-demo';
import {ChipsDemo} from './chips/chips-demo';
import {RadioDemo} from './radio/radio-demo';
import {ButtonToggleDemo} from './button-toggle/button-toggle-demo';
import {ProgressCircleDemo} from './progress-circle/progress-circle-demo';
Expand Down Expand Up @@ -48,6 +49,7 @@ import {TabsDemo, SunnyTabContent, RainyTabContent, FoggyTabContent} from './tab
ButtonDemo,
ButtonToggleDemo,
CardDemo,
ChipsDemo,
CheckboxDemo,
DemoApp,
DialogDemo,
Expand Down
1 change: 1 addition & 0 deletions src/demo-app/demo-app/demo-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class DemoApp {
{name: 'Button', route: 'button'},
{name: 'Button Toggle', route: 'button-toggle'},
{name: 'Card', route: 'card'},
{name: 'Chips', route: 'chips'},
{name: 'Checkbox', route: 'checkbox'},
{name: 'Dialog', route: 'dialog'},
{name: 'Gestures', route: 'gestures'},
Expand Down
2 changes: 2 additions & 0 deletions src/demo-app/demo-app/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {SlideToggleDemo} from '../slide-toggle/slide-toggle-demo';
import {SliderDemo} from '../slider/slider-demo';
import {RadioDemo} from '../radio/radio-demo';
import {CardDemo} from '../card/card-demo';
import {ChipsDemo} from '../chips/chips-demo';
import {MenuDemo} from '../menu/menu-demo';
import {RippleDemo} from '../ripple/ripple-demo';
import {DialogDemo} from '../dialog/dialog-demo';
Expand All @@ -33,6 +34,7 @@ export const DEMO_APP_ROUTES: Routes = [
{path: '', component: Home},
{path: 'button', component: ButtonDemo},
{path: 'card', component: CardDemo},
{path: 'chips', component: ChipsDemo},
{path: 'radio', component: RadioDemo},
{path: 'select', component: SelectDemo},
{path: 'sidenav', component: SidenavDemo},
Expand Down
7 changes: 7 additions & 0 deletions src/lib/chips/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# md-chips

`md-chips` provides a horizontal display of (optionally) selectable, addable, and removable,
items and an input to create additional ones (again; optional). You can read more about chips
in the [Material Design spec](https://material.google.com/components/chips.html).

This is a placeholder README for the eventual chips component.
26 changes: 26 additions & 0 deletions src/lib/chips/chip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
Component,
ElementRef,
Renderer
} from '@angular/core';

@Component(MdChip.COMPONENT_CONFIG)
export class MdChip {

static COMPONENT_CONFIG:Component = {
selector: 'md-chip, [md-chip]',
template: `<ng-content></ng-content>`,
host: {
// Properties
'tabindex': '-1',
'role': 'option'
}
};

constructor(protected _renderer: Renderer, protected _elementRef: ElementRef) {
}

ngAfterContentInit(): void {
this._elementRef.nativeElement.classList.add('md-chip');
}
}
18 changes: 18 additions & 0 deletions src/lib/chips/chips.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$md-chip-vertical-padding: 8px;
$md-chip-horizontal-padding: 12px;

.md-chips {
padding: $md-chip-horizontal-padding;
}

.md-chip {
display: inline-block;
padding: $md-chip-vertical-padding $md-chip-horizontal-padding
$md-chip-vertical-padding $md-chip-horizontal-padding;
border-radius: $md-chip-horizontal-padding * 2;

background-color: #E0E0E0;
color: rgba(0, 0, 0, 0.87);
font-size: 13px;
line-height: 16px;
}
55 changes: 55 additions & 0 deletions src/lib/chips/chips.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
ChangeDetectionStrategy,
Component,
ContentChildren,
ElementRef,
ModuleWithProviders,
NgModule,
QueryList,
ViewEncapsulation
} from '@angular/core';

import {MdChip} from './chip';

@Component(MdChips.COMPONENT_CONFIG)
export class MdChips {

static COMPONENT_CONFIG: Component = {
moduleId: module.id,
selector: 'md-chips',
template: `<ng-content></ng-content>`,
host: {
// Properties
'tabindex': '0',
'role': 'listbox',
},
queries: {
items: new ContentChildren(MdChip)
},
styleUrls: ['chips.css'],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush
};

protected items: QueryList<MdChip>;

constructor(private _elementRef: ElementRef) {}

ngAfterContentInit(): void {
this._elementRef.nativeElement.classList.add('md-chips');
}
}

@NgModule({
imports: [],
exports: [MdChips, MdChip],
declarations: [MdChips, MdChip]
})
export class MdChipsModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: MdChipsModule,
providers: []
}
}
}
2 changes: 2 additions & 0 deletions src/lib/chips/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './chips';
export * from './chip';
1 change: 1 addition & 0 deletions src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './module';
export * from './button/index';
export * from './button-toggle/index';
export * from './card/index';
export * from './chips/index';
export * from './checkbox/index';
export * from './dialog/index';
export * from './grid-list/index';
Expand Down
3 changes: 3 additions & 0 deletions src/lib/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {MdSidenavModule} from './sidenav/index';
import {MdListModule} from './list/index';
import {MdGridListModule} from './grid-list/index';
import {MdCardModule} from './card/index';
import {MdChipsModule} from './chips/index';
import {MdIconModule} from './icon/index';
import {MdProgressCircleModule} from './progress-circle/index';
import {MdProgressBarModule} from './progress-bar/index';
Expand All @@ -36,6 +37,7 @@ const MATERIAL_MODULES = [
MdButtonModule,
MdButtonToggleModule,
MdCardModule,
MdChipsModule,
MdCheckboxModule,
MdDialogModule,
MdGridListModule,
Expand Down Expand Up @@ -66,6 +68,7 @@ const MATERIAL_MODULES = [
imports: [
MdButtonModule.forRoot(),
MdCardModule.forRoot(),
MdChipsModule.forRoot(),
MdCheckboxModule.forRoot(),
MdGridListModule.forRoot(),
MdInputModule.forRoot(),
Expand Down

0 comments on commit e553b8a

Please sign in to comment.