-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoast-position.component.ts
More file actions
87 lines (80 loc) · 2.75 KB
/
toast-position.component.ts
File metadata and controls
87 lines (80 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { Component } from '@angular/core';
import { StoryObj } from '@storybook/angular';
import { Toast } from 'primeng/toast';
import { Button } from 'primeng/button';
import { MessageService, SharedModule } from 'primeng/api';
const POSITIONS = [
{ position: 'top-left', label: 'Вверх слева', key: 'pos-top-left' },
{ position: 'top-center', label: 'Вверх по центру', key: 'pos-top-center' },
{ position: 'top-right', label: 'Вверх справа', key: 'pos-top-right' },
{ position: 'bottom-left', label: 'Вниз слева', key: 'pos-bottom-left' },
{ position: 'bottom-center', label: 'Вниз по центру', key: 'pos-bottom-center' },
{ position: 'bottom-right', label: 'Вниз справа', key: 'pos-bottom-right' },
] as const;
const template = `
@for (p of positions; track p.key) {
<p-toast [position]="p.position" [key]="p.key">
<ng-template #message let-message>
<div class="p-toast-accent-line"></div>
<i [class]="message.icon + ' p-toast-message-icon'"></i>
<div class="p-toast-message-text">
<span class="p-toast-summary">{{ message.summary }}</span>
<div class="p-toast-detail">{{ message.detail }}</div>
</div>
</ng-template>
</p-toast>
}
<div class="flex flex-col gap-2 items-center justify-center min-h-48">
@for (p of positions; track p.key) {
<p-button
[label]="p.label"
severity="contrast"
(onClick)="show(p.key, p.position)"
></p-button>
}
</div>
`;
const styles = '';
@Component({
selector: 'app-toast-position',
standalone: true,
imports: [Toast, Button, SharedModule],
providers: [MessageService],
template,
styles,
})
export class ToastPositionComponent {
readonly positions = POSITIONS;
constructor(private readonly messageService: MessageService) {}
show(key: string, position: string): void {
this.messageService.add({
key,
severity: 'info',
summary: 'Сообщение',
detail: 'Позиция: ' + position,
life: 3000,
icon: 'ti ti-info-circle',
});
}
}
export const Position: StoryObj = {
render: () => ({
template: `<app-toast-position></app-toast-position>`,
}),
parameters: {
docs: {
description: { story: 'Расположение тоста задаётся через `position` и `key`.' },
source: {
language: 'ts',
code: `
<p-toast position="top-left" key="top-left"></p-toast>
<p-toast position="top-center" key="top-center"></p-toast>
<p-toast position="top-right" key="top-right"></p-toast>
<p-toast position="bottom-left" key="bottom-left"></p-toast>
<p-toast position="bottom-center" key="bottom-center"></p-toast>
<p-toast position="bottom-right" key="bottom-right"></p-toast>
`,
},
},
},
};