avalynx-alert 0.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 avalynx
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # avalynx-alert
@@ -0,0 +1,47 @@
1
+ /**
2
+
3
+ */
4
+
5
+ .avalynx-alert .alert-content {
6
+ padding: var(--bs-alert-padding-y) var(--bs-alert-padding-x);
7
+ }
8
+
9
+ .avalynx-alert.alert-dismissible .alert-content {
10
+ padding-right: 3rem;
11
+ }
12
+
13
+ .avalynx-alert .btn-close {
14
+ --bs-btn-close-focus-shadow: 0;
15
+ }
16
+
17
+ .avalynx-alert.alert-primary .alert-timer {
18
+ background-color: var(--bs-primary-border-subtle);
19
+ }
20
+
21
+ .avalynx-alert.alert-secondary .alert-timer {
22
+ background-color: var(--bs-secondary-border-subtle);
23
+ }
24
+
25
+ .avalynx-alert.alert-success .alert-timer {
26
+ background-color: var(--bs-success-border-subtle);
27
+ }
28
+
29
+ .avalynx-alert.alert-danger .alert-timer {
30
+ background-color: var(--bs-danger-border-subtle);
31
+ }
32
+
33
+ .avalynx-alert.alert-warning .alert-timer {
34
+ background-color: var(--bs-warning-border-subtle);
35
+ }
36
+
37
+ .avalynx-alert.alert-info .alert-timer {
38
+ background-color: var(--bs-info-border-subtle);
39
+ }
40
+
41
+ .avalynx-alert.alert-light .alert-timer {
42
+ background-color: var(--bs-light-border-subtle);
43
+ }
44
+
45
+ .avalynx-alert.alert-dark .alert-timer {
46
+ background-color: var(--bs-dark-border-subtle);
47
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * AvalynxAlert
3
+ *
4
+ * A simple alert system for web applications.
5
+ *
6
+ * @version 0.0.1
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
+
24
+ export class AvalynxAlert {
25
+ constructor(message, type, options = {}) {
26
+ this.message = message;
27
+ this.type = type;
28
+ this.duration = options.duration || 5000;
29
+ this.position = options.position || 'top-center';
30
+ this.closeable = options.closeable || true;
31
+ this.autoClose = options.autoClose || true;
32
+ this.width = options.width || '400px';
33
+ if (!['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'].includes(this.type)) {
34
+ this.type = 'info';
35
+ }
36
+ if (!['top-left', 'top-center', 'top-right', 'bottom-left', 'bottom-center', 'bottom-right'].includes(this.position)) {
37
+ this.position = 'top-center';
38
+ }
39
+ if (this.autoClose!==false && this.autoClose!==true) {
40
+ this.autoClose = true;
41
+ }
42
+ if ((this.closeable!==false && this.closeable!==true) || (this.autoClose===true)) {
43
+ this.closeable = true;
44
+ }
45
+
46
+ this.init();
47
+ }
48
+
49
+ ensureAlertContainer() {
50
+ if (!document.getElementById('avalynx-alert-container-' + this.position)) {
51
+ var container = document.createElement('div');
52
+ container.id = 'avalynx-alert-container-' + this.position;
53
+ container.style.width = '100%';
54
+ container.style.maxWidth = this.width;
55
+ container.style.zIndex = '1000';
56
+ container.classList.add('container-fluid');
57
+
58
+ if (this.position === 'top-left') {
59
+ container.style.position = 'fixed';
60
+ container.style.top = '10px';
61
+ container.style.left = '0px';
62
+ } else if (this.position === 'top-center') {
63
+ container.style.position = 'fixed';
64
+ container.style.top = '10px';
65
+ container.style.left = '50%';
66
+ container.style.transform = 'translateX(-50%)';
67
+ } else if (this.position === 'top-right') {
68
+ container.style.position = 'fixed';
69
+ container.style.top = '10px';
70
+ container.style.right = '0px';
71
+ } else if (this.position === 'bottom-left') {
72
+ container.style.position = 'fixed';
73
+ container.style.bottom = '10px';
74
+ container.style.left = '0px';
75
+ } else if (this.position === 'bottom-center') {
76
+ container.style.position = 'fixed';
77
+ container.style.bottom = '10px';
78
+ container.style.left = '50%';
79
+ container.style.transform = 'translateX(-50%)';
80
+ } else if (this.position === 'bottom-right') {
81
+ container.style.position = 'fixed';
82
+ container.style.bottom = '10px';
83
+ container.style.right = '0px';
84
+ }
85
+
86
+ document.body.appendChild(container);
87
+ }
88
+ }
89
+
90
+ init() {
91
+ this.ensureAlertContainer();
92
+
93
+ var alert = document.createElement('div');
94
+ alert.className = `alert alert-${this.type}`;
95
+ if (this.closeable) {
96
+ alert.classList.add('alert-dismissible');
97
+ }
98
+ alert.classList.add('fade');
99
+ alert.classList.add('show');
100
+ alert.classList.add('p-0');
101
+ alert.classList.add('overflow-hidden');
102
+ alert.classList.add('avalynx-alert');
103
+ alert.role = 'alert';
104
+ alert.innerHTML = '<div class="alert-content">' + this.message;
105
+ console.log(this.closeable);
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
+ setTimeout(() => { timerBar.style.width = '100%'; }, 10);
120
+
121
+ setTimeout(() => {
122
+ alert.classList.remove('show');
123
+ setTimeout(() => alert.remove(), 150);
124
+ }, this.duration);
125
+ }
126
+ }
127
+ }
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "avalynx-alert",
3
+ "title": "AvalynxAlert",
4
+ "description": "AvalynxAlert is a simple, lightweight, and customizable alert component for Bootstrap.",
5
+ "version": "0.0.1",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist/css/avalynx-alert.css",
9
+ "dist/js/avalynx-alert.js"
10
+ ],
11
+ "keywords": [
12
+ "alert",
13
+ "bootstrap",
14
+ "component",
15
+ "notification",
16
+ "popup"
17
+ ],
18
+ "dependencies": {
19
+ "bootstrap": ">=5.3"
20
+ },
21
+ "ignore": [
22
+ "package.json"
23
+ ],
24
+ "author": {
25
+ "name": "The Avalynx-Alert Authors",
26
+ "url": "https://github.com/avalynx/avalynx-alert/graphs/contributors"
27
+ },
28
+ "homepage": "https://github.com/avalynx/",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/avalynx/avalynx-alert.git"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/avalynx/avalynx-alert/issues"
35
+ }
36
+ }