Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tutkli/ngx-sonner
Browse files Browse the repository at this point in the history
  • Loading branch information
tutkli committed Apr 1, 2024
2 parents 7111cb8 + 69de492 commit d59d767
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 91 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## [0.4.0](https://github.com/tutkli/ngx-sonner/compare/v0.3.4...v0.4.0) (2024-04-01)


### Features

* use new signal queries ([#4](https://github.com/tutkli/ngx-sonner/issues/4)) ([bde803e](https://github.com/tutkli/ngx-sonner/commit/bde803efb543fbbbc4a812d6ebc19d4c595cd04a))


### Bug Fixes

* blurry toasts ([#6](https://github.com/tutkli/ngx-sonner/issues/6)) ([5ba650c](https://github.com/tutkli/ngx-sonner/commit/5ba650c58ecf1fa1f839c85fe0ebe5e825a72f65))
* preserve heights order when adding new toasts ([#8](https://github.com/tutkli/ngx-sonner/issues/8)) ([c7775a2](https://github.com/tutkli/ngx-sonner/commit/c7775a20f165bc39575afd599004e6cb3787859a))


### Chores

* remove nx cloud ([fe4a4d1](https://github.com/tutkli/ngx-sonner/commit/fe4a4d19c9b9d97f4af096e5bb909f04b0b0a777))
* sync package-lock.json ([ead7f75](https://github.com/tutkli/ngx-sonner/commit/ead7f7597326b1f2ea166fab1fa4efe1821831f8))
* sync package-lock.json ([bcf2f46](https://github.com/tutkli/ngx-sonner/commit/bcf2f468815d1974e621d4fd9e8918a39a8a0334))
* update nx ([ddc83fa](https://github.com/tutkli/ngx-sonner/commit/ddc83fa76da51f9d85dd4c2aa7eeb1cf8c1f029f))

## [0.3.4](https://github.com/tutkli/ngx-sonner/compare/v0.3.3...v0.3.4) (2024-03-07)


Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Based on [emilkowalski](https://github.com/emilkowalski)'s React [implementation

## Angular compatibility

Make sure you are using Angular v17.2.0 or greater
Make sure you are using Angular v17.3.0 or greater

## Quick start

Expand Down
12 changes: 3 additions & 9 deletions apps/docs/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,9 @@ import { UsageComponent } from './components/usage.component';
<docs-installation />
<docs-usage />
<docs-types />
<docs-position
[position]="position()"
(positionChange)="position.set($event)" />
<docs-expand [expand]="expand()" (expandChange)="expand.set($event)" />
<docs-other
[richColors]="richColors()"
(richColorsChange)="richColors.set($event)"
[closeButton]="closeButton()"
(closeButtonChange)="closeButton.set($event)" />
<docs-position [(position)]="position" />
<docs-expand [(expand)]="expand" />
<docs-other [(richColors)]="richColors" [(closeButton)]="closeButton" />
</div>
</main>
<docs-footer />
Expand Down
8 changes: 3 additions & 5 deletions apps/docs/src/app/components/code-block.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
inject,
input,
signal,
ViewChild,
viewChild,
} from '@angular/core';
import hljs from 'highlight.js/lib/core';
import javascript from 'highlight.js/lib/languages/javascript';
Expand Down Expand Up @@ -138,7 +138,7 @@ export class CodeBlockComponent {
code = input.required<string>();
_class = input<string>('', { alias: 'class' });

@ViewChild('codeElement') codeElement!: ElementRef<HTMLElement>;
codeElement = viewChild.required<ElementRef<HTMLElement>>('codeElement');

copying = signal(false);
cannotDetectLanguage = computed(
Expand Down Expand Up @@ -168,9 +168,7 @@ export class CodeBlockComponent {

constructor() {
effect(() => {
if (this.codeElement?.nativeElement) {
this.codeElement.nativeElement.innerHTML = this.highlightedCode();
}
this.codeElement().nativeElement.innerHTML = this.highlightedCode();
});
}

Expand Down
11 changes: 4 additions & 7 deletions apps/docs/src/app/components/expand.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -41,8 +39,7 @@ import { CodeBlockComponent } from './code-block.component';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ExpandComponent {
expand = input.required<boolean>();
@Output() expandChange = new EventEmitter<boolean>();
expand = model.required<boolean>();

expandSnippet = computed(
() => `<ngx-sonner-toaster [expand]="${this.expand()}" />`
Expand All @@ -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);
}
}
21 changes: 8 additions & 13 deletions apps/docs/src/app/components/other.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import {
ChangeDetectionStrategy,
Component,
computed,
EventEmitter,
input,
Output,
model,
signal,
} from '@angular/core';
import { toast } from 'ngx-sonner';
Expand Down Expand Up @@ -39,43 +37,40 @@ import { TestComponent } from './test.component';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class OtherComponent {
closeButton = input.required<boolean>();
@Output() closeButtonChange = new EventEmitter<boolean>();

richColors = input.required<boolean>();
@Output() richColorsChange = new EventEmitter<boolean>();
closeButton = model.required<boolean>();
richColors = model.required<boolean>();

allTypes = [
{
name: 'Rich Colors Success',
snippet: "toast.success('Event has been created')",
action: () => {
toast.success('Event has been created');
this.richColorsChange.emit(true);
this.richColors.set(true);
},
},
{
name: 'Rich Colors Error',
snippet: "toast.error('Event has not been created')",
action: () => {
toast.error('Event has not been created');
this.richColorsChange.emit(true);
this.richColors.set(true);
},
},
{
name: 'Rich Colors Info',
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);
},
},
{
name: 'Rich Colors Warning',
snippet: "toast.warning('Warning')",
action: () => {
toast.warning('Event start time cannot be earlier than 8am');
this.richColorsChange.emit(true);
this.richColors.set(true);
},
},
{
Expand All @@ -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());
},
},
{
Expand Down
43 changes: 21 additions & 22 deletions apps/docs/src/app/components/position.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<Position>();

positionSnippet = computed(
() => `<ngx-sonner-toaster position="${this.position()}" />`
);

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);
}
}
5 changes: 2 additions & 3 deletions apps/docs/src/app/components/test.component.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
input,
Output,
output,
} from '@angular/core';

@Component({
Expand Down Expand Up @@ -75,5 +74,5 @@ import {
})
export class TestComponent {
eventName = input.required<string>();
@Output() closeToast = new EventEmitter<void>();
closeToast = output<void>();
}
2 changes: 1 addition & 1 deletion libs/ngx-sonner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Based on [emilkowalski](https://github.com/emilkowalski)'s React [implementation

## Angular compatibility

Make sure you are using Angular v17.2.0 or greater
Make sure you are using Angular v17.3.0 or greater

## Quick start

Expand Down
6 changes: 3 additions & 3 deletions libs/ngx-sonner/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ngx-sonner",
"description": "An opinionated toast component for Angular.",
"version": "0.3.0",
"version": "0.0.0",
"bugs": {
"url": "https://github.com/tutkli/ngx-sonner/issues"
},
Expand All @@ -23,8 +23,8 @@
},
"license": "MIT",
"peerDependencies": {
"@angular/common": ">=17.1.0",
"@angular/core": ">=17.1.0"
"@angular/common": ">=17.3.0",
"@angular/core": ">=17.3.0"
},
"dependencies": {
"tslib": "^2.3.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Pipe, PipeTransform } from '@angular/core';
import { Position, ToastT } from '../types';

@Pipe({ name: 'toastPosition', standalone: true })
export class ToastPositionPipe implements PipeTransform {
@Pipe({ name: 'toastFilter', standalone: true })
export class ToastFilterPipe implements PipeTransform {
transform(toasts: ToastT[], index: number, position: Position): ToastT[] {
return toasts.filter(
toast => (!toast.position && index === 0) || toast.position === position
Expand Down
6 changes: 5 additions & 1 deletion libs/ngx-sonner/src/lib/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,13 @@ function createToastState() {
}

function addHeight(height: HeightT) {
heights.update(prev => [height, ...prev]);
heights.update(prev => [height, ...prev].sort(sortHeights));
}

const sortHeights = (a: HeightT, b: HeightT) =>
toasts().findIndex(t => t.id === a.toastId) -
toasts().findIndex(t => t.id === b.toastId);

function reset() {
toasts.set([]);
heights.set([]);
Expand Down
Loading

0 comments on commit d59d767

Please sign in to comment.