card and checkbox docs wip

This commit is contained in:
Tim Lancina
2015-08-28 13:55:09 -07:00
parent f8fc17dc42
commit 0078e4d4b7
2 changed files with 51 additions and 7 deletions

View File

@ -6,11 +6,18 @@ import {IonicDirective} from '../../config/annotations';
import {ListVirtualScroll} from './virtual'; import {ListVirtualScroll} from './virtual';
import * as util from 'ionic/util'; import * as util from 'ionic/util';
/**
* TODO
*/
@IonicDirective({ @IonicDirective({
selector: 'ion-card' selector: 'ion-card'
}) })
export class Card extends Ion { export class Card extends Ion {
/**
* TODO
* @param {ElementeRef} elementRef TODO
* @param {IonicConfig} ionicConfig TODO
*/
constructor(elementRef: ElementRef, ionicConfig: IonicConfig) { constructor(elementRef: ElementRef, ionicConfig: IonicConfig) {
super(elementRef, ionicConfig); super(elementRef, ionicConfig);
} }

View File

@ -12,7 +12,9 @@ import {IonicConfig} from '../../config/config';
import {IonicComponent, IonicView} from '../../config/annotations'; import {IonicComponent, IonicView} from '../../config/annotations';
import {TapClick} from '../button/button'; import {TapClick} from '../button/button';
/**
* Checkbox control value accessor.
*/
@IonicComponent({ @IonicComponent({
selector: 'ion-checkbox', selector: 'ion-checkbox',
properties: [ properties: [
@ -41,10 +43,17 @@ import {TapClick} from '../button/button';
'</ion-item-content>' '</ion-item-content>'
}) })
export class Checkbox extends Ion { export class Checkbox extends Ion {
/**
* TODO
* @param {ElementRef} elementRef TODO
* @param {IonicConfig} ionicConfig TODO
* @param {NgControl=} ngControl TODO
* @param {TapClick=} tapClick TODO
*/
constructor( constructor(
elementRef: ElementRef, elementRef: ElementRef,
config: IonicConfig, config: IonicConfig,
@Optional() cd: NgControl, @Optional() ngControl: NgControl,
tapClick: TapClick tapClick: TapClick
) { ) {
super(elementRef, config); super(elementRef, config);
@ -55,21 +64,32 @@ export class Checkbox extends Ion {
this.onChange = (_) => {}; this.onChange = (_) => {};
this.onTouched = (_) => {}; this.onTouched = (_) => {};
this.cd = cd; this.ngControl = ngControl;
if (cd) cd.valueAccessor = this; if (ngControl) ngControl.valueAccessor = this;
} }
/**
* TODO
*/
onInit() { onInit() {
super.onInit(); super.onInit();
this.labelId = 'label-' + this.id; this.labelId = 'label-' + this.id;
} }
/**
* Toggle the checked state of the checkbox. Calls onChange to pass the
* updated checked state to the model (Control).
*/
toggle() { toggle() {
this.checked = !this.checked; this.checked = !this.checked;
this.onChange(this.checked); this.onChange(this.checked);
} }
/**
* Click event handler to toggle the checkbox checked state.
* @param {MouseEvent} ev The click event.
*/
click(ev) { click(ev) {
if (this.tapClick.allowClick(ev)) { if (this.tapClick.allowClick(ev)) {
ev.preventDefault(); ev.preventDefault();
@ -78,13 +98,30 @@ export class Checkbox extends Ion {
} }
} }
/**
* @private
* Angular2 Forms API method called by the model (Control) on change to update
* the checked value.
* https://github.com/angular/angular/blob/master/modules/angular2/src/forms/directives/shared.ts#L34
*/
writeValue(value) { writeValue(value) {
this.checked = value; this.checked = value;
} }
// Used by the view to update the model (Control) /**
// Up to us to call it in update() * @private
* Angular2 Forms API method called by the view (NgControl) to register the
* onChange event handler that updates the model (Control).
* https://github.com/angular/angular/blob/master/modules/angular2/src/forms/directives/shared.ts#L27
* @param {Function} fn the onChange event handler.
*/
registerOnChange(fn) { this.onChange = fn; } registerOnChange(fn) { this.onChange = fn; }
/**
* @private
* Angular2 Forms API method called by the the view (NgControl) to register
* the onTouched event handler that marks model as touched.
* @param {Function} fn onTouched event handler.
*/
registerOnTouched(fn) { this.onTouched = fn; } registerOnTouched(fn) { this.onTouched = fn; }
} }