You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
282 lines
13 KiB
282 lines
13 KiB
import * as i0 from '@angular/core';
|
|
import { Directive, Input, EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, ContentChildren, Output, NgModule } from '@angular/core';
|
|
import { DomHandler } from 'primeng/dom';
|
|
import * as i2 from '@angular/common';
|
|
import { CommonModule } from '@angular/common';
|
|
import * as i1 from 'primeng/ripple';
|
|
import { RippleModule } from 'primeng/ripple';
|
|
import { PrimeTemplate } from 'primeng/api';
|
|
|
|
class ButtonDirective {
|
|
constructor(el) {
|
|
this.el = el;
|
|
this.iconPos = 'left';
|
|
this.loadingIcon = "pi pi-spinner pi-spin";
|
|
this._loading = false;
|
|
}
|
|
ngAfterViewInit() {
|
|
this._initialStyleClass = this.el.nativeElement.className;
|
|
DomHandler.addMultipleClasses(this.el.nativeElement, this.getStyleClass());
|
|
if (this.icon || this.loading) {
|
|
this.createIconEl();
|
|
}
|
|
let labelElement = document.createElement("span");
|
|
if (this.icon && !this.label) {
|
|
labelElement.setAttribute('aria-hidden', 'true');
|
|
}
|
|
labelElement.className = 'p-button-label';
|
|
if (this.label)
|
|
labelElement.appendChild(document.createTextNode(this.label));
|
|
else
|
|
labelElement.innerHTML = ' ';
|
|
this.el.nativeElement.appendChild(labelElement);
|
|
this.initialized = true;
|
|
}
|
|
getStyleClass() {
|
|
let styleClass = 'p-button p-component';
|
|
if (this.icon && !this.label) {
|
|
styleClass = styleClass + ' p-button-icon-only';
|
|
}
|
|
if (this.loading) {
|
|
styleClass = styleClass + ' p-disabled p-button-loading';
|
|
if (!this.icon && this.label)
|
|
styleClass = styleClass + ' p-button-loading-label-only';
|
|
}
|
|
return styleClass;
|
|
}
|
|
setStyleClass() {
|
|
let styleClass = this.getStyleClass();
|
|
this.el.nativeElement.className = styleClass + ' ' + this._initialStyleClass;
|
|
}
|
|
createIconEl() {
|
|
let iconElement = document.createElement("span");
|
|
iconElement.className = 'p-button-icon';
|
|
iconElement.setAttribute("aria-hidden", "true");
|
|
let iconPosClass = this.label ? 'p-button-icon-' + this.iconPos : null;
|
|
if (iconPosClass) {
|
|
DomHandler.addClass(iconElement, iconPosClass);
|
|
}
|
|
let iconClass = this.getIconClass();
|
|
if (iconClass) {
|
|
DomHandler.addMultipleClasses(iconElement, iconClass);
|
|
}
|
|
let labelEl = DomHandler.findSingle(this.el.nativeElement, '.p-button-label');
|
|
if (labelEl)
|
|
this.el.nativeElement.insertBefore(iconElement, labelEl);
|
|
else
|
|
this.el.nativeElement.appendChild(iconElement);
|
|
}
|
|
getIconClass() {
|
|
return this.loading ? 'p-button-loading-icon ' + this.loadingIcon : this._icon;
|
|
}
|
|
setIconClass() {
|
|
let iconElement = DomHandler.findSingle(this.el.nativeElement, '.p-button-icon');
|
|
if (iconElement) {
|
|
if (this.iconPos)
|
|
iconElement.className = 'p-button-icon p-button-icon-' + this.iconPos + ' ' + this.getIconClass();
|
|
else
|
|
iconElement.className = 'p-button-icon ' + this.getIconClass();
|
|
}
|
|
else {
|
|
this.createIconEl();
|
|
}
|
|
}
|
|
removeIconElement() {
|
|
let iconElement = DomHandler.findSingle(this.el.nativeElement, '.p-button-icon');
|
|
this.el.nativeElement.removeChild(iconElement);
|
|
}
|
|
get label() {
|
|
return this._label;
|
|
}
|
|
set label(val) {
|
|
this._label = val;
|
|
if (this.initialized) {
|
|
DomHandler.findSingle(this.el.nativeElement, '.p-button-label').textContent = this._label || ' ';
|
|
if (this.loading || this.icon) {
|
|
this.setIconClass();
|
|
}
|
|
this.setStyleClass();
|
|
}
|
|
}
|
|
get icon() {
|
|
return this._icon;
|
|
}
|
|
set icon(val) {
|
|
this._icon = val;
|
|
if (this.initialized) {
|
|
this.setIconClass();
|
|
this.setStyleClass();
|
|
}
|
|
}
|
|
get loading() {
|
|
return this._loading;
|
|
}
|
|
set loading(val) {
|
|
this._loading = val;
|
|
if (this.initialized) {
|
|
if (this.loading || this.icon)
|
|
this.setIconClass();
|
|
else
|
|
this.removeIconElement();
|
|
this.setStyleClass();
|
|
}
|
|
}
|
|
ngOnDestroy() {
|
|
this.initialized = false;
|
|
}
|
|
}
|
|
ButtonDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: ButtonDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
ButtonDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.0.3", type: ButtonDirective, selector: "[pButton]", inputs: { iconPos: "iconPos", loadingIcon: "loadingIcon", label: "label", icon: "icon", loading: "loading" }, host: { classAttribute: "p-element" }, ngImport: i0 });
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: ButtonDirective, decorators: [{
|
|
type: Directive,
|
|
args: [{
|
|
selector: '[pButton]',
|
|
host: {
|
|
'class': 'p-element'
|
|
}
|
|
}]
|
|
}], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { iconPos: [{
|
|
type: Input
|
|
}], loadingIcon: [{
|
|
type: Input
|
|
}], label: [{
|
|
type: Input
|
|
}], icon: [{
|
|
type: Input
|
|
}], loading: [{
|
|
type: Input
|
|
}] } });
|
|
class Button {
|
|
constructor() {
|
|
this.type = "button";
|
|
this.iconPos = 'left';
|
|
this.loading = false;
|
|
this.loadingIcon = "pi pi-spinner pi-spin";
|
|
this.onClick = new EventEmitter();
|
|
this.onFocus = new EventEmitter();
|
|
this.onBlur = new EventEmitter();
|
|
}
|
|
ngAfterContentInit() {
|
|
this.templates.forEach((item) => {
|
|
switch (item.getType()) {
|
|
case 'content':
|
|
this.contentTemplate = item.template;
|
|
break;
|
|
default:
|
|
this.contentTemplate = item.template;
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
badgeStyleClass() {
|
|
return {
|
|
'p-badge p-component': true,
|
|
'p-badge-no-gutter': this.badge && String(this.badge).length === 1
|
|
};
|
|
}
|
|
}
|
|
Button.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: Button, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
Button.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.3", type: Button, selector: "p-button", inputs: { type: "type", iconPos: "iconPos", icon: "icon", badge: "badge", label: "label", disabled: "disabled", loading: "loading", loadingIcon: "loadingIcon", style: "style", styleClass: "styleClass", badgeClass: "badgeClass" }, outputs: { onClick: "onClick", onFocus: "onFocus", onBlur: "onBlur" }, host: { classAttribute: "p-element" }, queries: [{ propertyName: "templates", predicate: PrimeTemplate }], ngImport: i0, template: `
|
|
<button [attr.type]="type" [class]="styleClass" [ngStyle]="style" [disabled]="disabled || loading"
|
|
[ngClass]="{'p-button p-component':true,
|
|
'p-button-icon-only': (icon && !label),
|
|
'p-button-vertical': (iconPos === 'top' || iconPos === 'bottom') && label,
|
|
'p-disabled': this.disabled || this.loading,
|
|
'p-button-loading': this.loading,
|
|
'p-button-loading-label-only': this.loading && !this.icon && this.label}"
|
|
(click)="onClick.emit($event)" (focus)="onFocus.emit($event)" (blur)="onBlur.emit($event)" pRipple>
|
|
<ng-content></ng-content>
|
|
<ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
|
|
<span [ngClass]="{'p-button-icon': true,
|
|
'p-button-icon-left': iconPos === 'left' && label,
|
|
'p-button-icon-right': iconPos === 'right' && label,
|
|
'p-button-icon-top': iconPos === 'top' && label,
|
|
'p-button-icon-bottom': iconPos === 'bottom' && label}"
|
|
[class]="loading ? 'p-button-loading-icon ' + loadingIcon : icon" *ngIf="!contentTemplate && (icon||loading)" [attr.aria-hidden]="true"></span>
|
|
<span class="p-button-label" [attr.aria-hidden]="icon && !label" *ngIf="!contentTemplate">{{label||' '}}</span>
|
|
<span [ngClass]="badgeStyleClass()" [class]="badgeClass" *ngIf="!contentTemplate && badge">{{badge}}</span>
|
|
</button>
|
|
`, isInline: true, directives: [{ type: i1.Ripple, selector: "[pRipple]" }, { type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }, { type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: Button, decorators: [{
|
|
type: Component,
|
|
args: [{
|
|
selector: 'p-button',
|
|
template: `
|
|
<button [attr.type]="type" [class]="styleClass" [ngStyle]="style" [disabled]="disabled || loading"
|
|
[ngClass]="{'p-button p-component':true,
|
|
'p-button-icon-only': (icon && !label),
|
|
'p-button-vertical': (iconPos === 'top' || iconPos === 'bottom') && label,
|
|
'p-disabled': this.disabled || this.loading,
|
|
'p-button-loading': this.loading,
|
|
'p-button-loading-label-only': this.loading && !this.icon && this.label}"
|
|
(click)="onClick.emit($event)" (focus)="onFocus.emit($event)" (blur)="onBlur.emit($event)" pRipple>
|
|
<ng-content></ng-content>
|
|
<ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
|
|
<span [ngClass]="{'p-button-icon': true,
|
|
'p-button-icon-left': iconPos === 'left' && label,
|
|
'p-button-icon-right': iconPos === 'right' && label,
|
|
'p-button-icon-top': iconPos === 'top' && label,
|
|
'p-button-icon-bottom': iconPos === 'bottom' && label}"
|
|
[class]="loading ? 'p-button-loading-icon ' + loadingIcon : icon" *ngIf="!contentTemplate && (icon||loading)" [attr.aria-hidden]="true"></span>
|
|
<span class="p-button-label" [attr.aria-hidden]="icon && !label" *ngIf="!contentTemplate">{{label||' '}}</span>
|
|
<span [ngClass]="badgeStyleClass()" [class]="badgeClass" *ngIf="!contentTemplate && badge">{{badge}}</span>
|
|
</button>
|
|
`,
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
encapsulation: ViewEncapsulation.None,
|
|
host: {
|
|
'class': 'p-element'
|
|
}
|
|
}]
|
|
}], propDecorators: { type: [{
|
|
type: Input
|
|
}], iconPos: [{
|
|
type: Input
|
|
}], icon: [{
|
|
type: Input
|
|
}], badge: [{
|
|
type: Input
|
|
}], label: [{
|
|
type: Input
|
|
}], disabled: [{
|
|
type: Input
|
|
}], loading: [{
|
|
type: Input
|
|
}], loadingIcon: [{
|
|
type: Input
|
|
}], style: [{
|
|
type: Input
|
|
}], styleClass: [{
|
|
type: Input
|
|
}], badgeClass: [{
|
|
type: Input
|
|
}], templates: [{
|
|
type: ContentChildren,
|
|
args: [PrimeTemplate]
|
|
}], onClick: [{
|
|
type: Output
|
|
}], onFocus: [{
|
|
type: Output
|
|
}], onBlur: [{
|
|
type: Output
|
|
}] } });
|
|
class ButtonModule {
|
|
}
|
|
ButtonModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: ButtonModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
ButtonModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: ButtonModule, declarations: [ButtonDirective, Button], imports: [CommonModule, RippleModule], exports: [ButtonDirective, Button] });
|
|
ButtonModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: ButtonModule, imports: [[CommonModule, RippleModule]] });
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.3", ngImport: i0, type: ButtonModule, decorators: [{
|
|
type: NgModule,
|
|
args: [{
|
|
imports: [CommonModule, RippleModule],
|
|
exports: [ButtonDirective, Button],
|
|
declarations: [ButtonDirective, Button]
|
|
}]
|
|
}] });
|
|
|
|
/**
|
|
* Generated bundle index. Do not edit.
|
|
*/
|
|
|
|
export { Button, ButtonDirective, ButtonModule };
|
|
//# sourceMappingURL=primeng-button.mjs.map
|