UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Join the chat at https://gitter.im/primefaces/primeng](https://badges.gitter.im/primefaces/primeng.svg)](https://gitter.im/primefaces/primeng?ut

201 lines 9.06 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var domhandler_1 = require("../dom/domhandler"); var common_1 = require("@angular/common"); var ButtonDirective = /** @class */ (function () { function ButtonDirective(el, domHandler) { this.el = el; this.domHandler = domHandler; this.iconPos = 'left'; this.cornerStyleClass = 'ui-corner-all'; } ButtonDirective.prototype.ngAfterViewInit = function () { this.domHandler.addMultipleClasses(this.el.nativeElement, this.getStyleClass()); if (this.icon) { var iconElement = document.createElement("span"); iconElement.setAttribute("aria-hidden", "true"); var iconPosClass = (this.iconPos == 'right') ? 'ui-button-icon-right' : 'ui-button-icon-left'; iconElement.className = iconPosClass + ' ui-clickable ' + this.icon; this.el.nativeElement.appendChild(iconElement); } var labelElement = document.createElement("span"); labelElement.className = 'ui-button-text ui-clickable'; labelElement.appendChild(document.createTextNode(this.label || 'ui-btn')); this.el.nativeElement.appendChild(labelElement); this.initialized = true; }; ButtonDirective.prototype.getStyleClass = function () { var styleClass = 'ui-button ui-widget ui-state-default ' + this.cornerStyleClass; if (this.icon) { if (this.label != null && this.label != undefined) { if (this.iconPos == 'left') styleClass = styleClass + ' ui-button-text-icon-left'; else styleClass = styleClass + ' ui-button-text-icon-right'; } else { styleClass = styleClass + ' ui-button-icon-only'; } } else { if (this.label) { styleClass = styleClass + ' ui-button-text-only'; } else { styleClass = styleClass + ' ui-button-text-empty'; } } return styleClass; }; Object.defineProperty(ButtonDirective.prototype, "label", { get: function () { return this._label; }, set: function (val) { this._label = val; if (this.initialized) { this.domHandler.findSingle(this.el.nativeElement, '.ui-button-text').textContent = this._label; if (!this.icon) { if (this._label) { this.domHandler.removeClass(this.el.nativeElement, 'ui-button-text-empty'); this.domHandler.addClass(this.el.nativeElement, 'ui-button-text-only'); } else { this.domHandler.addClass(this.el.nativeElement, 'ui-button-text-empty'); this.domHandler.removeClass(this.el.nativeElement, 'ui-button-text-only'); } } } }, enumerable: true, configurable: true }); Object.defineProperty(ButtonDirective.prototype, "icon", { get: function () { return this._icon; }, set: function (val) { this._icon = val; if (this.initialized) { var iconPosClass = (this.iconPos == 'right') ? 'ui-button-icon-right' : 'ui-button-icon-left'; this.domHandler.findSingle(this.el.nativeElement, '.ui-clickable').className = iconPosClass + ' ui-clickable ' + this.icon; } }, enumerable: true, configurable: true }); ButtonDirective.prototype.ngOnDestroy = function () { while (this.el.nativeElement.hasChildNodes()) { this.el.nativeElement.removeChild(this.el.nativeElement.lastChild); } this.initialized = false; }; __decorate([ core_1.Input(), __metadata("design:type", String) ], ButtonDirective.prototype, "iconPos", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], ButtonDirective.prototype, "cornerStyleClass", void 0); __decorate([ core_1.Input(), __metadata("design:type", String), __metadata("design:paramtypes", [String]) ], ButtonDirective.prototype, "label", null); __decorate([ core_1.Input(), __metadata("design:type", String), __metadata("design:paramtypes", [String]) ], ButtonDirective.prototype, "icon", null); ButtonDirective = __decorate([ core_1.Directive({ selector: '[pButton]', providers: [domhandler_1.DomHandler] }), __metadata("design:paramtypes", [core_1.ElementRef, domhandler_1.DomHandler]) ], ButtonDirective); return ButtonDirective; }()); exports.ButtonDirective = ButtonDirective; var Button = /** @class */ (function () { function Button() { this.iconPos = 'left'; this.onClick = new core_1.EventEmitter(); this.onFocus = new core_1.EventEmitter(); this.onBlur = new core_1.EventEmitter(); } __decorate([ core_1.Input(), __metadata("design:type", String) ], Button.prototype, "type", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], Button.prototype, "iconPos", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], Button.prototype, "icon", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], Button.prototype, "label", void 0); __decorate([ core_1.Input(), __metadata("design:type", Boolean) ], Button.prototype, "disabled", void 0); __decorate([ core_1.Input(), __metadata("design:type", Object) ], Button.prototype, "style", void 0); __decorate([ core_1.Input(), __metadata("design:type", String) ], Button.prototype, "styleClass", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], Button.prototype, "onClick", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], Button.prototype, "onFocus", void 0); __decorate([ core_1.Output(), __metadata("design:type", core_1.EventEmitter) ], Button.prototype, "onBlur", void 0); Button = __decorate([ core_1.Component({ selector: 'p-button', template: "\n <button [attr.type]=\"type\" [class]=\"styleClass\" [style]=\"style\" [disabled]=\"disabled\"\n [ngClass]=\"{'ui-button ui-widget ui-state-default ui-corner-all':true,\n 'ui-button-icon-only': (icon && !label),\n 'ui-button-text-icon-left': (icon && label && iconPos === 'left'),\n 'ui-button-text-icon-right': (icon && label && iconPos === 'right'),\n 'ui-button-text-only': (!icon && label),\n 'ui-button-text-empty': (!icon && !label),\n 'ui-state-disabled': disabled}\"\n (click)=\"onClick.emit($event)\" (focus)=\"onFocus.emit($event)\" (blur)=\"onBlur.emit($event)\">\n <ng-content></ng-content>\n <span [ngClass]=\"{'ui-clickable': true,\n 'ui-button-icon-left': (iconPos === 'left'), \n 'ui-button-icon-right': (iconPos === 'right')}\"\n [class]=\"icon\" *ngIf=\"icon\"></span>\n <span class=\"ui-button-text ui-clickable\">{{label||'ui-btn'}}</span>\n </button>\n " }) ], Button); return Button; }()); exports.Button = Button; var ButtonModule = /** @class */ (function () { function ButtonModule() { } ButtonModule = __decorate([ core_1.NgModule({ imports: [common_1.CommonModule], exports: [ButtonDirective, Button], declarations: [ButtonDirective, Button] }) ], ButtonModule); return ButtonModule; }()); exports.ButtonModule = ButtonModule; //# sourceMappingURL=button.js.map