diff --git a/apps/docs/src/app/app.component.ts b/apps/docs/src/app/app.component.ts index 9d36a8e..59acb6a 100644 --- a/apps/docs/src/app/app.component.ts +++ b/apps/docs/src/app/app.component.ts @@ -36,15 +36,9 @@ import { UsageComponent } from './components/usage.component'; - - - + + + diff --git a/apps/docs/src/app/components/expand.component.ts b/apps/docs/src/app/components/expand.component.ts index 8f91712..bf67e70 100644 --- a/apps/docs/src/app/components/expand.component.ts +++ b/apps/docs/src/app/components/expand.component.ts @@ -2,9 +2,7 @@ import { ChangeDetectionStrategy, Component, computed, - EventEmitter, - input, - Output, + model, } from '@angular/core'; import { toast } from 'ngx-sonner'; import { CodeBlockComponent } from './code-block.component'; @@ -41,8 +39,7 @@ import { CodeBlockComponent } from './code-block.component'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class ExpandComponent { - expand = input.required(); - @Output() expandChange = new EventEmitter(); + expand = model.required(); expandSnippet = computed( () => `` @@ -52,13 +49,13 @@ export class ExpandComponent { toast('Event has been created', { description: 'Monday, January 3rd at 6:00pm', }); - this.expandChange.emit(true); + this.expand.set(true); } collapseToasts() { toast('Event has been created', { description: 'Monday, January 3rd at 6:00pm', }); - this.expandChange.emit(false); + this.expand.set(false); } } diff --git a/apps/docs/src/app/components/other.component.ts b/apps/docs/src/app/components/other.component.ts index 15ea4ba..a3e4c1b 100644 --- a/apps/docs/src/app/components/other.component.ts +++ b/apps/docs/src/app/components/other.component.ts @@ -2,9 +2,7 @@ import { ChangeDetectionStrategy, Component, computed, - EventEmitter, - input, - Output, + model, signal, } from '@angular/core'; import { toast } from 'ngx-sonner'; @@ -39,11 +37,8 @@ import { TestComponent } from './test.component'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class OtherComponent { - closeButton = input.required(); - @Output() closeButtonChange = new EventEmitter(); - - richColors = input.required(); - @Output() richColorsChange = new EventEmitter(); + closeButton = model.required(); + richColors = model.required(); allTypes = [ { @@ -51,7 +46,7 @@ export class OtherComponent { snippet: "toast.success('Event has been created')", action: () => { toast.success('Event has been created'); - this.richColorsChange.emit(true); + this.richColors.set(true); }, }, { @@ -59,7 +54,7 @@ export class OtherComponent { snippet: "toast.error('Event has not been created')", action: () => { toast.error('Event has not been created'); - this.richColorsChange.emit(true); + this.richColors.set(true); }, }, { @@ -67,7 +62,7 @@ export class OtherComponent { snippet: "toast.info('Info')", action: () => { toast.info('Be at the area 10 minutes before the event time'); - this.richColorsChange.emit(true); + this.richColors.set(true); }, }, { @@ -75,7 +70,7 @@ export class OtherComponent { snippet: "toast.warning('Warning')", action: () => { toast.warning('Event start time cannot be earlier than 8am'); - this.richColorsChange.emit(true); + this.richColors.set(true); }, }, { @@ -87,7 +82,7 @@ export class OtherComponent { toast('Event has been created', { description: 'Monday, January 3rd at 6:00pm', }); - this.closeButtonChange.emit(!this.closeButton()); + this.closeButton.set(!this.closeButton()); }, }, { diff --git a/apps/docs/src/app/components/position.component.ts b/apps/docs/src/app/components/position.component.ts index 7ba1054..2d48bf1 100644 --- a/apps/docs/src/app/components/position.component.ts +++ b/apps/docs/src/app/components/position.component.ts @@ -2,13 +2,22 @@ import { ChangeDetectionStrategy, Component, computed, - EventEmitter, - input, - Output, + model, } from '@angular/core'; import { toast } from 'ngx-sonner'; import { CodeBlockComponent } from './code-block.component'; +const positions = [ + 'top-left', + 'top-center', + 'top-right', + 'bottom-left', + 'bottom-center', + 'bottom-right', +] as const; + +type Position = (typeof positions)[number]; + @Component({ selector: 'docs-position', standalone: true, @@ -33,36 +42,26 @@ import { CodeBlockComponent } from './code-block.component'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class PositionComponent { - positions = [ - 'top-left', - 'top-center', - 'top-right', - 'bottom-left', - 'bottom-center', - 'bottom-right', - ] as const; - - position = input.required<(typeof this.positions)[number]>(); + protected positions = positions; - @Output() positionChange = new EventEmitter< - (typeof this.positions)[number] - >(); + position = model.required(); positionSnippet = computed( () => `` ); - showToast(position: (typeof this.positions)[number]) { + showToast(position: Position) { const toastsAmount = document.querySelectorAll( '[data-sonner-toast]' ).length; - this.positionChange.emit(position); // No need to show a toast when there is already one - if (toastsAmount > 0 && position !== this.position()) return; + if (toastsAmount === 0 || position === this.position()) { + toast('Event has been created', { + description: 'Monday, January 3rd at 6:00pm', + }); + } - toast('Event has been created', { - description: 'Monday, January 3rd at 6:00pm', - }); + this.position.set(position); } } diff --git a/apps/docs/src/app/components/test.component.ts b/apps/docs/src/app/components/test.component.ts index fdc3453..3f302e1 100644 --- a/apps/docs/src/app/components/test.component.ts +++ b/apps/docs/src/app/components/test.component.ts @@ -1,9 +1,8 @@ import { ChangeDetectionStrategy, Component, - EventEmitter, input, - Output, + output, } from '@angular/core'; @Component({ @@ -75,5 +74,5 @@ import { }) export class TestComponent { eventName = input.required(); - @Output() closeToast = new EventEmitter(); + closeToast = output(); }