diff --git a/src/checkbox/checkbox.html b/src/checkbox/checkbox.html index d83b639f555..492199b8164 100644 --- a/src/checkbox/checkbox.html +++ b/src/checkbox/checkbox.html @@ -4,7 +4,7 @@ [attr.name]="name" [attr.value]="value" [attr.tabindex]="tabindex" - [disabled]="disabled" + [attr.disabled]="disabled ? true : null" [checked]="checked" (change)="onChange($event)" (focus)="onFocus($event)" diff --git a/src/checkbox/checkbox.spec.ts b/src/checkbox/checkbox.spec.ts new file mode 100644 index 00000000000..f19d0ddd5dd --- /dev/null +++ b/src/checkbox/checkbox.spec.ts @@ -0,0 +1,119 @@ +import { + async, + TestBed +} from "@angular/core/testing"; +import { Component, ViewChild } from "@angular/core"; +import { FormsModule } from '@angular/forms'; +import { By } from "@angular/platform-browser"; +import { IgCheckbox } from "./checkbox"; + +describe('IgCheckbox', function() { + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ + InitCheckbox, + CheckboxSimple, + CheckboxDisabled, + IgCheckbox + ], + imports: [FormsModule] + }) + .compileComponents(); + })); + + it('Initializes a checkbox', () => { + let fixture = TestBed.createComponent(InitCheckbox); + fixture.detectChanges(); + + let nativeCheckbox = fixture.debugElement.query(By.css('input')).nativeElement; + let nativeLabel = fixture.debugElement.query(By.css('label')).nativeElement; + + expect(nativeCheckbox).toBeTruthy(); + expect(nativeLabel).toBeTruthy(); + expect(nativeLabel.textContent.trim()).toEqual('Init'); + }); + + it('Initialize with a ngModel', () => { + let fixture = TestBed.createComponent(CheckboxSimple); + fixture.detectChanges(); + + let nativeCheckbox = fixture.debugElement.query(By.css('input')).nativeElement; + let checkboxInstance = fixture.componentInstance.cb; + let testInstance = fixture.componentInstance; + + fixture.detectChanges(); + + expect(nativeCheckbox.checked).toBe(false); + expect(checkboxInstance.checked).toBe(false); + + testInstance.subscribed = true; + fixture.detectChanges(); + + expect(nativeCheckbox.checked).toBe(true); + expect(checkboxInstance.checked).toBe(true); + }); + + it('Disabled state', () => { + let fixture = TestBed.createComponent(CheckboxDisabled); + fixture.detectChanges(); + + let nativeCheckbox = fixture.debugElement.query(By.css('input')).nativeElement; + let checkboxInstance = fixture.componentInstance.cb; + let testInstance = fixture.componentInstance; + + fixture.detectChanges(); + + expect(checkboxInstance.disabled).toBe(true); + expect(nativeCheckbox.getAttribute('disabled')).toBe('true'); + + nativeCheckbox.dispatchEvent(new Event('change')); + fixture.detectChanges(); + + // Should not update + expect(checkboxInstance.checked).toBe(false); + expect(testInstance.subscribed).toBe(false); + }); + + it('Event handling', () => { + let fixture = TestBed.createComponent(CheckboxSimple); + fixture.detectChanges(); + + let nativeCheckbox = fixture.debugElement.query(By.css('input')).nativeElement; + let checkboxInstance = fixture.componentInstance.cb; + let testInstance = fixture.componentInstance; + + nativeCheckbox.dispatchEvent(new Event('focus')); + fixture.detectChanges(); + + expect(checkboxInstance.focused).toBe(true); + + nativeCheckbox.dispatchEvent(new Event('blur')); + fixture.detectChanges(); + + expect(checkboxInstance.focused).toBe(false); + + spyOn(checkboxInstance.change, 'emit'); + nativeCheckbox.dispatchEvent(new Event('change')); + fixture.detectChanges(); + + expect(checkboxInstance.change.emit).toHaveBeenCalled(); + expect(testInstance.subscribed).toBe(true); + }); +}); + +@Component({ template: `Init`}) +class InitCheckbox {} + +@Component({ template: `Simple`}) +class CheckboxSimple { + @ViewChild('cb') cb: IgCheckbox; + + subscribed: boolean = false; +} + +@Component({ template: `Disabled`}) +class CheckboxDisabled { + @ViewChild('cb') cb: IgCheckbox; + + subscribed: boolean = false; +} \ No newline at end of file diff --git a/src/checkbox/checkbox.ts b/src/checkbox/checkbox.ts index 6c762198922..d90d162c47d 100644 --- a/src/checkbox/checkbox.ts +++ b/src/checkbox/checkbox.ts @@ -41,7 +41,7 @@ export class IgCheckbox implements ControlValueAccessor { protected _value: any; - focused: boolean = false; + focused: boolean = false; onChange(event) { if (this.disabled) { @@ -67,7 +67,7 @@ export class IgCheckbox implements ControlValueAccessor { return; } this._value = value; - this.checked = this._value; + this.checked = !!this._value; } private _onTouchedCallback: () => void = noop; diff --git a/src/layout/layout.ts b/src/layout/layout.ts new file mode 100644 index 00000000000..dc25b28e3ea --- /dev/null +++ b/src/layout/layout.ts @@ -0,0 +1,53 @@ +import { Directive, HostBinding, Input, NgModule } from '@angular/core'; + + +@Directive({ + selector: '[layout]' +}) +export class LayoutDirective { + + @Input() dir: string = "row"; + @Input() reverse: boolean = false; + @Input() wrap: string = "nowrap"; + @Input() justify: string = "flex-start"; + @Input() itemAlign: string = "flex-start"; + + @HostBinding('style.display') display = 'flex'; + @HostBinding('style.flex-wrap') get flexwrap() { return this.wrap; } + @HostBinding('style.justify-content') get justifycontent() { return this.justify; } + @HostBinding('style.align-content') get align() { return this.itemAlign; } + + @HostBinding('style.flex-direction') + get direction() { + if (this.reverse) { + return (this.dir == 'row') ? 'row-reverse' : 'column-reverse'; + } + return (this.dir == 'row') ? 'row' : 'column'; + } +} + +@Directive({ + selector: '[flex]' +}) +export class FlexDirective { + @Input() grow: number = 1; + @Input() shrink: number = 1; + @Input() flex: string; + @Input() order: number = 0; + + @HostBinding('style.flex') + get style() { + return `${this.grow} ${this.shrink}`; + } + + @HostBinding('style.order') + get itemorder() { + return this.order || 0; + } +} + +@NgModule({ + declarations: [LayoutDirective, FlexDirective], + exports: [FlexDirective, LayoutDirective] +}) +export class IgLayout {} \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index 9e1e44d70f5..bd323afc01f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -14,3 +14,5 @@ export * from './radio/radio'; export * from './label/label'; export * from './switch/switch'; export * from './avatar/avatar'; +export * from './layout/layout'; +export * from './modal/modal'; \ No newline at end of file diff --git a/src/modal/modal.html b/src/modal/modal.html new file mode 100644 index 00000000000..62675ef1b57 --- /dev/null +++ b/src/modal/modal.html @@ -0,0 +1,8 @@ +
+