avalynx-alert 0.0.3 → 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/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,128 @@
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
+
21
+ ## Installation
22
+
23
+ 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.
24
+
25
+ First, include Bootstrap:
26
+
27
+ ```html
28
+ <!-- Bootstrap -->
29
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3/dist/css/bootstrap.min.css" rel="stylesheet">
30
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3/dist/js/bootstrap.bundle.min.js"></script>
31
+ ```
32
+
33
+ Then, include AvalynxAlert:
34
+
35
+ ```html
36
+ <link href="path/to/avalynx-alert.css" rel="stylesheet">
37
+ <script src="path/to/avalynx-alert.js"></script>
38
+ ```
39
+
40
+ Replace `path/to/avalynx-alert.js` and `path/to/avalynx-alert.css` with the actual path to the files in your project.
41
+
42
+ ## Installation via jsDelivr
43
+
44
+ AvalynxAlert is also available via [jsDelivr](https://www.jsdelivr.com/). You can include it in your project like this:
45
+
46
+ ```html
47
+ <link href="https://cdn.jsdelivr.net/npm/avalynx-alert/dist/avalynx-alert.css" rel="stylesheet">
48
+ <script src="https://cdn.jsdelivr.net/npm/avalynx-alert/dist/avalynx-alert.js"></script>
49
+ ```
50
+
51
+ ## Installation via NPM
52
+
53
+ AvalynxAlert is also available as a npm package. You can add it to your project with the following command:
54
+
55
+ ```bash
56
+ npm install avalynx-alert
57
+ ```
58
+
59
+ After installing, you can import AvalynxAlert into your JavaScript file like this:
60
+
61
+ ```javascript
62
+ import { AvalynxAlert } from 'avalynx-alert';
63
+ import 'avalynx-alert/dist/css/avalynx-alert.min.css';
64
+ ```
65
+
66
+ Make sure to also include Bootstrap's CSS in your project to ensure AvalynxAlert displays correctly.
67
+
68
+ ## Installation via Symfony AssetMapper
69
+
70
+ ```bash
71
+ php bin/console importmap:require avalynx-alert
72
+ ```
73
+
74
+ After installing, you can import AvalynxAlert into your JavaScript file like this:
75
+
76
+ ```javascript
77
+ import { AvalynxAlert } from 'avalynx-alert';
78
+ import 'avalynx-alert/dist/css/avalynx-alert.min.css';
79
+ ```
80
+
81
+ Make sure to also include Bootstrap's CSS in your project to ensure AvalynxAlert displays correctly.
82
+
83
+ ## Usage
84
+
85
+ To create an alert, simply instantiate a new `AvalynxAlert` object with the desired options:
86
+
87
+ ```javascript
88
+ new AvalynxAlert('Your message here', 'success', {
89
+ duration: 5000,
90
+ position: 'top-right',
91
+ closeable: true,
92
+ autoClose: true,
93
+ width: '400px'
94
+ });
95
+ ```
96
+
97
+ ## Options
98
+
99
+ AvalynxAlert allows the following options for customization:
100
+
101
+ - `message`: The message to display in the alert.
102
+ - `type`: The type of alert (`primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark`).
103
+ - `options`: An object containing the following keys:
104
+ - `duration`: Duration in milliseconds for the alert to be displayed (default: 5000).
105
+ - `position`: Position of the alert on the screen (default: `top-center`).
106
+ - `closeable`: Whether the alert can be closed by the user (default: true).
107
+ - `autoClose`: Whether the alert will close automatically after the duration (default: true).
108
+ - `width`: The width of the alert (default: `400px`).
109
+
110
+ ## Contributing
111
+
112
+ 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:
113
+
114
+ - Bug fixes
115
+ - Feature enhancements
116
+ - Documentation improvements
117
+
118
+ Before submitting your pull request, please ensure your changes are well-documented and follow the existing coding style of the project.
119
+
120
+ ## License
121
+
122
+ AvalynxAlert is open-sourced software licensed under the [MIT license](LICENSE).
123
+
124
+ ## Contact
125
+
126
+ 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.
127
+
128
+ 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.4
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,130 @@
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.4
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
+ if (!['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'].includes(this.type)) {
33
+ this.type = 'info';
34
+ }
35
+ if (!['top-left', 'top-center', 'top-right', 'bottom-left', 'bottom-center', 'bottom-right'].includes(this.position)) {
36
+ this.position = 'top-center';
37
+ }
38
+ if (this.autoClose !== false && this.autoClose !== true) {
39
+ this.autoClose = true;
40
+ }
41
+ if ((this.closeable !== false && this.closeable !== true) || (this.autoClose === true)) {
42
+ this.closeable = true;
43
+ }
44
+
45
+ this.init();
46
+ }
47
+
48
+ ensureAlertContainer() {
49
+ if (!document.getElementById('avalynx-alert-container-' + this.position)) {
50
+ var container = document.createElement('div');
51
+ container.id = 'avalynx-alert-container-' + this.position;
52
+ container.style.width = '100%';
53
+ container.style.maxWidth = this.width;
54
+ container.style.zIndex = '1000';
55
+ container.classList.add('container-fluid');
56
+
57
+ if (this.position === 'top-left') {
58
+ container.style.position = 'fixed';
59
+ container.style.top = '10px';
60
+ container.style.left = '0px';
61
+ } else if (this.position === 'top-center') {
62
+ container.style.position = 'fixed';
63
+ container.style.top = '10px';
64
+ container.style.left = '50%';
65
+ container.style.transform = 'translateX(-50%)';
66
+ } else if (this.position === 'top-right') {
67
+ container.style.position = 'fixed';
68
+ container.style.top = '10px';
69
+ container.style.right = '0px';
70
+ } else if (this.position === 'bottom-left') {
71
+ container.style.position = 'fixed';
72
+ container.style.bottom = '10px';
73
+ container.style.left = '0px';
74
+ } else if (this.position === 'bottom-center') {
75
+ container.style.position = 'fixed';
76
+ container.style.bottom = '10px';
77
+ container.style.left = '50%';
78
+ container.style.transform = 'translateX(-50%)';
79
+ } else if (this.position === 'bottom-right') {
80
+ container.style.position = 'fixed';
81
+ container.style.bottom = '10px';
82
+ container.style.right = '0px';
83
+ }
84
+
85
+ document.body.appendChild(container);
86
+ }
87
+ }
88
+
89
+ init() {
90
+ this.ensureAlertContainer();
91
+
92
+ var alert = document.createElement('div');
93
+ alert.className = `alert alert-${this.type}`;
94
+ if (this.closeable) {
95
+ alert.classList.add('alert-dismissible');
96
+ }
97
+ alert.classList.add('fade');
98
+ alert.classList.add('show');
99
+ alert.classList.add('p-0');
100
+ alert.classList.add('overflow-hidden');
101
+ alert.classList.add('avalynx-alert');
102
+ alert.role = 'alert';
103
+ alert.innerHTML = `<div class="alert-content">${this.message}`;
104
+ if (this.closeable) {
105
+ alert.innerHTML += `<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>`;
106
+ }
107
+ alert.innerHTML += `</div>`;
108
+ if (this.autoClose) {
109
+ alert.innerHTML += `<div class="alert-timer" style="height: 5px; width: 0;"></div>`;
110
+ }
111
+
112
+ document.getElementById('avalynx-alert-container-' + this.position).appendChild(alert);
113
+
114
+ if (this.autoClose) {
115
+ var timerBar = alert.querySelector('.alert-timer');
116
+ timerBar.style.transition = `width ${this.duration}ms linear`;
117
+
118
+ requestAnimationFrame(() => {
119
+ requestAnimationFrame(() => {
120
+ timerBar.style.width = '100%';
121
+ });
122
+ });
123
+
124
+ setTimeout(() => {
125
+ alert.classList.remove('show');
126
+ setTimeout(() => alert.remove(), 150);
127
+ }, this.duration);
128
+ }
129
+ }
130
+ }
@@ -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.4
7
7
  * @license MIT
8
8
  * @author https://github.com/avalynx/avalynx-alert/graphs/contributors
9
9
  * @website https://github.com/avalynx/
@@ -20,7 +20,7 @@
20
20
  * @param {string} options.width - The width of the alert. Default is '400px'.
21
21
  */
22
22
 
23
- export class AvalynxAlert {
23
+ class AvalynxAlert {
24
24
  constructor(message, type, options = {}) {
25
25
  this.message = message;
26
26
  this.type = type;
@@ -114,7 +114,12 @@ export class AvalynxAlert {
114
114
  if (this.autoClose) {
115
115
  var timerBar = alert.querySelector('.alert-timer');
116
116
  timerBar.style.transition = `width ${this.duration}ms linear`;
117
- setTimeout(() => { timerBar.style.width = '100%'; }, 10);
117
+
118
+ requestAnimationFrame(() => {
119
+ requestAnimationFrame(() => {
120
+ timerBar.style.width = '100%';
121
+ });
122
+ });
118
123
 
119
124
  setTimeout(() => {
120
125
  alert.classList.remove('show');
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.4",
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/",