radiobutton.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. "use strict";
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  4. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  5. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  6. return c > 3 && r && Object.defineProperty(target, key, r), r;
  7. };
  8. var __metadata = (this && this.__metadata) || function (k, v) {
  9. if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var core_1 = require("@angular/core");
  13. var common_1 = require("@angular/common");
  14. var forms_1 = require("@angular/forms");
  15. exports.RADIO_VALUE_ACCESSOR = {
  16. provide: forms_1.NG_VALUE_ACCESSOR,
  17. useExisting: core_1.forwardRef(function () { return RadioButton; }),
  18. multi: true
  19. };
  20. var RadioButton = /** @class */ (function () {
  21. function RadioButton(cd) {
  22. this.cd = cd;
  23. this.onClick = new core_1.EventEmitter();
  24. this.onFocus = new core_1.EventEmitter();
  25. this.onBlur = new core_1.EventEmitter();
  26. this.onModelChange = function () { };
  27. this.onModelTouched = function () { };
  28. }
  29. RadioButton.prototype.handleClick = function (event, radioButton, focus) {
  30. event.preventDefault();
  31. if (this.disabled) {
  32. return;
  33. }
  34. this.select(event);
  35. if (focus) {
  36. radioButton.focus();
  37. }
  38. };
  39. RadioButton.prototype.select = function (event) {
  40. if (!this.disabled) {
  41. this.inputViewChild.nativeElement.checked = true;
  42. this.checked = true;
  43. this.onModelChange(this.value);
  44. this.onClick.emit(event);
  45. }
  46. };
  47. RadioButton.prototype.writeValue = function (value) {
  48. this.checked = (value == this.value);
  49. if (this.inputViewChild && this.inputViewChild.nativeElement) {
  50. this.inputViewChild.nativeElement.checked = this.checked;
  51. }
  52. this.cd.markForCheck();
  53. };
  54. RadioButton.prototype.registerOnChange = function (fn) {
  55. this.onModelChange = fn;
  56. };
  57. RadioButton.prototype.registerOnTouched = function (fn) {
  58. this.onModelTouched = fn;
  59. };
  60. RadioButton.prototype.setDisabledState = function (val) {
  61. this.disabled = val;
  62. };
  63. RadioButton.prototype.onInputFocus = function (event) {
  64. this.focused = true;
  65. this.onFocus.emit(event);
  66. };
  67. RadioButton.prototype.onInputBlur = function (event) {
  68. this.focused = false;
  69. this.onModelTouched();
  70. this.onBlur.emit(event);
  71. };
  72. RadioButton.prototype.onChange = function (event) {
  73. this.select(event);
  74. };
  75. __decorate([
  76. core_1.Input(),
  77. __metadata("design:type", Object)
  78. ], RadioButton.prototype, "value", void 0);
  79. __decorate([
  80. core_1.Input(),
  81. __metadata("design:type", String)
  82. ], RadioButton.prototype, "name", void 0);
  83. __decorate([
  84. core_1.Input(),
  85. __metadata("design:type", Boolean)
  86. ], RadioButton.prototype, "disabled", void 0);
  87. __decorate([
  88. core_1.Input(),
  89. __metadata("design:type", String)
  90. ], RadioButton.prototype, "label", void 0);
  91. __decorate([
  92. core_1.Input(),
  93. __metadata("design:type", Number)
  94. ], RadioButton.prototype, "tabindex", void 0);
  95. __decorate([
  96. core_1.Input(),
  97. __metadata("design:type", String)
  98. ], RadioButton.prototype, "inputId", void 0);
  99. __decorate([
  100. core_1.Input(),
  101. __metadata("design:type", Object)
  102. ], RadioButton.prototype, "style", void 0);
  103. __decorate([
  104. core_1.Input(),
  105. __metadata("design:type", String)
  106. ], RadioButton.prototype, "styleClass", void 0);
  107. __decorate([
  108. core_1.Input(),
  109. __metadata("design:type", String)
  110. ], RadioButton.prototype, "labelStyleClass", void 0);
  111. __decorate([
  112. core_1.Output(),
  113. __metadata("design:type", core_1.EventEmitter)
  114. ], RadioButton.prototype, "onClick", void 0);
  115. __decorate([
  116. core_1.Output(),
  117. __metadata("design:type", core_1.EventEmitter)
  118. ], RadioButton.prototype, "onFocus", void 0);
  119. __decorate([
  120. core_1.Output(),
  121. __metadata("design:type", core_1.EventEmitter)
  122. ], RadioButton.prototype, "onBlur", void 0);
  123. __decorate([
  124. core_1.ViewChild('rb', { static: true }),
  125. __metadata("design:type", core_1.ElementRef)
  126. ], RadioButton.prototype, "inputViewChild", void 0);
  127. RadioButton = __decorate([
  128. core_1.Component({
  129. selector: 'p-radioButton',
  130. template: "\n <div [ngStyle]=\"style\" [ngClass]=\"'ui-radiobutton ui-widget'\" [class]=\"styleClass\">\n <div class=\"ui-helper-hidden-accessible\">\n <input #rb type=\"radio\" [attr.id]=\"inputId\" [attr.name]=\"name\" [attr.value]=\"value\" [attr.tabindex]=\"tabindex\" \n [checked]=\"checked\" (change)=\"onChange($event)\" (focus)=\"onInputFocus($event)\" (blur)=\"onInputBlur($event)\" [disabled]=\"disabled\">\n </div>\n <div (click)=\"handleClick($event, rb, true)\"\n [ngClass]=\"{'ui-radiobutton-box ui-widget ui-state-default':true,\n 'ui-state-active':rb.checked,'ui-state-disabled':disabled,'ui-state-focus':focused}\">\n <span class=\"ui-radiobutton-icon ui-clickable\" [ngClass]=\"{'pi pi-circle-on':rb.checked}\"></span>\n </div>\n </div>\n <label (click)=\"select($event)\" [class]=\"labelStyleClass\"\n [ngClass]=\"{'ui-radiobutton-label':true, 'ui-label-active':rb.checked, 'ui-label-disabled':disabled, 'ui-label-focus':focused}\"\n *ngIf=\"label\" [attr.for]=\"inputId\">{{label}}</label>\n ",
  131. providers: [exports.RADIO_VALUE_ACCESSOR]
  132. }),
  133. __metadata("design:paramtypes", [core_1.ChangeDetectorRef])
  134. ], RadioButton);
  135. return RadioButton;
  136. }());
  137. exports.RadioButton = RadioButton;
  138. var RadioButtonModule = /** @class */ (function () {
  139. function RadioButtonModule() {
  140. }
  141. RadioButtonModule = __decorate([
  142. core_1.NgModule({
  143. imports: [common_1.CommonModule],
  144. exports: [RadioButton],
  145. declarations: [RadioButton]
  146. })
  147. ], RadioButtonModule);
  148. return RadioButtonModule;
  149. }());
  150. exports.RadioButtonModule = RadioButtonModule;
  151. //# sourceMappingURL=radiobutton.js.map