128 lines
4.3 KiB
JavaScript
128 lines
4.3 KiB
JavaScript
import { forwardRef, EventEmitter, Component, ChangeDetectionStrategy, ChangeDetectorRef, Input, Output, ViewChild, NgModule } from '@angular/core';
|
|
import { CommonModule } from '@angular/common';
|
|
import { NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
|
|
const RADIO_VALUE_ACCESSOR = {
|
|
provide: NG_VALUE_ACCESSOR,
|
|
useExisting: forwardRef(() => RadioButton),
|
|
multi: true
|
|
};
|
|
class RadioButton {
|
|
constructor(cd) {
|
|
this.cd = cd;
|
|
this.onClick = new EventEmitter();
|
|
this.onFocus = new EventEmitter();
|
|
this.onBlur = new EventEmitter();
|
|
this.onModelChange = () => { };
|
|
this.onModelTouched = () => { };
|
|
}
|
|
handleClick(event, radioButton, focus) {
|
|
event.preventDefault();
|
|
if (this.disabled) {
|
|
return;
|
|
}
|
|
this.select(event);
|
|
if (focus) {
|
|
radioButton.focus();
|
|
}
|
|
}
|
|
select(event) {
|
|
if (!this.disabled) {
|
|
this.inputViewChild.nativeElement.checked = true;
|
|
this.checked = true;
|
|
this.onModelChange(this.value);
|
|
this.onClick.emit(event);
|
|
}
|
|
}
|
|
writeValue(value) {
|
|
this.checked = (value == this.value);
|
|
if (this.inputViewChild && this.inputViewChild.nativeElement) {
|
|
this.inputViewChild.nativeElement.checked = this.checked;
|
|
}
|
|
this.cd.markForCheck();
|
|
}
|
|
registerOnChange(fn) {
|
|
this.onModelChange = fn;
|
|
}
|
|
registerOnTouched(fn) {
|
|
this.onModelTouched = fn;
|
|
}
|
|
setDisabledState(val) {
|
|
this.disabled = val;
|
|
this.cd.markForCheck();
|
|
}
|
|
onInputFocus(event) {
|
|
this.focused = true;
|
|
this.onFocus.emit(event);
|
|
}
|
|
onInputBlur(event) {
|
|
this.focused = false;
|
|
this.onModelTouched();
|
|
this.onBlur.emit(event);
|
|
}
|
|
onChange(event) {
|
|
this.select(event);
|
|
}
|
|
focus() {
|
|
this.inputViewChild.nativeElement.focus();
|
|
}
|
|
}
|
|
RadioButton.decorators = [
|
|
{ type: Component, args: [{
|
|
selector: 'p-radioButton',
|
|
template: `
|
|
<div [ngStyle]="style" [ngClass]="{'p-radiobutton p-component':true,'p-radiobutton-checked': checked, 'p-radiobutton-disabled': disabled, 'p-radiobutton-focused': focused}" [class]="styleClass">
|
|
<div class="p-hidden-accessible">
|
|
<input #rb type="radio" [attr.id]="inputId" [attr.name]="name" [attr.value]="value" [attr.tabindex]="tabindex" [attr.aria-labelledby]="ariaLabelledBy"
|
|
[checked]="checked" (change)="onChange($event)" (focus)="onInputFocus($event)" (blur)="onInputBlur($event)" [disabled]="disabled">
|
|
</div>
|
|
<div (click)="handleClick($event, rb, true)" role="radio" [attr.aria-checked]="checked"
|
|
[ngClass]="{'p-radiobutton-box':true,
|
|
'p-highlight': checked, 'p-disabled': disabled, 'p-focus': focused}">
|
|
<span class="p-radiobutton-icon"></span>
|
|
</div>
|
|
</div>
|
|
<label (click)="select($event)" [class]="labelStyleClass"
|
|
[ngClass]="{'p-radiobutton-label':true, 'p-radiobutton-label-active':rb.checked, 'p-disabled':disabled, 'p-radiobutton-label-focus':focused}"
|
|
*ngIf="label" [attr.for]="inputId">{{label}}</label>
|
|
`,
|
|
providers: [RADIO_VALUE_ACCESSOR],
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
},] }
|
|
];
|
|
RadioButton.ctorParameters = () => [
|
|
{ type: ChangeDetectorRef }
|
|
];
|
|
RadioButton.propDecorators = {
|
|
value: [{ type: Input }],
|
|
name: [{ type: Input }],
|
|
disabled: [{ type: Input }],
|
|
label: [{ type: Input }],
|
|
tabindex: [{ type: Input }],
|
|
inputId: [{ type: Input }],
|
|
ariaLabelledBy: [{ type: Input }],
|
|
style: [{ type: Input }],
|
|
styleClass: [{ type: Input }],
|
|
labelStyleClass: [{ type: Input }],
|
|
onClick: [{ type: Output }],
|
|
onFocus: [{ type: Output }],
|
|
onBlur: [{ type: Output }],
|
|
inputViewChild: [{ type: ViewChild, args: ['rb',] }]
|
|
};
|
|
class RadioButtonModule {
|
|
}
|
|
RadioButtonModule.decorators = [
|
|
{ type: NgModule, args: [{
|
|
imports: [CommonModule],
|
|
exports: [RadioButton],
|
|
declarations: [RadioButton]
|
|
},] }
|
|
];
|
|
|
|
/**
|
|
* Generated bundle index. Do not edit.
|
|
*/
|
|
|
|
export { RADIO_VALUE_ACCESSOR, RadioButton, RadioButtonModule };
|
|
//# sourceMappingURL=primeng-radiobutton.js.map
|