-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(chips): Initial skeleton/demo. #1855
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div class="chips-demo"> | ||
<section> | ||
<h3>Static Chips</h3> | ||
|
||
<md-chip-list> | ||
<md-chip>Basic Chip</md-chip> | ||
<md-chip class="selected md-primary">Primary</md-chip> | ||
<md-chip class="selected md-accent">Accent</md-chip> | ||
<md-chip class="selected md-warn">Warn</md-chip> | ||
</md-chip-list> | ||
</section> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.chips-demo { | ||
} |
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 { | ||
} |
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@import '../core/theming/theming'; | ||
|
||
@mixin md-chips-theme($theme) { | ||
$is-dark-theme: map-get($theme, is-dark); | ||
$primary: map-get($theme, primary); | ||
$accent: map-get($theme, accent); | ||
$warn: map-get($theme, warn); | ||
$background: map-get($theme, background); | ||
|
||
.md-chip { | ||
background-color: #e0e0e0; | ||
color: rgba(0, 0, 0, 0.87); | ||
} | ||
|
||
.md-chip.selected { | ||
&.md-primary { | ||
background-color: md-color($primary, 500); | ||
color: md-contrast($primary, 500); | ||
} | ||
&.md-accent { | ||
background-color: md-color($accent, 500); | ||
color: md-contrast($accent, 500); | ||
} | ||
&.md-warn { | ||
background-color: md-color($warn, 500); | ||
color: md-contrast($warn, 500); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {async, ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {Component, DebugElement} from '@angular/core'; | ||
import {By} from '@angular/platform-browser'; | ||
import {MdChipList, MdChipsModule} from './index'; | ||
|
||
describe('MdChip', () => { | ||
let fixture: ComponentFixture<any>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MdChipsModule.forRoot()], | ||
declarations: [ | ||
StaticChipList | ||
] | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
})); | ||
|
||
describe('basic behaviors', () => { | ||
let chipListDebugElement: DebugElement; | ||
let chipListNativeElement: HTMLElement; | ||
let chipListInstance: MdChipList; | ||
let testComponent: StaticChipList; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(StaticChipList); | ||
fixture.detectChanges(); | ||
|
||
chipListDebugElement = fixture.debugElement.query(By.directive(MdChipList)); | ||
chipListNativeElement = chipListDebugElement.nativeElement; | ||
chipListInstance = chipListDebugElement.componentInstance; | ||
testComponent = fixture.debugElement.componentInstance; | ||
}); | ||
|
||
it('adds the `md-chip-list` class', () => { | ||
expect(chipListNativeElement.classList).toContain('md-chip-list'); | ||
}); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
template: ` | ||
<md-chip-list> | ||
<md-chip>{{name}} 1</md-chip> | ||
<md-chip>{{name}} 2</md-chip> | ||
<md-chip>{{name}} 3</md-chip> | ||
</md-chip-list> | ||
` | ||
}) | ||
class StaticChipList { | ||
name: 'Test'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
ElementRef, | ||
ModuleWithProviders, | ||
NgModule, | ||
ViewEncapsulation | ||
} from '@angular/core'; | ||
|
||
import {MdChip} from './chip'; | ||
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: 'md-chip-list', | ||
template: `<ng-content></ng-content>`, | ||
host: { | ||
// Properties | ||
'tabindex': '0', | ||
'role': 'listbox', | ||
'class': 'md-chip-list' | ||
}, | ||
styleUrls: ['chips.css'], | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class MdChipList { | ||
constructor(private _elementRef: ElementRef) {} | ||
|
||
ngAfterContentInit(): void {} | ||
} | ||
|
||
@NgModule({ | ||
imports: [], | ||
exports: [MdChipList, MdChip], | ||
declarations: [MdChipList, MdChip] | ||
}) | ||
export class MdChipsModule { | ||
static forRoot(): ModuleWithProviders { | ||
return { | ||
ngModule: MdChipsModule, | ||
providers: [] | ||
}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import {async, ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {Component, DebugElement} from '@angular/core'; | ||
import {By} from '@angular/platform-browser'; | ||
import {MdChip, MdChipsModule} from './index'; | ||
|
||
describe('MdChip', () => { | ||
let fixture: ComponentFixture<any>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MdChipsModule.forRoot()], | ||
declarations: [ | ||
SingleChip | ||
] | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
})); | ||
|
||
describe('basic behaviors', () => { | ||
let chipDebugElement: DebugElement; | ||
let chipNativeElement: HTMLElement; | ||
let chipInstance: MdChip; | ||
let testComponent: SingleChip; | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(SingleChip); | ||
fixture.detectChanges(); | ||
|
||
chipDebugElement = fixture.debugElement.query(By.directive(MdChip)); | ||
chipNativeElement = chipDebugElement.nativeElement; | ||
chipInstance = chipDebugElement.componentInstance; | ||
testComponent = fixture.debugElement.componentInstance; | ||
}); | ||
|
||
it('adds the `md-chip` class', () => { | ||
expect(chipNativeElement.classList).toContain('md-chip'); | ||
}); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
template: `<md-chip>{{name}}</md-chip>` | ||
}) | ||
class SingleChip { | ||
name: 'Test'; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Component, ElementRef, Renderer } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'md-chip, [md-chip]', | ||
template: `<ng-content></ng-content>`, | ||
host: { | ||
// Properties | ||
'class': 'md-chip', | ||
'tabindex': '-1', | ||
'role': 'option' | ||
} | ||
}) | ||
export class MdChip { | ||
constructor(protected _renderer: Renderer, protected _elementRef: ElementRef) {} | ||
|
||
ngAfterContentInit(): void {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
$md-chip-vertical-padding: 8px; | ||
$md-chip-horizontal-padding: 12px; | ||
|
||
.md-chip-list { | ||
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; | ||
|
||
font-size: 13px; | ||
line-height: 16px; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we should be setting @hansl thoughts on this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would love some additional guidance on this. Those values were set based off of the spec, so if we are allowing users to deviate, it may change some other values (like the border raidus in particular). Is there any plan to use |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './chip-list'; | ||
export * from './chip'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to repeat these,
is enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed; will fix in my next PR.