rails_toastify 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +8 -0
- data/app/assets/javascripts/rails_toastify.js +27 -10
- data/app/assets/stylesheets/rails_toastify.css +6 -3
- data/lib/rails_toastify/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6d828b6b26290af46ef2beb27cbd662e963f2b8b9969e55a782ce34a5a4bf4d
|
4
|
+
data.tar.gz: 768fa851fdcb5d66f8e692346f0d13fa3d99e75bfc69683a6d2f022b09b78139
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 845a520486d658392542d67daf6e70b5b72fb4854c04e05b497f4b2d89f421040bcedf5a08b871c9827745420d2d3ea7e8a1523c09ecf9bf56d429fc04e5ec5a
|
7
|
+
data.tar.gz: '00893d8c3e0237247046bdea15d9a01a418f684037c398a707bac9f91a033012667ccac26620de2cc0123f623681cea0c0e28ae0a3337d3a6e8c1d400fb28107'
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -56,6 +56,14 @@ RailsToastify.showToast('This is an info message!', 'info');
|
|
56
56
|
RailsToastify.showToast('This is a warning message!', 'warning');
|
57
57
|
```
|
58
58
|
|
59
|
+
To see notice in a toast add:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
<%= javascript_tag do %>
|
63
|
+
RailsToastify.showToast('<%= notice %>', 'success')
|
64
|
+
<% end %>
|
65
|
+
```
|
66
|
+
|
59
67
|
## Requirements
|
60
68
|
|
61
69
|
- Ruby >= 2.6.0 (recommended 2.7+)
|
@@ -4,10 +4,29 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
4
4
|
const toastContainer = document.querySelector('.toast-container') || createToastContainer();
|
5
5
|
const toast = createToast(message, type, duration);
|
6
6
|
toastContainer.appendChild(toast);
|
7
|
-
|
7
|
+
|
8
|
+
let startTime = Date.now();
|
9
|
+
let remainingTime = duration;
|
10
|
+
|
11
|
+
const hideToast = () => {
|
8
12
|
toast.classList.add('hide');
|
9
13
|
toast.addEventListener('transitionend', () => toast.remove());
|
10
|
-
}
|
14
|
+
};
|
15
|
+
|
16
|
+
let timeoutId = setTimeout(hideToast, remainingTime);
|
17
|
+
|
18
|
+
toast.addEventListener('mouseover', () => {
|
19
|
+
clearTimeout(timeoutId);
|
20
|
+
const elapsedTime = Date.now() - startTime;
|
21
|
+
remainingTime -= elapsedTime;
|
22
|
+
toast.querySelector('.toast__progress-bar').style.animationPlayState = 'paused';
|
23
|
+
});
|
24
|
+
|
25
|
+
toast.addEventListener('mouseout', () => {
|
26
|
+
startTime = Date.now();
|
27
|
+
toast.querySelector('.toast__progress-bar').style.animationPlayState = 'running';
|
28
|
+
timeoutId = setTimeout(hideToast, remainingTime);
|
29
|
+
});
|
11
30
|
}
|
12
31
|
};
|
13
32
|
|
@@ -22,7 +41,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
22
41
|
const toast = document.createElement('div');
|
23
42
|
toast.className = `toast toast--${type}`;
|
24
43
|
toast.classList.add('show');
|
25
|
-
|
44
|
+
|
26
45
|
const closeButton = document.createElement('button');
|
27
46
|
closeButton.className = 'toast__close-button';
|
28
47
|
closeButton.innerHTML = '<svg aria-hidden="true" viewBox="0 0 14 16"><path fill-rule="evenodd" d="M7.71 8.23l3.75 3.75-1.48 1.48-3.75-3.75-3.75 3.75L1 11.98l3.75-3.75L1 4.48 2.48 3l3.75 3.75L9.98 3l1.48 1.48-3.75 3.75z"></path></svg>';
|
@@ -30,26 +49,24 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
30
49
|
toast.classList.add('hide');
|
31
50
|
toast.addEventListener('transitionend', () => toast.remove());
|
32
51
|
});
|
33
|
-
|
52
|
+
|
34
53
|
const progressBar = document.createElement('div');
|
35
54
|
progressBar.className = `toast__progress-bar toast__progress-bar--${type}`;
|
36
55
|
progressBar.style.animationDuration = `${duration}ms`;
|
37
|
-
|
56
|
+
|
38
57
|
const body = document.createElement('div');
|
39
58
|
body.className = 'toast__body';
|
40
59
|
body.textContent = message;
|
41
|
-
|
60
|
+
|
42
61
|
toast.appendChild(body);
|
43
62
|
toast.appendChild(closeButton);
|
44
63
|
toast.appendChild(progressBar);
|
45
|
-
|
64
|
+
|
46
65
|
toast.addEventListener('click', () => {
|
47
66
|
toast.classList.add('hide');
|
48
67
|
toast.addEventListener('transitionend', () => toast.remove());
|
49
68
|
});
|
50
|
-
|
51
|
-
toast.addEventListener('mouseout', () => progressBar.style.animationPlayState = 'running');
|
52
|
-
|
69
|
+
|
53
70
|
return toast;
|
54
71
|
}
|
55
72
|
});
|
@@ -20,6 +20,7 @@
|
|
20
20
|
transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
|
21
21
|
transform: translateX(100%);
|
22
22
|
max-width: 300px;
|
23
|
+
pointer-events: auto;
|
23
24
|
}
|
24
25
|
|
25
26
|
.toast.show {
|
@@ -70,6 +71,7 @@
|
|
70
71
|
width: 100%;
|
71
72
|
height: 4px;
|
72
73
|
animation: progress-bar 5s linear forwards;
|
74
|
+
animation-play-state: running;
|
73
75
|
}
|
74
76
|
|
75
77
|
@keyframes progress-bar {
|
@@ -86,15 +88,15 @@
|
|
86
88
|
}
|
87
89
|
|
88
90
|
.toast {
|
89
|
-
@apply flex items-center bg-white rounded-lg shadow-lg p-4 my-2 text-gray-800 relative max-w-sm;
|
91
|
+
@apply flex items-center bg-white rounded-lg shadow-lg p-4 my-2 text-gray-800 relative max-w-sm pointer-events-auto;
|
90
92
|
transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
|
91
93
|
transform: translateX(100%);
|
92
94
|
}
|
93
|
-
|
95
|
+
|
94
96
|
.toast.show {
|
95
97
|
transform: translateX(0);
|
96
98
|
}
|
97
|
-
|
99
|
+
|
98
100
|
.toast.hide {
|
99
101
|
transform: translateX(100%);
|
100
102
|
opacity: 0;
|
@@ -126,6 +128,7 @@
|
|
126
128
|
.toast__progress-bar {
|
127
129
|
@apply absolute bottom-0 left-0 w-full h-1;
|
128
130
|
animation: progress-bar 5s linear forwards;
|
131
|
+
animation-play-state: running;
|
129
132
|
}
|
130
133
|
|
131
134
|
@keyframes progress-bar {
|