ng-prime-tools 1.0.74 → 1.0.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1398,7 +1398,6 @@ class PTButtonComponent {
|
|
|
1398
1398
|
this.el = el;
|
|
1399
1399
|
}
|
|
1400
1400
|
ngOnInit() {
|
|
1401
|
-
// Fallback to default config if undefined
|
|
1402
1401
|
if (!this.buttonConfig) {
|
|
1403
1402
|
this.buttonConfig = {
|
|
1404
1403
|
label: 'Click Me',
|
|
@@ -1419,87 +1418,123 @@ class PTButtonComponent {
|
|
|
1419
1418
|
}
|
|
1420
1419
|
ngOnChanges(changes) {
|
|
1421
1420
|
const configChange = changes['buttonConfig'];
|
|
1422
|
-
if (configChange) {
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
this.applyButtonStyles();
|
|
1434
|
-
}
|
|
1421
|
+
if (!configChange) {
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
const prev = configChange.previousValue;
|
|
1425
|
+
const curr = configChange.currentValue;
|
|
1426
|
+
if (prev && curr) {
|
|
1427
|
+
const onlyDisabledChanged = prev.disabled !== curr.disabled &&
|
|
1428
|
+
JSON.stringify({ ...prev, disabled: undefined }) ===
|
|
1429
|
+
JSON.stringify({ ...curr, disabled: undefined });
|
|
1430
|
+
if (onlyDisabledChanged) {
|
|
1431
|
+
setTimeout(() => this.updateDisabledStyles(curr.disabled ?? false));
|
|
1435
1432
|
}
|
|
1436
1433
|
else {
|
|
1437
|
-
|
|
1438
|
-
this.applyButtonStyles();
|
|
1434
|
+
setTimeout(() => this.applyButtonStyles());
|
|
1439
1435
|
}
|
|
1436
|
+
return;
|
|
1440
1437
|
}
|
|
1438
|
+
setTimeout(() => this.applyButtonStyles());
|
|
1441
1439
|
}
|
|
1442
1440
|
ngAfterViewInit() {
|
|
1443
|
-
this.applyButtonStyles();
|
|
1441
|
+
setTimeout(() => this.applyButtonStyles());
|
|
1444
1442
|
}
|
|
1445
1443
|
getIconPos() {
|
|
1446
|
-
return this.buttonConfig
|
|
1444
|
+
return this.buttonConfig?.iconPos === 'right' ? 'right' : 'left';
|
|
1447
1445
|
}
|
|
1448
1446
|
getType() {
|
|
1449
|
-
return this.buttonConfig
|
|
1447
|
+
return this.buttonConfig?.type || 'button';
|
|
1448
|
+
}
|
|
1449
|
+
hasCustomColors() {
|
|
1450
|
+
return !!(this.buttonConfig?.backgroundColor ||
|
|
1451
|
+
this.buttonConfig?.borderColor ||
|
|
1452
|
+
this.buttonConfig?.fontColor);
|
|
1453
|
+
}
|
|
1454
|
+
getSeverity() {
|
|
1455
|
+
/**
|
|
1456
|
+
* If custom colors are provided, do not pass PrimeNG severity.
|
|
1457
|
+
* PrimeNG severity classes can override custom background/border colors.
|
|
1458
|
+
*/
|
|
1459
|
+
if (this.hasCustomColors()) {
|
|
1460
|
+
return undefined;
|
|
1461
|
+
}
|
|
1462
|
+
return this.buttonConfig?.severity;
|
|
1463
|
+
}
|
|
1464
|
+
getStyleClass() {
|
|
1465
|
+
const classes = [];
|
|
1466
|
+
if (this.buttonConfig?.styleClass) {
|
|
1467
|
+
classes.push(this.buttonConfig.styleClass);
|
|
1468
|
+
}
|
|
1469
|
+
if (this.hasCustomColors()) {
|
|
1470
|
+
classes.push('pt-custom-colored-button');
|
|
1471
|
+
}
|
|
1472
|
+
return classes.join(' ');
|
|
1450
1473
|
}
|
|
1451
1474
|
updateDisabledStyles(isDisabled) {
|
|
1452
|
-
const buttonElement = this.
|
|
1453
|
-
if (buttonElement) {
|
|
1454
|
-
|
|
1455
|
-
this.renderer.setStyle(buttonElement, 'background-color', isDisabled ? '#e0e0e0' : this.buttonConfig.backgroundColor);
|
|
1456
|
-
this.renderer.setStyle(buttonElement, 'border-color', isDisabled ? '#bdbdbd' : this.buttonConfig.borderColor);
|
|
1475
|
+
const buttonElement = this.getButtonElement();
|
|
1476
|
+
if (!buttonElement || !this.buttonConfig) {
|
|
1477
|
+
return;
|
|
1457
1478
|
}
|
|
1479
|
+
if (this.hasCustomColors()) {
|
|
1480
|
+
this.renderer.setStyle(buttonElement, 'color', isDisabled ? '#999' : this.buttonConfig.fontColor || '#ffffff');
|
|
1481
|
+
this.renderer.setStyle(buttonElement, 'background-color', isDisabled
|
|
1482
|
+
? '#e0e0e0'
|
|
1483
|
+
: this.buttonConfig.backgroundColor || 'transparent');
|
|
1484
|
+
this.renderer.setStyle(buttonElement, 'border-color', isDisabled
|
|
1485
|
+
? '#bdbdbd'
|
|
1486
|
+
: this.buttonConfig.borderColor ||
|
|
1487
|
+
this.buttonConfig.backgroundColor ||
|
|
1488
|
+
'transparent');
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
this.renderer.removeStyle(buttonElement, 'color');
|
|
1492
|
+
this.renderer.removeStyle(buttonElement, 'background-color');
|
|
1493
|
+
this.renderer.removeStyle(buttonElement, 'border-color');
|
|
1458
1494
|
}
|
|
1459
1495
|
/**
|
|
1460
|
-
* We delegate colors to PrimeNG theme when
|
|
1461
|
-
* - outlined = true
|
|
1462
|
-
* - and no manual color is provided (no backgroundColor, borderColor, fontColor)
|
|
1496
|
+
* We delegate colors to PrimeNG theme when no manual color is provided.
|
|
1463
1497
|
*/
|
|
1464
1498
|
shouldUseThemeColors() {
|
|
1465
|
-
|
|
1466
|
-
return false;
|
|
1467
|
-
}
|
|
1468
|
-
const outlined = !!this.buttonConfig.outlined; // ✅ coerce to boolean
|
|
1469
|
-
return (outlined &&
|
|
1470
|
-
!this.buttonConfig.backgroundColor &&
|
|
1471
|
-
!this.buttonConfig.borderColor &&
|
|
1472
|
-
!this.buttonConfig.fontColor);
|
|
1499
|
+
return !this.hasCustomColors();
|
|
1473
1500
|
}
|
|
1474
1501
|
applyButtonStyles() {
|
|
1475
|
-
const buttonElement = this.
|
|
1502
|
+
const buttonElement = this.getButtonElement();
|
|
1476
1503
|
if (!buttonElement || !this.buttonConfig) {
|
|
1477
1504
|
return;
|
|
1478
1505
|
}
|
|
1479
1506
|
const isDisabled = !!this.buttonConfig.disabled;
|
|
1480
1507
|
const useThemeColors = this.shouldUseThemeColors();
|
|
1481
|
-
// Width / height always applied
|
|
1482
1508
|
this.renderer.setStyle(buttonElement, 'width', this.buttonConfig.width || 'auto');
|
|
1483
1509
|
this.renderer.setStyle(buttonElement, 'height', this.buttonConfig.height || 'auto');
|
|
1484
|
-
// ✅ Only override colors when we are NOT delegating to PrimeNG theme
|
|
1485
1510
|
if (!useThemeColors) {
|
|
1486
|
-
this.renderer.setStyle(buttonElement, 'color', isDisabled ? '#999' : this.buttonConfig.fontColor);
|
|
1487
|
-
this.renderer.setStyle(buttonElement, 'background-color', isDisabled
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1511
|
+
this.renderer.setStyle(buttonElement, 'color', isDisabled ? '#999' : this.buttonConfig.fontColor || '#ffffff');
|
|
1512
|
+
this.renderer.setStyle(buttonElement, 'background-color', isDisabled
|
|
1513
|
+
? '#e0e0e0'
|
|
1514
|
+
: this.buttonConfig.backgroundColor || 'transparent');
|
|
1515
|
+
this.renderer.setStyle(buttonElement, 'border-color', isDisabled
|
|
1516
|
+
? '#bdbdbd'
|
|
1517
|
+
: this.buttonConfig.borderColor ||
|
|
1518
|
+
this.buttonConfig.backgroundColor ||
|
|
1519
|
+
'transparent');
|
|
1520
|
+
return;
|
|
1495
1521
|
}
|
|
1522
|
+
this.renderer.removeStyle(buttonElement, 'color');
|
|
1523
|
+
this.renderer.removeStyle(buttonElement, 'background-color');
|
|
1524
|
+
this.renderer.removeStyle(buttonElement, 'border-color');
|
|
1525
|
+
}
|
|
1526
|
+
getButtonElement() {
|
|
1527
|
+
return (this.el.nativeElement.querySelector('button.p-button') ||
|
|
1528
|
+
this.el.nativeElement.querySelector('button.p-element') ||
|
|
1529
|
+
this.el.nativeElement.querySelector('.p-button') ||
|
|
1530
|
+
this.el.nativeElement.querySelector('button'));
|
|
1496
1531
|
}
|
|
1497
1532
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: PTButtonComponent, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
1498
|
-
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.14", type: PTButtonComponent, isStandalone: false, selector: "pt-button", inputs: { buttonConfig: "buttonConfig" }, usesOnChanges: true, ngImport: i0, template: "<p-button\n [label]=\"buttonConfig.label\"\n [icon]=\"buttonConfig.icon || ''\"\n [iconPos]=\"getIconPos()\"\n [disabled]=\"buttonConfig.disabled\"\n [loading]=\"buttonConfig.loading\"\n [
|
|
1533
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.14", type: PTButtonComponent, isStandalone: false, selector: "pt-button", inputs: { buttonConfig: "buttonConfig" }, usesOnChanges: true, ngImport: i0, template: "<p-button\n [label]=\"buttonConfig.label\"\n [icon]=\"buttonConfig.icon || ''\"\n [iconPos]=\"getIconPos()\"\n [disabled]=\"buttonConfig.disabled\"\n [loading]=\"buttonConfig.loading\"\n [styleClass]=\"getStyleClass()\"\n [type]=\"getType()\"\n [severity]=\"getSeverity()\"\n [outlined]=\"buttonConfig.outlined\"\n></p-button>\n", styles: [":host{display:inline-block}:host ::ng-deep p-button{display:block}:host ::ng-deep .pt-custom-colored-button.p-button{box-shadow:none}:host ::ng-deep .pt-custom-colored-button.p-button:hover:not(:disabled){filter:brightness(.95)}:host ::ng-deep .pt-custom-colored-button.p-button:disabled{filter:none;cursor:not-allowed}\n"], dependencies: [{ kind: "component", type: i6.Button, selector: "p-button", inputs: ["hostName", "type", "badge", "disabled", "raised", "rounded", "text", "plain", "outlined", "link", "tabindex", "size", "variant", "style", "styleClass", "badgeClass", "badgeSeverity", "ariaLabel", "autofocus", "iconPos", "icon", "label", "loading", "loadingIcon", "severity", "buttonProps", "fluid"], outputs: ["onClick", "onFocus", "onBlur"] }] }); }
|
|
1499
1534
|
}
|
|
1500
1535
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.14", ngImport: i0, type: PTButtonComponent, decorators: [{
|
|
1501
1536
|
type: Component,
|
|
1502
|
-
args: [{ selector: 'pt-button', standalone: false, template: "<p-button\n [label]=\"buttonConfig.label\"\n [icon]=\"buttonConfig.icon || ''\"\n [iconPos]=\"getIconPos()\"\n [disabled]=\"buttonConfig.disabled\"\n [loading]=\"buttonConfig.loading\"\n [
|
|
1537
|
+
args: [{ selector: 'pt-button', standalone: false, template: "<p-button\n [label]=\"buttonConfig.label\"\n [icon]=\"buttonConfig.icon || ''\"\n [iconPos]=\"getIconPos()\"\n [disabled]=\"buttonConfig.disabled\"\n [loading]=\"buttonConfig.loading\"\n [styleClass]=\"getStyleClass()\"\n [type]=\"getType()\"\n [severity]=\"getSeverity()\"\n [outlined]=\"buttonConfig.outlined\"\n></p-button>\n", styles: [":host{display:inline-block}:host ::ng-deep p-button{display:block}:host ::ng-deep .pt-custom-colored-button.p-button{box-shadow:none}:host ::ng-deep .pt-custom-colored-button.p-button:hover:not(:disabled){filter:brightness(.95)}:host ::ng-deep .pt-custom-colored-button.p-button:disabled{filter:none;cursor:not-allowed}\n"] }]
|
|
1503
1538
|
}], ctorParameters: () => [{ type: i0.Renderer2 }, { type: i0.ElementRef }], propDecorators: { buttonConfig: [{
|
|
1504
1539
|
type: Input
|
|
1505
1540
|
}] } });
|