Skip to content

Commit

Permalink
Revert "Fixed #14286 - Add missing icon template"
Browse files Browse the repository at this point in the history
This reverts commit 09e5249.
  • Loading branch information
cetincakiroglu committed Dec 7, 2023
1 parent 09e5249 commit 02176f1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 45 deletions.
19 changes: 0 additions & 19 deletions src/app/components/togglebutton/togglebutton.interface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { TemplateRef } from '@angular/core';
import { ToggleButton } from './togglebutton';

/**
* Custom change event.
* @see {@link ToggleButton.onChange}
Expand All @@ -16,20 +14,3 @@ export interface ToggleButtonChangeEvent {
*/
checked: boolean | undefined;
}

/**
* Defines valid templates in ToggleButton.
* @group Templates
*/
export interface ToggleButtonTemplates {
/**
* Custom icon template.
* @param {boolean} context - checked state as boolean.
*/
icon(context: {
/**
* Checked.
*/
$implicit: boolean;
}): TemplateRef<{ $implicit: boolean }>;
}
29 changes: 3 additions & 26 deletions src/app/components/togglebutton/togglebutton.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { CommonModule } from '@angular/common';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChildren, EventEmitter, forwardRef, Input, NgModule, Output, QueryList, TemplateRef } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, forwardRef, Input, NgModule, Output } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { RippleModule } from 'primeng/ripple';
import { ToggleButtonChangeEvent } from './togglebutton.interface';
import { Nullable } from 'primeng/ts-helpers';
import { PrimeTemplate, SharedModule } from 'primeng/api';

type ToggleButtonIconPosition = 'left' | 'right';

Expand Down Expand Up @@ -35,16 +33,12 @@ export const TOGGLEBUTTON_VALUE_ACCESSOR: any = {
[attr.data-pc-name]="'togglebutton'"
[attr.data-pc-section]="'root'"
>
@if(!iconTemplate) {
<span
*ngIf="onIcon || offIcon"
[class]="checked ? this.onIcon : this.offIcon"
[ngClass]="{ 'p-button-icon': true, 'p-button-icon-left': iconPos === 'left', 'p-button-icon-right': iconPos === 'right' }"
[attr.data-pc-section]="'icon'"
></span>
} @else {
<ng-container *ngTemplateOutlet="iconTemplate; context: { $implicit: checked }"></ng-container>
}
<span class="p-button-label" *ngIf="onLabel || offLabel" [attr.data-pc-section]="'label'">{{ checked ? (hasOnLabel ? onLabel : '') : hasOffLabel ? offLabel : '' }}</span>
</div>
`,
Expand Down Expand Up @@ -123,10 +117,6 @@ export class ToggleButton implements ControlValueAccessor {
*/
@Output() onChange: EventEmitter<ToggleButtonChangeEvent> = new EventEmitter<ToggleButtonChangeEvent>();

@ContentChildren(PrimeTemplate) templates!: QueryList<PrimeTemplate>;

iconTemplate: Nullable<TemplateRef<any>>;

checked: boolean = false;

onModelChange: Function = () => {};
Expand All @@ -135,19 +125,6 @@ export class ToggleButton implements ControlValueAccessor {

constructor(public cd: ChangeDetectorRef) {}

ngAfterContentInit() {
this.templates.forEach((item) => {
switch (item.getType()) {
case 'icon':
this.iconTemplate = item.template;
break;
default:
this.iconTemplate = item.template;
break;
}
});
}

toggle(event: Event) {
if (!this.disabled) {
this.checked = !this.checked;
Expand Down Expand Up @@ -207,8 +184,8 @@ export class ToggleButton implements ControlValueAccessor {
}

@NgModule({
imports: [CommonModule, RippleModule, SharedModule],
exports: [ToggleButton, SharedModule],
imports: [CommonModule, RippleModule],
exports: [ToggleButton],
declarations: [ToggleButton]
})
export class ToggleButtonModule {}

1 comment on commit 02176f1

@vercel
Copy link

@vercel vercel bot commented on 02176f1 Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

primeng – ./

primeng-git-prod-primetek.vercel.app
primeng-primetek.vercel.app
primeng.org

Please sign in to comment.