@scania-nl/tegel-angular-extensions 0.0.1 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/index.mjs +5 -0
- package/esm2022/lib/toast/models/toast-state.enum.mjs +19 -0
- package/esm2022/lib/toast/models/toast-type.mjs +5 -0
- package/esm2022/lib/toast/models/toast.model.mjs +2 -0
- package/esm2022/lib/toast/provide-toast.mjs +19 -0
- package/esm2022/lib/toast/toast.component.mjs +34 -0
- package/esm2022/lib/toast/toast.config.mjs +11 -0
- package/esm2022/lib/toast/toast.service.mjs +206 -0
- package/esm2022/lib/utils/bootstrap-global-component.mjs +43 -0
- package/esm2022/scania-nl-tegel-angular-extensions.mjs +5 -0
- package/{src/index.ts → index.d.ts} +1 -1
- package/lib/toast/models/toast-state.enum.d.ts +17 -0
- package/lib/toast/models/toast-type.d.ts +8 -0
- package/lib/toast/models/toast.model.d.ts +73 -0
- package/lib/toast/provide-toast.d.ts +3 -0
- package/lib/toast/toast.component.d.ts +24 -0
- package/lib/toast/toast.config.d.ts +35 -0
- package/lib/toast/toast.service.d.ts +98 -0
- package/lib/utils/bootstrap-global-component.d.ts +23 -0
- package/package.json +16 -2
- package/eslint.config.mjs +0 -48
- package/jest.config.ts +0 -21
- package/ng-package.json +0 -7
- package/project.json +0 -36
- package/src/lib/toast/models/toast-state.enum.ts +0 -19
- package/src/lib/toast/models/toast-type.ts +0 -9
- package/src/lib/toast/models/toast.model.ts +0 -87
- package/src/lib/toast/provide-toast.ts +0 -29
- package/src/lib/toast/toast.component.html +0 -41
- package/src/lib/toast/toast.component.scss +0 -118
- package/src/lib/toast/toast.component.spec.ts +0 -28
- package/src/lib/toast/toast.component.ts +0 -37
- package/src/lib/toast/toast.config.ts +0 -50
- package/src/lib/toast/toast.service.ts +0 -275
- package/src/lib/utils/bootstrap-global-component.ts +0 -73
- package/src/test-setup.ts +0 -6
- package/tsconfig.json +0 -28
- package/tsconfig.lib.json +0 -17
- package/tsconfig.lib.prod.json +0 -7
- package/tsconfig.spec.json +0 -16
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Toast, ToastOptions } from './models/toast.model';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
/**
|
|
4
|
+
* Service for creating, managing, and removing toast notifications.
|
|
5
|
+
* Supports automatic dismissal, manual control, and lifecycle hooks.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ToastService {
|
|
8
|
+
private readonly config;
|
|
9
|
+
/** Internal ID tracker for unique toast IDs */
|
|
10
|
+
private id;
|
|
11
|
+
/** Signal state holding all toasts */
|
|
12
|
+
private readonly _toasts;
|
|
13
|
+
/** Public signal of all toasts */
|
|
14
|
+
readonly toasts: import("@angular/core").Signal<Toast[]>;
|
|
15
|
+
/** Signal of toasts that are not yet closed (open or closing) */
|
|
16
|
+
readonly activeToasts: import("@angular/core").Signal<Toast[]>;
|
|
17
|
+
/** Internal stream for auto-closing toasts */
|
|
18
|
+
private readonly autoCloseSubject;
|
|
19
|
+
/** Internal stream for fade-out/removal of toasts */
|
|
20
|
+
private readonly closeSubject;
|
|
21
|
+
constructor();
|
|
22
|
+
/**
|
|
23
|
+
* Creates and adds a new toast.
|
|
24
|
+
* @param toastOptions Partial toast definition.
|
|
25
|
+
* @returns The toast's unique ID.
|
|
26
|
+
*/
|
|
27
|
+
create(toastOptions: Partial<ToastOptions>): number;
|
|
28
|
+
/**
|
|
29
|
+
* Initiates the fade-out transition for a toast.
|
|
30
|
+
* @param id The toast ID.
|
|
31
|
+
*/
|
|
32
|
+
close(id: number): void;
|
|
33
|
+
/**
|
|
34
|
+
* Immediately marks a toast as closed and removes it from display.
|
|
35
|
+
* @param id The toast ID.
|
|
36
|
+
*/
|
|
37
|
+
remove(id: number): void;
|
|
38
|
+
/**
|
|
39
|
+
* Closes and removes all toasts immediately without fade-out.
|
|
40
|
+
*/
|
|
41
|
+
removeAll(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Initiates closing process for all open toasts.
|
|
44
|
+
*/
|
|
45
|
+
closeAll(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Gets a toast by ID.
|
|
48
|
+
* @param id The toast ID.
|
|
49
|
+
* @returns The toast instance or undefined.
|
|
50
|
+
*/
|
|
51
|
+
getToast(id: number): Toast | undefined;
|
|
52
|
+
/** Whether the toast is eligible for auto-closing */
|
|
53
|
+
private shouldAutoClose;
|
|
54
|
+
/** Whether the toast is eligible for final removal */
|
|
55
|
+
private shouldRemove;
|
|
56
|
+
/** Add toast to signal list */
|
|
57
|
+
private addToast;
|
|
58
|
+
/**
|
|
59
|
+
* Updates the state of a toast.
|
|
60
|
+
* @param id Toast ID
|
|
61
|
+
* @param state New state
|
|
62
|
+
* @returns The updated toast or undefined
|
|
63
|
+
*/
|
|
64
|
+
private updateToastState;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a unique id
|
|
67
|
+
* @returns New id
|
|
68
|
+
*/
|
|
69
|
+
private createId;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a success toast.
|
|
72
|
+
* @param props Toast props without type.
|
|
73
|
+
*/
|
|
74
|
+
readonly success: (props?: Partial<Omit<ToastOptions, "type">>) => number;
|
|
75
|
+
/**
|
|
76
|
+
* Creates an error toast.
|
|
77
|
+
* @param props Toast props without type.
|
|
78
|
+
*/
|
|
79
|
+
readonly error: (props?: Partial<Omit<ToastOptions, "type">>) => number;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a warning toast.
|
|
82
|
+
* @param props Toast props without type.
|
|
83
|
+
*/
|
|
84
|
+
readonly warning: (props?: Partial<Omit<ToastOptions, "type">>) => number;
|
|
85
|
+
/**
|
|
86
|
+
* Creates an informational toast.
|
|
87
|
+
* @param props Toast props without type.
|
|
88
|
+
*/
|
|
89
|
+
readonly info: (props?: Partial<Omit<ToastOptions, "type">>) => number;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a random toast for testing/demo purposes.
|
|
92
|
+
* @param props Optional overrides
|
|
93
|
+
*/
|
|
94
|
+
readonly createRandomToast: (props?: Partial<ToastOptions>) => number;
|
|
95
|
+
private normalizeDuration;
|
|
96
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ToastService, never>;
|
|
97
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<ToastService>;
|
|
98
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ComponentRef, Type } from '@angular/core';
|
|
2
|
+
interface BootstrapGlobalComponentOptions {
|
|
3
|
+
/**
|
|
4
|
+
* If true, avoids re-creating the component if it's already mounted.
|
|
5
|
+
*/
|
|
6
|
+
reuseIfExists?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Bootstraps a global Angular component directly into the <body> element.
|
|
10
|
+
* Useful for toasts, modals, and other global overlays.
|
|
11
|
+
*
|
|
12
|
+
* @param component - The component class to bootstrap.
|
|
13
|
+
* @param options - Optional settings like preventing duplicates.
|
|
14
|
+
* @returns The created ComponentRef.
|
|
15
|
+
*/
|
|
16
|
+
export declare function bootstrapGlobalComponent<T>(component: Type<T>, options?: BootstrapGlobalComponentOptions): ComponentRef<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Destroys a previously bootstrapped global component.
|
|
19
|
+
*
|
|
20
|
+
* @param component - The component class to remove from DOM.
|
|
21
|
+
*/
|
|
22
|
+
export declare function destroyGlobalComponent<T>(component: Type<T>): void;
|
|
23
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scania-nl/tegel-angular-extensions",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,5 +16,19 @@
|
|
|
16
16
|
"author": {
|
|
17
17
|
"name": "Patrick Groot Koerkamp",
|
|
18
18
|
"email": "patrick.groot.koerkamp@scania.com"
|
|
19
|
+
},
|
|
20
|
+
"module": "esm2022/scania-nl-tegel-angular-extensions.mjs",
|
|
21
|
+
"typings": "index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
"./package.json": {
|
|
24
|
+
"default": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./index.d.ts",
|
|
28
|
+
"default": "./esm2022/scania-nl-tegel-angular-extensions.mjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"tslib": "^2.3.0"
|
|
19
33
|
}
|
|
20
|
-
}
|
|
34
|
+
}
|
package/eslint.config.mjs
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import nx from '@nx/eslint-plugin';
|
|
2
|
-
import baseConfig from '../../eslint.base.config.mjs';
|
|
3
|
-
|
|
4
|
-
export default [
|
|
5
|
-
...baseConfig,
|
|
6
|
-
{
|
|
7
|
-
files: ['**/*.json'],
|
|
8
|
-
rules: {
|
|
9
|
-
'@nx/dependency-checks': [
|
|
10
|
-
'error',
|
|
11
|
-
{
|
|
12
|
-
ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'],
|
|
13
|
-
},
|
|
14
|
-
],
|
|
15
|
-
},
|
|
16
|
-
languageOptions: {
|
|
17
|
-
parser: await import('jsonc-eslint-parser'),
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
...nx.configs['flat/angular'],
|
|
21
|
-
...nx.configs['flat/angular-template'],
|
|
22
|
-
{
|
|
23
|
-
files: ['**/*.ts'],
|
|
24
|
-
rules: {
|
|
25
|
-
'@angular-eslint/directive-selector': [
|
|
26
|
-
'error',
|
|
27
|
-
{
|
|
28
|
-
type: 'attribute',
|
|
29
|
-
prefix: 'lib',
|
|
30
|
-
style: 'camelCase',
|
|
31
|
-
},
|
|
32
|
-
],
|
|
33
|
-
'@angular-eslint/component-selector': [
|
|
34
|
-
'error',
|
|
35
|
-
{
|
|
36
|
-
type: 'element',
|
|
37
|
-
prefix: 'tds-ext',
|
|
38
|
-
style: 'kebab-case',
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
files: ['**/*.html'],
|
|
45
|
-
// Override or add rules here
|
|
46
|
-
rules: {},
|
|
47
|
-
},
|
|
48
|
-
];
|
package/jest.config.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
displayName: 'tegel-angular-extensions',
|
|
3
|
-
preset: '../../jest.preset.js',
|
|
4
|
-
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
|
|
5
|
-
coverageDirectory: '../../coverage/libs/tegel-angular-extensions',
|
|
6
|
-
transform: {
|
|
7
|
-
'^.+\\.(ts|mjs|js|html)$': [
|
|
8
|
-
'jest-preset-angular',
|
|
9
|
-
{
|
|
10
|
-
tsconfig: '<rootDir>/tsconfig.spec.json',
|
|
11
|
-
stringifyContentPathRegex: '\\.(html|svg)$',
|
|
12
|
-
},
|
|
13
|
-
],
|
|
14
|
-
},
|
|
15
|
-
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
|
|
16
|
-
snapshotSerializers: [
|
|
17
|
-
'jest-preset-angular/build/serializers/no-ng-attributes',
|
|
18
|
-
'jest-preset-angular/build/serializers/ng-snapshot',
|
|
19
|
-
'jest-preset-angular/build/serializers/html-comment',
|
|
20
|
-
],
|
|
21
|
-
};
|
package/ng-package.json
DELETED
package/project.json
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "tegel-angular-extensions",
|
|
3
|
-
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
-
"sourceRoot": "libs/tegel-angular-extensions/src",
|
|
5
|
-
"prefix": "lib",
|
|
6
|
-
"projectType": "library",
|
|
7
|
-
"tags": [],
|
|
8
|
-
"targets": {
|
|
9
|
-
"build": {
|
|
10
|
-
"executor": "@nx/angular:ng-packagr-lite",
|
|
11
|
-
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
|
|
12
|
-
"options": {
|
|
13
|
-
"project": "libs/tegel-angular-extensions/ng-package.json"
|
|
14
|
-
},
|
|
15
|
-
"configurations": {
|
|
16
|
-
"production": {
|
|
17
|
-
"tsConfig": "libs/tegel-angular-extensions/tsconfig.lib.prod.json"
|
|
18
|
-
},
|
|
19
|
-
"development": {
|
|
20
|
-
"tsConfig": "libs/tegel-angular-extensions/tsconfig.lib.json"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"defaultConfiguration": "production"
|
|
24
|
-
},
|
|
25
|
-
"test": {
|
|
26
|
-
"executor": "@nx/jest:jest",
|
|
27
|
-
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
28
|
-
"options": {
|
|
29
|
-
"jestConfig": "libs/tegel-angular-extensions/jest.config.ts"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"lint": {
|
|
33
|
-
"executor": "@nx/eslint:lint"
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents the current lifecycle state of a toast.
|
|
3
|
-
*/
|
|
4
|
-
export enum ToastState {
|
|
5
|
-
/**
|
|
6
|
-
* The toast is fully visible and active.
|
|
7
|
-
*/
|
|
8
|
-
Open = 'open',
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* The toast is transitioning out (e.g., fading out).
|
|
12
|
-
*/
|
|
13
|
-
Closing = 'closing',
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The toast is fully removed or dismissed.
|
|
17
|
-
*/
|
|
18
|
-
Closed = 'closed',
|
|
19
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* List of available toast types (inherited from Tegel)
|
|
3
|
-
*/
|
|
4
|
-
export const TOAST_TYPES = ['success', 'information', 'warning', 'error'] as const;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Type representing valid toast type values.
|
|
8
|
-
*/
|
|
9
|
-
export type ToastType = (typeof TOAST_TYPES)[number];
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { ToastState } from './toast-state.enum';
|
|
2
|
-
import { ToastType } from './toast-type';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Defines the base structure for a toast message.
|
|
6
|
-
*/
|
|
7
|
-
export interface ToastOptions {
|
|
8
|
-
/**
|
|
9
|
-
* The visual style of the toast (e.g., success, error).
|
|
10
|
-
*/
|
|
11
|
-
type: ToastType;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The main title text displayed in the toast.
|
|
15
|
-
*/
|
|
16
|
-
title: string;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Optional description text providing additional context.
|
|
20
|
-
*/
|
|
21
|
-
description?: string;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Duration in milliseconds before the toast auto-dismisses.
|
|
25
|
-
* Use `0` for persistent toasts.
|
|
26
|
-
*/
|
|
27
|
-
duration: number;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Duration in milliseconds for the fade-out transition.
|
|
31
|
-
*/
|
|
32
|
-
closeDuration: number;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Whether the toast can be manually closed by the user.
|
|
36
|
-
*/
|
|
37
|
-
closable?: boolean;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Optional router link to navigate to when the toast is clicked.
|
|
41
|
-
*/
|
|
42
|
-
link?: string;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Custom link text shown if a link is provided.
|
|
46
|
-
*/
|
|
47
|
-
linkText?: string;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Optional callback triggered when the linkText is clicked.
|
|
51
|
-
* Used as an alternative to `link` for invoking custom behavior.
|
|
52
|
-
*/
|
|
53
|
-
action?: () => void;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Optional callback triggered when the toast is created.
|
|
57
|
-
* @param toast The created toast instance.
|
|
58
|
-
*/
|
|
59
|
-
onCreated?: (toast: Toast) => void;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Optional callback triggered when the toast begins to close.
|
|
63
|
-
* @param toast The toast that is closing.
|
|
64
|
-
*/
|
|
65
|
-
onClose?: (toast: Toast) => void;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Optional callback triggered when the toast has been fully removed.
|
|
69
|
-
* @param toast The removed toast instance.
|
|
70
|
-
*/
|
|
71
|
-
onRemoved?: (toast: Toast) => void;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Represents a fully instantiated toast, including unique ID and current state.
|
|
76
|
-
*/
|
|
77
|
-
export interface Toast extends ToastOptions {
|
|
78
|
-
/**
|
|
79
|
-
* Unique identifier for the toast instance.
|
|
80
|
-
*/
|
|
81
|
-
id: number;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* The current state of the toast (open, closing, or closed).
|
|
85
|
-
*/
|
|
86
|
-
state: ToastState;
|
|
87
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EnvironmentProviders,
|
|
3
|
-
makeEnvironmentProviders,
|
|
4
|
-
provideAppInitializer,
|
|
5
|
-
} from '@angular/core';
|
|
6
|
-
import { bootstrapGlobalComponent } from '../utils/bootstrap-global-component';
|
|
7
|
-
import { ToastComponent } from './toast.component';
|
|
8
|
-
import {
|
|
9
|
-
DEFAULT_TOAST_CONFIG,
|
|
10
|
-
TOAST_CONFIG,
|
|
11
|
-
ToastConfig,
|
|
12
|
-
} from './toast.config';
|
|
13
|
-
|
|
14
|
-
export function provideToast(
|
|
15
|
-
config: Partial<ToastConfig> = {}
|
|
16
|
-
): EnvironmentProviders {
|
|
17
|
-
return makeEnvironmentProviders([
|
|
18
|
-
{
|
|
19
|
-
provide: TOAST_CONFIG,
|
|
20
|
-
useFactory: () => ({
|
|
21
|
-
...DEFAULT_TOAST_CONFIG,
|
|
22
|
-
...(config ?? {}),
|
|
23
|
-
}),
|
|
24
|
-
},
|
|
25
|
-
provideAppInitializer(() => {
|
|
26
|
-
bootstrapGlobalComponent(ToastComponent, { reuseIfExists: true });
|
|
27
|
-
}),
|
|
28
|
-
]);
|
|
29
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
<ul class="toast-list" aria-live="polite" aria-atomic="true">
|
|
2
|
-
@for (toast of toastsSignal(); track toast.id) {
|
|
3
|
-
<li
|
|
4
|
-
class="toast-item"
|
|
5
|
-
[class]="'toast-' + toast.type"
|
|
6
|
-
[class.toast-closing]="toast.state === 'closing'"
|
|
7
|
-
[style.--duration.ms]="toast.duration"
|
|
8
|
-
[style.--close-duration.ms]="toast.closeDuration"
|
|
9
|
-
role="status"
|
|
10
|
-
>
|
|
11
|
-
<tds-toast
|
|
12
|
-
[variant]="toast.type"
|
|
13
|
-
[header]="toast.title"
|
|
14
|
-
[subheader]="toast.description"
|
|
15
|
-
[closable]="toast.closable"
|
|
16
|
-
tds-close-aria-label="Toast close button"
|
|
17
|
-
>
|
|
18
|
-
@if (toast.link) {
|
|
19
|
-
<tds-link slot="actions">
|
|
20
|
-
<a [routerLink]="toast.link">
|
|
21
|
-
{{ toast.linkText ?? 'Click here' }}
|
|
22
|
-
</a>
|
|
23
|
-
</tds-link>
|
|
24
|
-
} @else if (toast.action) {
|
|
25
|
-
<tds-link slot="actions">
|
|
26
|
-
<a href="#" (click)="toast.action()">
|
|
27
|
-
{{ toast.linkText ?? 'Click here' }}
|
|
28
|
-
</a>
|
|
29
|
-
</tds-link>
|
|
30
|
-
}
|
|
31
|
-
</tds-toast>
|
|
32
|
-
@if (toast.closable) {
|
|
33
|
-
<button
|
|
34
|
-
class="toast-close"
|
|
35
|
-
(click)="closeToast(toast)"
|
|
36
|
-
aria-label="Close toast"
|
|
37
|
-
></button>
|
|
38
|
-
}
|
|
39
|
-
</li>
|
|
40
|
-
}
|
|
41
|
-
</ul>
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
$default-close-duration: 300ms;
|
|
2
|
-
$default-duration: 7000ms;
|
|
3
|
-
$item-gap: 6px;
|
|
4
|
-
|
|
5
|
-
:host {
|
|
6
|
-
position: fixed;
|
|
7
|
-
right: 0;
|
|
8
|
-
bottom: 0;
|
|
9
|
-
overflow: hidden;
|
|
10
|
-
z-index: 9999;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.toast-list {
|
|
14
|
-
display: grid;
|
|
15
|
-
grid-template-columns: 1fr;
|
|
16
|
-
gap: $item-gap;
|
|
17
|
-
/* List resets */
|
|
18
|
-
list-style: none;
|
|
19
|
-
padding: $item-gap;
|
|
20
|
-
margin: 0;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.toast-item {
|
|
24
|
-
position: relative;
|
|
25
|
-
animation: fadeIn $default-close-duration ease-in forwards;
|
|
26
|
-
|
|
27
|
-
&.toast-closing {
|
|
28
|
-
animation-name: fadeOut;
|
|
29
|
-
animation-duration: var(--close-duration, $default-close-duration);
|
|
30
|
-
animation-fill-mode: forwards;
|
|
31
|
-
pointer-events: none;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
&::before {
|
|
35
|
-
content: '';
|
|
36
|
-
position: absolute;
|
|
37
|
-
height: 3px;
|
|
38
|
-
width: 100%;
|
|
39
|
-
bottom: 0;
|
|
40
|
-
left: 4px; /* Toast border itself */
|
|
41
|
-
right: 0;
|
|
42
|
-
|
|
43
|
-
animation: progress var(--duration, $default-duration)
|
|
44
|
-
linear forwards;
|
|
45
|
-
|
|
46
|
-
border-top-right-radius: 4px;
|
|
47
|
-
border-bottom-right-radius: 4px;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
&.toast-information::before {
|
|
51
|
-
background: var(--tds-information);
|
|
52
|
-
}
|
|
53
|
-
&.toast-success::before {
|
|
54
|
-
background: var(--tds-positive);
|
|
55
|
-
}
|
|
56
|
-
&.toast-warning::before {
|
|
57
|
-
background: var(--tds-warning);
|
|
58
|
-
}
|
|
59
|
-
&.toast-error::before {
|
|
60
|
-
background: var(--tds-negative);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/*
|
|
64
|
-
Custom Close element for TDS, which is just a transparent block covering the close-button of the TdsToast element
|
|
65
|
-
|
|
66
|
-
Height, width, and positioning values are equal to TdsToast's button.close element for a perfect overlap
|
|
67
|
-
*/
|
|
68
|
-
.toast-close {
|
|
69
|
-
height: 20px;
|
|
70
|
-
width: 20px;
|
|
71
|
-
|
|
72
|
-
box-sizing: border-box;
|
|
73
|
-
cursor: pointer;
|
|
74
|
-
position: absolute;
|
|
75
|
-
top: 14px;
|
|
76
|
-
right: 14px;
|
|
77
|
-
|
|
78
|
-
border: 0;
|
|
79
|
-
background: transparent;
|
|
80
|
-
|
|
81
|
-
&:active {
|
|
82
|
-
border: 2px solid var(--tds-blue-400);
|
|
83
|
-
outline-offset: -2px;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
@keyframes fadeIn {
|
|
89
|
-
0% {
|
|
90
|
-
transform: translateY(40%);
|
|
91
|
-
opacity: 0;
|
|
92
|
-
margin-bottom: -25%;
|
|
93
|
-
}
|
|
94
|
-
100% {
|
|
95
|
-
transform: translateY(0);
|
|
96
|
-
opacity: 1;
|
|
97
|
-
margin-bottom: 0%;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
@keyframes fadeOut {
|
|
102
|
-
0% {
|
|
103
|
-
transform: translateY(0);
|
|
104
|
-
opacity: 1;
|
|
105
|
-
margin-top: 0;
|
|
106
|
-
}
|
|
107
|
-
100% {
|
|
108
|
-
opacity: 0;
|
|
109
|
-
transform: translateY(75%);
|
|
110
|
-
margin-top: -25%;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
@keyframes progress {
|
|
115
|
-
100% {
|
|
116
|
-
width: 0%;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
-
import { provideToast } from './provide-toast';
|
|
3
|
-
import { ToastComponent } from './toast.component';
|
|
4
|
-
|
|
5
|
-
describe('ToastComponent', () => {
|
|
6
|
-
let component: ToastComponent;
|
|
7
|
-
let fixture: ComponentFixture<ToastComponent>;
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
await TestBed.configureTestingModule({
|
|
11
|
-
declarations: [],
|
|
12
|
-
imports: [ToastComponent],
|
|
13
|
-
providers: [
|
|
14
|
-
provideToast()
|
|
15
|
-
]
|
|
16
|
-
}).compileComponents();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
fixture = TestBed.createComponent(ToastComponent);
|
|
21
|
-
component = fixture.componentInstance;
|
|
22
|
-
fixture.detectChanges();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should create', () => {
|
|
26
|
-
expect(component).toBeTruthy();
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { CommonModule } from '@angular/common';
|
|
2
|
-
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
|
|
3
|
-
import { RouterLink } from '@angular/router';
|
|
4
|
-
import { TegelModule } from '@scania/tegel-angular-17';
|
|
5
|
-
|
|
6
|
-
import { Toast } from './models/toast.model';
|
|
7
|
-
import { ToastService } from './toast.service';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Displays toast notifications provided by the ToastService.
|
|
11
|
-
*
|
|
12
|
-
* Toasts are non-blocking messages that automatically disappear after a set duration
|
|
13
|
-
* or can be dismissed manually by the user.
|
|
14
|
-
*/
|
|
15
|
-
@Component({
|
|
16
|
-
selector: 'tds-ext-toast',
|
|
17
|
-
templateUrl: './toast.component.html',
|
|
18
|
-
styleUrls: ['./toast.component.scss'],
|
|
19
|
-
imports: [CommonModule, TegelModule, RouterLink],
|
|
20
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
21
|
-
})
|
|
22
|
-
export class ToastComponent {
|
|
23
|
-
private readonly toastService = inject(ToastService);
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A reactive signal of all currently active toasts (open or closing).
|
|
27
|
-
*/
|
|
28
|
-
readonly toastsSignal = this.toastService.activeToasts;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Initiates the closing process for the given toast.
|
|
32
|
-
*
|
|
33
|
-
* @param toast The toast to be closed.
|
|
34
|
-
* @returns void
|
|
35
|
-
*/
|
|
36
|
-
closeToast = (toast: Toast) => this.toastService.close(toast.id);
|
|
37
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { InjectionToken } from '@angular/core';
|
|
2
|
-
import { ToastType } from './models/toast-type';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Global default configuration for toast behavior.
|
|
6
|
-
* Used when individual toast properties are not explicitly set.
|
|
7
|
-
*/
|
|
8
|
-
export interface ToastConfig {
|
|
9
|
-
/**
|
|
10
|
-
* Default toast type (e.g., 'success', 'information', etc.).
|
|
11
|
-
*/
|
|
12
|
-
type: ToastType;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Default title to use when none is provided.
|
|
16
|
-
*/
|
|
17
|
-
title: string;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Default description to use when none is provided.
|
|
21
|
-
*/
|
|
22
|
-
description: string;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Default duration (ms) before auto-dismiss.
|
|
26
|
-
* Use `0` for persistent toasts.
|
|
27
|
-
*/
|
|
28
|
-
duration: number;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Default duration (ms) for the fade-out animation.
|
|
32
|
-
*/
|
|
33
|
-
closeDuration: number;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Whether toasts are closable by default.
|
|
37
|
-
*/
|
|
38
|
-
closable: boolean;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const TOAST_CONFIG = new InjectionToken<ToastConfig>('ToastConfig');
|
|
42
|
-
|
|
43
|
-
export const DEFAULT_TOAST_CONFIG: Required<ToastConfig> = {
|
|
44
|
-
type: 'information',
|
|
45
|
-
title: 'Notification',
|
|
46
|
-
description: '',
|
|
47
|
-
duration: 7500,
|
|
48
|
-
closeDuration: 300,
|
|
49
|
-
closable: true,
|
|
50
|
-
};
|