UNPKG

k15t-aui-ng2

Version:

aui-ng2 is a set of angular 2 components, directives and services to simplify the integration with Atlassian products based on AUI/ADG. The library is still under development and is considered in an experimental state. So be aware that things will change

55 lines (48 loc) 1.61 kB
import {Component, Input, Output, EventEmitter} from '@angular/core'; import {FORM_DIRECTIVES} from '@angular/common'; @Component({ selector: 'auiNgRadioButtonGroup', directives: [...FORM_DIRECTIVES], styles: [` .aui-ng2-orientation-horizontal .radio{ float: left; margin-right: 10px; } `], template: ` <fieldset class="group aui-ng2-orientation-{{orientation}}"> <legend><span>{{title}}</span></legend> <div class="radio" *ngFor="let item of items"> <input class="radio" type="radio" name="{{name}}" id="{{name}}-{{getId(item)}}" (change)="onChange(item)" [checked]="getId(selection) == getId(item)"> <label attr.for="{{name}}-{{getId(item)}}">{{getLabel(item)}}</label> </div> </fieldset> ` }) export class AuiNgRadioButtonGroupComponent { @Input() orientation: string; @Input() title: string; @Input() name: string; @Input() selection: any; @Input() items: any[]; @Input() idProperty: string; @Input() labelProperty: any; @Output() changed : EventEmitter<any> = new EventEmitter<any>(); private selection: any = {}; private onChange (item) { this.changed.emit(item); } private getLabel(item: any): string { if (typeof this.labelProperty === 'function') { return this.labelProperty(item); } return item && item[this.labelProperty]; } private getId(item:any):string { return item && item[this.idProperty]; } }