feat(ba-checkbox): create checkbox component

This commit is contained in:
tibing 2016-07-07 15:25:08 +03:00
parent f3f3f43805
commit 73cec2fceb
6 changed files with 48 additions and 18 deletions

View file

@ -0,0 +1,32 @@
import {Component, Provider, forwardRef, Input} from "@angular/core";
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from "@angular/common";
const BA_CHECKBOX_CONTROL_VALUE_ACCESSOR = new Provider(
NG_VALUE_ACCESSOR, {
useExisting: forwardRef(() => BaCheckbox),
multi: true
});
@Component({
selector: 'ba-checkbox',
template: require('./baCheckbox.html'),
providers: [BA_CHECKBOX_CONTROL_VALUE_ACCESSOR]
})
export class BaCheckbox implements ControlValueAccessor {
@Input() disabled:boolean;
@Input() label:string;
@Input() value:string;
@Input() name:string;
@Input() baCheckboxClass:string;
public state: boolean;
onChange(value: any): void {}
onTouch(value: any): void {}
writeValue(value: any): void {
this.state = value;
}
registerOnChange(fn: any): void { this.onChange = fn; }
registerOnTouched(fn: any): void { this.onTouch = fn; }
}

View file

@ -0,0 +1,8 @@
<div class="{{baCheckboxClass}}">
<label class="checkbox-inline custom-checkbox nowrap">
<input type="checkbox" [name]="name" [checked]=state
(change)="onChange($event.target.checked)"
[disabled]="disabled" [value]="value">
<span>{{label}}</span>
</label>
</div>

View file

@ -0,0 +1 @@
export * from './baCheckbox.component';