@rdkmaster/jigsaw-labs
Version:
Jigsaw, the next generation component set for RDK
94 lines (75 loc) • 2.73 kB
text/typescript
import {Component, EventEmitter, forwardRef, Input, NgModule, Output} from "@angular/core";
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from "@angular/forms";
import {CommonModule} from "@angular/common";
import {JigsawRadioModule} from "./radio";
import {GroupOptionValue} from "../list-and-tile/group-common";
import {ArrayCollection} from "../../core/data/array-collection";
import {AbstractJigsawComponent} from "../common";
import {CommonUtils} from "../../core/utils/common-utils";
export class JigsawRadiosLite extends AbstractJigsawComponent implements ControlValueAccessor {
public valid: boolean = true;
public data: ArrayCollection<GroupOptionValue> | GroupOptionValue[];
public value: any;
private _trackItemBy: string | string[];
public get trackItemBy(): string | string[] {
if (!this._trackItemBy && this.data && typeof this.data[0] !== 'string') {
this._trackItemBy = this.labelField;
}
return this._trackItemBy;
}
public set trackItemBy(value: string | string[]) {
if (!value) {
return;
}
this._trackItemBy = typeof value === 'string' ? value.split(/\s*,\s*/g) : value;
}
public labelField: string = 'label';
public valueChange: EventEmitter<any> = new EventEmitter<any>();
public get _$trackByFn() {
return CommonUtils.toTrackByFunction(this._trackItemBy);
};
radioChange(item) {
this.valueChange.emit(item);
this._propagateChange(item);
}
ngOnInit() {
super.ngOnInit();
}
private _propagateChange: any = () => {
};
public writeValue(value: any): void {
}
public registerOnChange(fn: any): void {
this._propagateChange = fn;
}
public registerOnTouched(fn: any): void {
}
}
export class JigsawRadioLiteModule {
}