diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6ebdfc8..23bbd62 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -34,18 +34,7 @@ jobs: HUSKY_SKIP_INSTALL: true run: npm ci - - name: Check Conventional Commits - id: check-commits - run: | - echo "commit_message=$(git log -1 --pretty=%B)" >> $GITHUB_ENV - if [[ ! $commit_message =~ ^(docs|chore|ci)(\(.+\))?:\s.+$ ]]; then - echo "is_conventional=false" >> $GITHUB_ENV - else - echo "is_conventional=true" >> $GITHUB_ENV - fi - - name: Lint - if: env.is_conventional == 'true' run: npm run lint -- @ngxpert/hot-toast - name: Build library @@ -55,7 +44,6 @@ jobs: run: npm run build - name: Test - if: env.is_conventional == 'true' run: npm run test - name: Release diff --git a/CHANGELOG.md b/CHANGELOG.md index ee799c9..e96e000 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## [3.1.1-beta.1](https://github.com/ngxpert/hot-toast/compare/v3.1.0...v3.1.1-beta.1) (2024-12-10) + + +### Bug Fixes + +* use inject function instead of decorator ([9b63e61](https://github.com/ngxpert/hot-toast/commit/9b63e614729d9d1807d13d1c9ee4e409c371ef34)), closes [#22](https://github.com/ngxpert/hot-toast/issues/22) + +# [3.1.0-beta.3](https://github.com/ngxpert/hot-toast/compare/v3.1.0-beta.2...v3.1.0-beta.3) (2024-12-10) + + +### Bug Fixes + +* use inject function instead of decorator ([9b63e61](https://github.com/ngxpert/hot-toast/commit/9b63e614729d9d1807d13d1c9ee4e409c371ef34)), closes [#22](https://github.com/ngxpert/hot-toast/issues/22) + # [3.1.0](https://github.com/ngxpert/hot-toast/compare/v3.0.2...v3.1.0) (2024-12-10) diff --git a/projects/ngxpert/hot-toast/src/lib/components/hot-toast-container/hot-toast-container.component.ts b/projects/ngxpert/hot-toast/src/lib/components/hot-toast-container/hot-toast-container.component.ts index c59db5d..d36eb62 100644 --- a/projects/ngxpert/hot-toast/src/lib/components/hot-toast-container/hot-toast-container.component.ts +++ b/projects/ngxpert/hot-toast/src/lib/components/hot-toast-container/hot-toast-container.component.ts @@ -1,4 +1,12 @@ -import { Component, ChangeDetectionStrategy, ChangeDetectorRef, Input, QueryList, ViewChildren } from '@angular/core'; +import { + Component, + ChangeDetectionStrategy, + inject, + Input, + QueryList, + ViewChildren, + ChangeDetectorRef, +} from '@angular/core'; import { Subject } from 'rxjs'; import { HotToastClose, @@ -46,7 +54,8 @@ export class HotToastContainerComponent { private onGroupToggle$ = this._onGroupToggle.asObservable(); private onGroupRefAttached$ = this._onGroupRefAttached.asObservable(); - constructor(private cdr: ChangeDetectorRef, private toastService: HotToastService) {} + private cdr = inject(ChangeDetectorRef); + private toastService = inject(HotToastService); trackById(index: number, toast: Toast) { return toast.id; @@ -66,18 +75,18 @@ export class HotToastContainerComponent { const visibleToasts = this.getVisibleToasts(position); const index = visibleToasts.findIndex((toast) => toast.id === toastId); const offset = - index !== -1 - ? visibleToasts.slice(...(this.defaultConfig.reverseOrder ? [index + 1] : [0, index])).reduce((acc, t, i) => { - const toastsAfter = visibleToasts.length - 1 - i; - return this.defaultConfig.visibleToasts !== 0 && i < visibleToasts.length - this.defaultConfig.visibleToasts - ? 0 - : acc + - (this.defaultConfig.stacking === 'vertical' || this.isShowingAllToasts - ? t.height || 0 - : toastsAfter * HOT_TOAST_DEPTH_SCALE + HOT_TOAST_DEPTH_SCALE_ADD) + - HOT_TOAST_MARGIN; - }, 0) - : 0; + index !== -1 + ? visibleToasts.slice(...(this.defaultConfig.reverseOrder ? [index + 1] : [0, index])).reduce((acc, t, i) => { + const toastsAfter = visibleToasts.length - 1 - i; + return this.defaultConfig.visibleToasts !== 0 && i < visibleToasts.length - this.defaultConfig.visibleToasts + ? 0 + : acc + + (this.defaultConfig.stacking === 'vertical' || this.isShowingAllToasts + ? t.height || 0 + : toastsAfter * HOT_TOAST_DEPTH_SCALE + HOT_TOAST_DEPTH_SCALE_ADD) + + HOT_TOAST_MARGIN; + }, 0) + : 0; return offset; } diff --git a/projects/ngxpert/hot-toast/src/lib/components/hot-toast-group-item/hot-toast-group-item.component.ts b/projects/ngxpert/hot-toast/src/lib/components/hot-toast-group-item/hot-toast-group-item.component.ts index a7b68bb..7ab77fd 100644 --- a/projects/ngxpert/hot-toast/src/lib/components/hot-toast-group-item/hot-toast-group-item.component.ts +++ b/projects/ngxpert/hot-toast/src/lib/components/hot-toast-group-item/hot-toast-group-item.component.ts @@ -16,6 +16,7 @@ import { OnDestroy, signal, ChangeDetectorRef, + inject, } from '@angular/core'; import { NgClass, NgStyle } from '@angular/common'; import { AnimatedIconComponent } from '../animated-icon/animated-icon.component'; @@ -79,12 +80,10 @@ export class HotToastGroupItemComponent implements OnChanges, OnInit, AfterViewI private unlisteners: VoidFunction[] = []; protected softClosed = false; - constructor( - protected injector: Injector, - protected renderer: Renderer2, - protected ngZone: NgZone, - private cdr: ChangeDetectorRef - ) {} + private injector = inject(Injector); + private renderer = inject(Renderer2); + private ngZone = inject(NgZone); + private cdr = inject(ChangeDetectorRef); get toastBarBaseHeight() { return this.toastBarBase.nativeElement.offsetHeight; diff --git a/projects/ngxpert/hot-toast/src/lib/components/hot-toast/hot-toast.component.ts b/projects/ngxpert/hot-toast/src/lib/components/hot-toast/hot-toast.component.ts index aa90db5..b5ff507 100644 --- a/projects/ngxpert/hot-toast/src/lib/components/hot-toast/hot-toast.component.ts +++ b/projects/ngxpert/hot-toast/src/lib/components/hot-toast/hot-toast.component.ts @@ -6,6 +6,7 @@ import { DoCheck, ElementRef, EventEmitter, + inject, Injector, Input, NgZone, @@ -97,12 +98,10 @@ export class HotToastComponent implements OnInit, AfterViewInit, OnDestroy, OnCh private softClosed = false; private groupRefs: CreateHotToastRef[] = []; - constructor( - private injector: Injector, - private renderer: Renderer2, - private ngZone: NgZone, - private cdr: ChangeDetectorRef - ) {} + private injector = inject(Injector); + private renderer = inject(Renderer2); + private ngZone = inject(NgZone); + private cdr = inject(ChangeDetectorRef); get toastBarBaseHeight() { return this.toastBarBase.nativeElement.offsetHeight; diff --git a/projects/ngxpert/hot-toast/src/lib/hot-toast-builder.ts b/projects/ngxpert/hot-toast/src/lib/hot-toast-builder.ts index ca0c603..5feb234 100644 --- a/projects/ngxpert/hot-toast/src/lib/hot-toast-builder.ts +++ b/projects/ngxpert/hot-toast/src/lib/hot-toast-builder.ts @@ -6,13 +6,11 @@ import { Observable } from 'rxjs'; type ToastMethod = 'show' | 'success' | 'error' | 'warning' | 'info' | 'loading'; export class HotToastBuilder { - private options: ToastOptions; + private options: ToastOptions = {}; private groupChildren: HotToastBuilder[] = []; private toastRef: CreateHotToastRef; - constructor(private message: Content, private service: HotToastService) { - this.options = {}; - } + constructor(private message: Content, private service: HotToastService) {} setOptions(options: ToastOptions): this { this.options = { ...this.options, ...options }; diff --git a/projects/ngxpert/hot-toast/src/lib/hot-toast-ref.ts b/projects/ngxpert/hot-toast/src/lib/hot-toast-ref.ts index 52e17cf..40a27b7 100644 --- a/projects/ngxpert/hot-toast/src/lib/hot-toast-ref.ts +++ b/projects/ngxpert/hot-toast/src/lib/hot-toast-ref.ts @@ -30,8 +30,6 @@ export class HotToastRef implements HotToastRefProps /** Subject for notifying the user that the toast has been closed. */ private _onGroupToggle = new Subject(); - private _componentRef: { changeDetectorRef: { detectChanges: () => void } }; - constructor(private toast: Toast) {} set data(data: DataType) { diff --git a/projects/ngxpert/hot-toast/src/lib/hot-toast.service.ts b/projects/ngxpert/hot-toast/src/lib/hot-toast.service.ts index 7663c71..3cc4d5a 100644 --- a/projects/ngxpert/hot-toast/src/lib/hot-toast.service.ts +++ b/projects/ngxpert/hot-toast/src/lib/hot-toast.service.ts @@ -1,5 +1,5 @@ import { isPlatformServer } from '@angular/common'; -import { Inject, Injectable, Optional, PLATFORM_ID } from '@angular/core'; +import { inject, Injectable, PLATFORM_ID } from '@angular/core'; import { CompRef, Content, isComponent, isTemplateRef, ViewService } from '@ngneat/overview'; import { defer, Observable } from 'rxjs'; import { tap } from 'rxjs/operators'; @@ -33,15 +33,15 @@ export class HotToastService implements HotToastServiceMethods { private _defaultGlobalConfig = new ToastConfig(); private _defaultPersistConfig = new ToastPersistConfig(); - constructor( - private _viewService: ViewService, - @Inject(PLATFORM_ID) private platformId: string, - @Optional() globalConfig: ToastConfig - ) { - if (globalConfig) { + private _viewService = inject(ViewService); + private _platformId = inject(PLATFORM_ID); + private _globalConfig = inject(ToastConfig, { optional: true }); + + constructor() { + if (this._globalConfig) { this._defaultGlobalConfig = { ...this._defaultGlobalConfig, - ...globalConfig, + ...this._globalConfig, }; } } @@ -269,7 +269,7 @@ export class HotToastService implements HotToastServiceMethods { * Creates a container component and attaches it to document.body. */ private init() { - if (isPlatformServer(this.platformId)) { + if (isPlatformServer(this._platformId)) { return; } this._componentRef = this._viewService