avalynx-alert 0.0.3 → 0.0.5

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 avalynx
3
+ Copyright (c) 2024 Juergen Schwind an the Avalynx-Alert Authors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1 +1,132 @@
1
- # avalynx-alert
1
+ # AvalynxAlert
2
+
3
+ AvalynxAlert is a lightweight, dependency-free alert system designed for web applications. It leverages Bootstrap (version 5.3 or higher) to provide a seamless integration with your project, offering a range of customizable alerts that can be positioned anywhere on the screen.
4
+
5
+ ## Features
6
+
7
+ - **Customizable Alerts**: Supports various alert types like primary, secondary, success, danger, warning, info, light, and dark.
8
+ - **Flexible Positioning**: Choose from predefined positions such as top-left, top-center, top-right, bottom-left, bottom-center, and bottom-right.
9
+ - **Duration Control**: Set the duration for how long the alert should be displayed.
10
+ - **Closeable Alerts**: Optionally allow users to close alerts.
11
+ - **AutoClose Functionality**: Alerts can automatically disappear after a certain period.
12
+ - **Easy to Use**: Simple API for creating and managing alerts within your web applications.
13
+
14
+ ## Example
15
+
16
+ Here's a simple example of how to use AvalynxAlert in your project:
17
+
18
+ * [Overview](https://avalynx-alert.jbs-newmedia.de/examples/index.html)
19
+ * [Random Alerts](https://avalynx-alert.jbs-newmedia.de/examples/random-alerts.html)
20
+ * [Callback on close](https://avalynx-alert.jbs-newmedia.de/examples/callback-onclose.html)
21
+
22
+ ## Installation
23
+
24
+ To use AvalynxAlert in your project, you can directly include it in your HTML file. Ensure you have Bootstrap 5.3 or higher included in your project for AvalynxAlert to work correctly.
25
+
26
+ First, include Bootstrap:
27
+
28
+ ```html
29
+ <!-- Bootstrap -->
30
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3/dist/css/bootstrap.min.css" rel="stylesheet">
31
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3/dist/js/bootstrap.bundle.min.js"></script>
32
+ ```
33
+
34
+ Then, include AvalynxAlert:
35
+
36
+ ```html
37
+ <link href="path/to/avalynx-alert.css" rel="stylesheet">
38
+ <script src="path/to/avalynx-alert.js"></script>
39
+ ```
40
+
41
+ Replace `path/to/avalynx-alert.js` and `path/to/avalynx-alert.css` with the actual path to the files in your project.
42
+
43
+ ## Installation via jsDelivr
44
+
45
+ AvalynxAlert is also available via [jsDelivr](https://www.jsdelivr.com/). You can include it in your project like this:
46
+
47
+ ```html
48
+ <link href="https://cdn.jsdelivr.net/npm/avalynx-alert/dist/avalynx-alert.css" rel="stylesheet">
49
+ <script src="https://cdn.jsdelivr.net/npm/avalynx-alert/dist/avalynx-alert.js"></script>
50
+ ```
51
+
52
+ Make sure to also include Bootstrap's JS/CSS in your project to ensure AvalynxAlert displays correctly.
53
+
54
+ ## Installation via NPM
55
+
56
+ AvalynxAlert is also available as a npm package. You can add it to your project with the following command:
57
+
58
+ ```bash
59
+ npm install avalynx-alert
60
+ ```
61
+
62
+ After installing, you can import AvalynxAlert into your JavaScript file like this:
63
+
64
+ ```javascript
65
+ import { AvalynxAlert } from 'avalynx-alert';
66
+ import 'avalynx-alert/dist/css/avalynx-alert.min.css';
67
+ ```
68
+
69
+ Make sure to also include Bootstrap's JS/CSS in your project to ensure AvalynxAlert displays correctly.
70
+
71
+ ## Installation via Symfony AssetMapper
72
+
73
+ ```bash
74
+ php bin/console importmap:require avalynx-alert
75
+ ```
76
+
77
+ After installing, you can import AvalynxAlert into your JavaScript file like this:
78
+
79
+ ```javascript
80
+ import { AvalynxAlert } from 'avalynx-alert';
81
+ import 'avalynx-alert/dist/css/avalynx-alert.min.css';
82
+ ```
83
+
84
+ Make sure to also include Bootstrap's JS/CSS in your project to ensure AvalynxAlert displays correctly.
85
+
86
+ ## Usage
87
+
88
+ To create an alert, simply instantiate a new `AvalynxAlert` object with the desired options:
89
+
90
+ ```javascript
91
+ new AvalynxAlert('Your message here', 'success', {
92
+ duration: 5000,
93
+ position: 'top-right',
94
+ closeable: true,
95
+ autoClose: true,
96
+ width: '400px'
97
+ });
98
+ ```
99
+
100
+ ## Options
101
+
102
+ AvalynxAlert allows the following options for customization:
103
+
104
+ - `message`: The message to display in the alert.
105
+ - `type`: The type of alert (`primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark`).
106
+ - `options`: An object containing the following keys:
107
+ - `duration`: Duration in milliseconds for the alert to be displayed (default: 5000).
108
+ - `position`: Position of the alert on the screen (default: `top-center`).
109
+ - `closeable`: Whether the alert can be closed by the user (default: true).
110
+ - `autoClose`: Whether the alert will close automatically after the duration (default: true).
111
+ - `width`: The width of the alert (default: `400px`).
112
+ - `onClose`: A callback function to be called when the alert is closed.
113
+
114
+ ## Contributing
115
+
116
+ Contributions are welcome! If you'd like to contribute, please fork the repository and submit a pull request with your changes or improvements. We're looking for contributions in the following areas:
117
+
118
+ - Bug fixes
119
+ - Feature enhancements
120
+ - Documentation improvements
121
+
122
+ Before submitting your pull request, please ensure your changes are well-documented and follow the existing coding style of the project.
123
+
124
+ ## License
125
+
126
+ AvalynxAlert is open-sourced software licensed under the [MIT license](LICENSE).
127
+
128
+ ## Contact
129
+
130
+ If you have any questions, feature requests, or issues, please open an issue on our [GitHub repository](https://github.com/avalynx/avalynx-alert/issues) or submit a pull request.
131
+
132
+ Thank you for considering AvalynxAlert for your project!
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * AvalynxAlert
3
3
  *
4
- * A simple alert system for web applications.
4
+ * A simple alert system for web applications. Based on Bootstrap >=5.3 without any framework dependencies.
5
5
  *
6
- * @version 0.0.3
6
+ * @version 0.0.5
7
7
  * @license MIT
8
8
  * @author https://github.com/avalynx/avalynx-alert/graphs/contributors
9
9
  * @website https://github.com/avalynx/
@@ -0,0 +1,137 @@
1
+ /**
2
+ * AvalynxAlert
3
+ *
4
+ * A simple alert system for web applications. Based on Bootstrap >=5.3 without any framework dependencies.
5
+ *
6
+ * @version 0.0.5
7
+ * @license MIT
8
+ * @author https://github.com/avalynx/avalynx-alert/graphs/contributors
9
+ * @website https://github.com/avalynx/
10
+ * @repository https://github.com/avalynx/avalynx-alert.git
11
+ * @bugs https://github.com/avalynx/avalynx-alert/issues
12
+ *
13
+ * @param {string} message - The message to display in the alert.
14
+ * @param {string} type - The type of alert. One of 'primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'.
15
+ * @param {object} options - The options for the alert.
16
+ * @param {number} options.duration - The duration in milliseconds for the alert to be displayed. Default is 5000.
17
+ * @param {string} options.position - The position of the alert. One of 'top-left', 'top-center', 'top-right', 'bottom-left', 'bottom-center', 'bottom-right'. Default is 'top-center'.
18
+ * @param {boolean} options.closeable - Whether the alert can be closed by the user. Default is true.
19
+ * @param {boolean} options.autoClose - Whether the alert will close automatically after the duration. Default is true.
20
+ * @param {string} options.width - The width of the alert. Default is '400px'.
21
+ */
22
+
23
+ export class AvalynxAlert {
24
+ constructor(message, type, options = {}) {
25
+ this.message = message;
26
+ this.type = type;
27
+ this.duration = options.duration || 5000;
28
+ this.position = options.position || 'top-center';
29
+ this.closeable = options.closeable || true;
30
+ this.autoClose = options.autoClose || true;
31
+ this.width = options.width || '400px';
32
+ this.onClose = options.onClose || null;
33
+
34
+ if (!['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'].includes(this.type)) {
35
+ this.type = 'info';
36
+ }
37
+ if (!['top-left', 'top-center', 'top-right', 'bottom-left', 'bottom-center', 'bottom-right'].includes(this.position)) {
38
+ this.position = 'top-center';
39
+ }
40
+ if (this.autoClose !== false && this.autoClose !== true) {
41
+ this.autoClose = true;
42
+ }
43
+ if ((this.closeable !== false && this.closeable !== true) || (this.autoClose === true)) {
44
+ this.closeable = true;
45
+ }
46
+
47
+ this.init();
48
+ }
49
+
50
+ ensureAlertContainer() {
51
+ if (!document.getElementById('avalynx-alert-container-' + this.position)) {
52
+ var container = document.createElement('div');
53
+ container.id = 'avalynx-alert-container-' + this.position;
54
+ container.style.width = '100%';
55
+ container.style.maxWidth = this.width;
56
+ container.style.zIndex = '1000';
57
+ container.classList.add('container-fluid');
58
+
59
+ if (this.position === 'top-left') {
60
+ container.style.position = 'fixed';
61
+ container.style.top = '10px';
62
+ container.style.left = '0px';
63
+ } else if (this.position === 'top-center') {
64
+ container.style.position = 'fixed';
65
+ container.style.top = '10px';
66
+ container.style.left = '50%';
67
+ container.style.transform = 'translateX(-50%)';
68
+ } else if (this.position === 'top-right') {
69
+ container.style.position = 'fixed';
70
+ container.style.top = '10px';
71
+ container.style.right = '0px';
72
+ } else if (this.position === 'bottom-left') {
73
+ container.style.position = 'fixed';
74
+ container.style.bottom = '10px';
75
+ container.style.left = '0px';
76
+ } else if (this.position === 'bottom-center') {
77
+ container.style.position = 'fixed';
78
+ container.style.bottom = '10px';
79
+ container.style.left = '50%';
80
+ container.style.transform = 'translateX(-50%)';
81
+ } else if (this.position === 'bottom-right') {
82
+ container.style.position = 'fixed';
83
+ container.style.bottom = '10px';
84
+ container.style.right = '0px';
85
+ }
86
+
87
+ document.body.appendChild(container);
88
+ }
89
+ }
90
+
91
+ init() {
92
+ this.ensureAlertContainer();
93
+
94
+ var alert = document.createElement('div');
95
+ alert.className = `alert alert-${this.type}`;
96
+ if (this.closeable) {
97
+ alert.classList.add('alert-dismissible');
98
+ }
99
+ alert.classList.add('fade');
100
+ alert.classList.add('show');
101
+ alert.classList.add('p-0');
102
+ alert.classList.add('overflow-hidden');
103
+ alert.classList.add('avalynx-alert');
104
+ alert.role = 'alert';
105
+ alert.innerHTML = `<div class="alert-content">${this.message}`;
106
+ if (this.closeable) {
107
+ alert.innerHTML += `<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>`;
108
+ }
109
+ alert.innerHTML += `</div>`;
110
+ if (this.autoClose) {
111
+ alert.innerHTML += `<div class="alert-timer" style="height: 5px; width: 0;"></div>`;
112
+ }
113
+
114
+ document.getElementById('avalynx-alert-container-' + this.position).appendChild(alert);
115
+
116
+ if (this.autoClose) {
117
+ var timerBar = alert.querySelector('.alert-timer');
118
+ timerBar.style.transition = `width ${this.duration}ms linear`;
119
+
120
+ requestAnimationFrame(() => {
121
+ requestAnimationFrame(() => {
122
+ timerBar.style.width = '100%';
123
+ });
124
+ });
125
+
126
+ setTimeout(() => {
127
+ alert.classList.remove('show');
128
+ setTimeout(() => {
129
+ alert.remove();
130
+ if (typeof this.onClose === 'function') {
131
+ this.onClose();
132
+ }
133
+ }, 150);
134
+ }, this.duration);
135
+ }
136
+ }
137
+ }
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * AvalynxAlert
3
3
  *
4
- * A simple alert system for web applications.
4
+ * A simple alert system for web applications. Based on Bootstrap >=5.3 without any framework dependencies.
5
5
  *
6
- * @version 0.0.3
6
+ * @version 0.0.5
7
7
  * @license MIT
8
8
  * @author https://github.com/avalynx/avalynx-alert/graphs/contributors
9
9
  * @website https://github.com/avalynx/
@@ -18,9 +18,10 @@
18
18
  * @param {boolean} options.closeable - Whether the alert can be closed by the user. Default is true.
19
19
  * @param {boolean} options.autoClose - Whether the alert will close automatically after the duration. Default is true.
20
20
  * @param {string} options.width - The width of the alert. Default is '400px'.
21
+ * @param {function} options.onClose - A callback function to be called when the alert is closed.
21
22
  */
22
23
 
23
- export class AvalynxAlert {
24
+ class AvalynxAlert {
24
25
  constructor(message, type, options = {}) {
25
26
  this.message = message;
26
27
  this.type = type;
@@ -29,6 +30,8 @@ export class AvalynxAlert {
29
30
  this.closeable = options.closeable || true;
30
31
  this.autoClose = options.autoClose || true;
31
32
  this.width = options.width || '400px';
33
+ this.onClose = options.onClose || null;
34
+
32
35
  if (!['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'].includes(this.type)) {
33
36
  this.type = 'info';
34
37
  }
@@ -114,11 +117,21 @@ export class AvalynxAlert {
114
117
  if (this.autoClose) {
115
118
  var timerBar = alert.querySelector('.alert-timer');
116
119
  timerBar.style.transition = `width ${this.duration}ms linear`;
117
- setTimeout(() => { timerBar.style.width = '100%'; }, 10);
120
+
121
+ requestAnimationFrame(() => {
122
+ requestAnimationFrame(() => {
123
+ timerBar.style.width = '100%';
124
+ });
125
+ });
118
126
 
119
127
  setTimeout(() => {
120
128
  alert.classList.remove('show');
121
- setTimeout(() => alert.remove(), 150);
129
+ setTimeout(() => {
130
+ alert.remove();
131
+ if (typeof this.onClose === 'function') {
132
+ this.onClose();
133
+ }
134
+ }, 150);
122
135
  }, this.duration);
123
136
  }
124
137
  }
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "avalynx-alert",
3
3
  "title": "AvalynxAlert",
4
- "description": "AvalynxAlert is a simple, lightweight, and customizable alert component for Bootstrap.",
5
- "version": "0.0.3",
4
+ "description": "AvalynxAlert is a simple alert system for web applications. Based on Bootstrap >=5.3 without any framework dependencies.",
5
+ "version": "0.0.5",
6
6
  "license": "MIT",
7
7
  "main": "dist/js/avalynx-alert.js",
8
- "module": "dist/js/avalynx-alert.js",
8
+ "module": "dist/js/avalynx-alert.esm.js",
9
9
  "style": "dist/css/avalynx-alert.css",
10
10
  "files": [
11
11
  "dist/css/avalynx-alert.css",
12
- "dist/js/avalynx-alert.js"
12
+ "dist/js/avalynx-alert.js",
13
+ "dist/js/avalynx-alert.esm.js"
13
14
  ],
14
15
  "keywords": [
15
16
  "alert",
@@ -25,7 +26,7 @@
25
26
  "package.json"
26
27
  ],
27
28
  "author": {
28
- "name": "The Avalynx-Alert Authors",
29
+ "name": "Juergen Schwind an the Avalynx-Alert Authors",
29
30
  "url": "https://github.com/avalynx/avalynx-alert/graphs/contributors"
30
31
  },
31
32
  "homepage": "https://github.com/avalynx/",