rails_toastify 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/app/assets/javascripts/rails_toastify.js +63 -59
- data/app/assets/stylesheets/rails_toastify.css +170 -121
- data/app/helpers/rails_toastify_helper.rb +21 -0
- data/lib/generators/rails_toastify/install/templates/rails_toastify.rb +6 -2
- data/lib/rails_toastify/engine.rb +8 -0
- data/lib/rails_toastify/version.rb +1 -1
- data/lib/rails_toastify.rb +16 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1426b7aba09cf180dfc97ea0ab32f685c9a3b56f9ca86a8f50b1184cae74c38a
|
4
|
+
data.tar.gz: 67aff9d7c8abe089bb54a1b97e1350e4e28a2d97e36ce600e51a3e826f09226b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cb4bf38f4460fdd488f5a068d37ccb8295bcc67f2a6d99ad008a7dcf8a942941266730170d8c2c466a1e48e389f72c8fe236474eab57149c9fac9f1830b3331
|
7
|
+
data.tar.gz: 04bbc058a1c816233907d8c8160b9c25d77acd0cf36470826df636934fdc7cbd8b4406305582246d2447eff946946710887ef9c1e1dbbb9766874a5eadf912c4
|
data/CHANGELOG.md
CHANGED
@@ -1,72 +1,76 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
showToast(message, type = 'info', duration = 5000) {
|
4
|
-
const toastContainer = document.querySelector('.toast-container') || createToastContainer();
|
5
|
-
const toast = createToast(message, type, duration);
|
6
|
-
toastContainer.appendChild(toast);
|
1
|
+
const totalDuration = 3000;
|
2
|
+
let toastIdCounter = 0;
|
7
3
|
|
8
|
-
|
9
|
-
|
4
|
+
function showToast(message, options) {
|
5
|
+
const toastContainer = document.getElementById('toast-container');
|
6
|
+
|
7
|
+
const toast = document.createElement('div');
|
8
|
+
toast.className = `toast toast-${options.theme} show ${options.animation}`;
|
9
|
+
toast.id = `toast-${toastIdCounter}`;
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
/* Adicione a respectiva classe para mudar a cor da progress-bar */
|
12
|
+
toast.innerHTML = `
|
13
|
+
<div>${message}</div>
|
14
|
+
<div class="progress-bar progress-bar-${options.type}" id="progress-bar-${toastIdCounter}"></div>
|
15
|
+
<span class="close-icon" onclick="hideToast(${toastIdCounter})"><i class="fas fa-times"></i></span>
|
16
|
+
`;
|
15
17
|
|
16
|
-
|
18
|
+
toastContainer.appendChild(toast);
|
19
|
+
toastIdCounter++;
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
const elapsedTime = Date.now() - startTime;
|
21
|
-
remainingTime -= elapsedTime;
|
22
|
-
toast.querySelector('.toast__progress-bar').style.animationPlayState = 'paused';
|
23
|
-
});
|
21
|
+
const progressBar = toast.querySelector('.progress-bar');
|
22
|
+
progressBar.style.width = '100%';
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
});
|
30
|
-
}
|
31
|
-
};
|
24
|
+
let remainingTime = options.duration;
|
25
|
+
let lastUpdateTime = Date.now();
|
26
|
+
let paused = false;
|
27
|
+
let intervalId;
|
32
28
|
|
33
|
-
function
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
function updateProgressBar() {
|
30
|
+
if (!paused) {
|
31
|
+
const currentTime = Date.now();
|
32
|
+
const elapsedTime = currentTime - lastUpdateTime;
|
33
|
+
remainingTime -= elapsedTime;
|
34
|
+
lastUpdateTime = currentTime;
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
toast.className = `toast toast--${type}`;
|
43
|
-
toast.classList.add('show');
|
36
|
+
const progress = (remainingTime / totalDuration) * 100;
|
37
|
+
progressBar.style.width = `${progress}%`;
|
44
38
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
39
|
+
if (remainingTime <= 0) {
|
40
|
+
clearInterval(intervalId);
|
41
|
+
toast.classList.remove('show');
|
42
|
+
toast.classList.add('hide');
|
43
|
+
setTimeout(() => {
|
44
|
+
toast.parentElement.removeChild(toast);
|
45
|
+
}, 300);
|
46
|
+
return;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
56
50
|
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
toast.addEventListener('mouseover', () => {
|
52
|
+
paused = true;
|
53
|
+
});
|
60
54
|
|
61
|
-
|
62
|
-
|
63
|
-
|
55
|
+
toast.addEventListener('mouseout', () => {
|
56
|
+
paused = false;
|
57
|
+
lastUpdateTime = Date.now();
|
58
|
+
});
|
64
59
|
|
65
|
-
|
66
|
-
|
67
|
-
toast.addEventListener('transitionend', () => toast.remove());
|
68
|
-
});
|
60
|
+
intervalId = setInterval(updateProgressBar, 100);
|
61
|
+
}
|
69
62
|
|
70
|
-
|
63
|
+
function hideToast(toastId) {
|
64
|
+
const toast = document.getElementById(`toast-${toastId}`);
|
65
|
+
if (toast) {
|
66
|
+
toast.classList.remove('show');
|
67
|
+
toast.classList.add('hide');
|
68
|
+
setTimeout(() => {
|
69
|
+
toast.parentElement.removeChild(toast);
|
70
|
+
}, 300);
|
71
71
|
}
|
72
|
-
}
|
72
|
+
}
|
73
|
+
|
74
|
+
window.hideToast = hideToast;
|
75
|
+
|
76
|
+
/* showToast('slide'); */
|
@@ -1,142 +1,191 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
.toast-container {
|
2
|
+
position: fixed;
|
3
|
+
/**POSITION**/
|
4
|
+
top: 20px;
|
5
|
+
right: 20px;
|
6
|
+
/************/
|
7
|
+
display: flex;
|
8
|
+
flex-direction: column;
|
9
|
+
gap: 10px;
|
10
|
+
}
|
11
|
+
|
12
|
+
.toast {
|
13
|
+
/**THEME**/
|
14
|
+
/* background e color serão adicionados através da classe escolhida colocando a respectiva toast-light ou toast-dark no javascript */
|
15
|
+
background-color: #fff;
|
16
|
+
color: #333;
|
17
|
+
/************/
|
18
|
+
padding: 20px;
|
19
|
+
border-radius: 5px;
|
20
|
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
21
|
+
opacity: 0;
|
22
|
+
transition: opacity 0.3s ease-in-out;
|
23
|
+
display: flex;
|
24
|
+
align-items: center;
|
25
|
+
justify-content: space-between;
|
26
|
+
overflow: hidden;
|
27
|
+
position: relative;
|
28
|
+
}
|
29
|
+
|
30
|
+
.toast.show {
|
31
|
+
opacity: 1;
|
32
|
+
}
|
33
|
+
|
34
|
+
.close-icon {
|
35
|
+
margin-left: 10px;
|
36
|
+
cursor: pointer;
|
37
|
+
}
|
38
|
+
|
39
|
+
.progress-bar {
|
40
|
+
height: 5px;
|
41
|
+
width: 100%;
|
42
|
+
/**TYPE**/
|
43
|
+
/* background será adicionado através da classe escolhida colocando a respectiva progress bar no javascript */
|
44
|
+
/* background: linear-gradient(90deg,#4cd964,#5ac8fa,#007aff,#34aadc,#5856d6,#ff2d55); */
|
45
|
+
/************/
|
46
|
+
position: absolute;
|
47
|
+
bottom: 0;
|
48
|
+
left: 0;
|
49
|
+
transition: width 0.1s linear;
|
50
|
+
}
|
51
|
+
|
52
|
+
/* THEME */
|
53
|
+
.toast-light {
|
54
|
+
background-color: #fff;
|
55
|
+
color: #333;
|
56
|
+
}
|
57
|
+
.toast-dark {
|
58
|
+
background-color: #333;
|
59
|
+
color: #fff;
|
60
|
+
}
|
61
|
+
|
62
|
+
/* TYPE */
|
63
|
+
.progress-bar-success {
|
64
|
+
background-color: #4caf50;
|
65
|
+
}
|
66
|
+
.progress-bar-info {
|
67
|
+
background-color: #2196f3;
|
68
|
+
}
|
69
|
+
.progress-bar-error {
|
70
|
+
background-color: #f44336;
|
71
|
+
}
|
72
|
+
.progress-bar-warning {
|
73
|
+
background-color: #ff9800;
|
74
|
+
}
|
75
|
+
.progress-bar-default {
|
76
|
+
background: linear-gradient(90deg,#4cd964,#5ac8fa,#007aff,#34aadc,#5856d6,#ff2d55);
|
77
|
+
}
|
78
|
+
|
79
|
+
/* POSITION */
|
80
|
+
.toast-container-top-left {
|
81
|
+
top: 20px;
|
82
|
+
left: 20px;
|
83
|
+
}
|
84
|
+
.toast-container-top-right {
|
85
|
+
top: 20px;
|
86
|
+
right: 20px;
|
87
|
+
}
|
88
|
+
.toast-container-bottom-left {
|
89
|
+
bottom: 20px;
|
90
|
+
left: 20px;
|
91
|
+
}
|
92
|
+
.toast-container-bottom-right {
|
93
|
+
bottom: 20px;
|
94
|
+
right: 20px;
|
95
|
+
}
|
96
|
+
|
97
|
+
/* ANIMATION */
|
98
|
+
/* BOUNCE */
|
99
|
+
/* @keyframes bounce-in {
|
100
|
+
0% {
|
101
|
+
transform: scale(0.8);
|
102
|
+
}
|
103
|
+
50% {
|
104
|
+
transform: scale(1.1);
|
105
|
+
}
|
106
|
+
100% {
|
107
|
+
transform: scale(1);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
.toast.bounce {
|
112
|
+
animation: bounce-in 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
|
113
|
+
} */
|
114
|
+
|
115
|
+
@keyframes bounce-all {
|
116
|
+
from,
|
117
|
+
60%,
|
118
|
+
75%,
|
119
|
+
90%,
|
120
|
+
to {
|
121
|
+
}
|
122
|
+
from {
|
32
123
|
opacity: 0;
|
124
|
+
transform: translate3d(500px, 0, 0);
|
33
125
|
}
|
34
|
-
|
35
|
-
.toast--success .toast__progress-bar {
|
36
|
-
background-color: #4caf50;
|
37
|
-
}
|
38
|
-
|
39
|
-
.toast--error .toast__progress-bar {
|
40
|
-
background-color: #f44336;
|
41
|
-
}
|
42
|
-
|
43
|
-
.toast--info .toast__progress-bar {
|
44
|
-
background-color: #2196f3;
|
45
|
-
}
|
46
|
-
|
47
|
-
.toast--warning .toast__progress-bar {
|
48
|
-
background-color: #ff9800;
|
49
|
-
}
|
50
|
-
|
51
|
-
.toast__close-button {
|
52
|
-
color: #333;
|
53
|
-
background-color: transparent;
|
54
|
-
border: none;
|
55
|
-
padding: 0;
|
56
|
-
cursor: pointer;
|
57
|
-
opacity: 0.7;
|
58
|
-
transition: opacity 0.3s;
|
59
|
-
align-self: flex-start;
|
60
|
-
margin-left: auto;
|
61
|
-
}
|
62
|
-
|
63
|
-
.toast__close-button:hover {
|
126
|
+
60% {
|
64
127
|
opacity: 1;
|
128
|
+
transform: translate3d(-25px, 0, 0);
|
65
129
|
}
|
66
|
-
|
67
|
-
|
68
|
-
position: absolute;
|
69
|
-
bottom: 0;
|
70
|
-
left: 0;
|
71
|
-
width: 100%;
|
72
|
-
height: 4px;
|
73
|
-
animation: progress-bar 5s linear forwards;
|
74
|
-
animation-play-state: running;
|
75
|
-
}
|
76
|
-
|
77
|
-
@keyframes progress-bar {
|
78
|
-
from {
|
79
|
-
width: 100%;
|
80
|
-
}
|
81
|
-
to {
|
82
|
-
width: 0;
|
83
|
-
}
|
130
|
+
75% {
|
131
|
+
transform: translate3d(10px, 0, 0);
|
84
132
|
}
|
85
|
-
|
86
|
-
|
87
|
-
@apply fixed z-50 pointer-events-none top-4 right-4;
|
133
|
+
90% {
|
134
|
+
transform: translate3d(-5px, 0, 0);
|
88
135
|
}
|
89
|
-
|
90
|
-
|
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;
|
92
|
-
transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
|
93
|
-
transform: translateX(100%);
|
136
|
+
to {
|
137
|
+
transform: none;
|
94
138
|
}
|
139
|
+
}
|
95
140
|
|
96
|
-
|
97
|
-
|
98
|
-
|
141
|
+
.toast.bounce {
|
142
|
+
animation: bounce-all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
|
143
|
+
}
|
99
144
|
|
100
|
-
|
145
|
+
/* SLIDE */
|
146
|
+
@keyframes slide-in {
|
147
|
+
0% {
|
101
148
|
transform: translateX(100%);
|
102
149
|
opacity: 0;
|
103
150
|
}
|
104
|
-
|
105
|
-
|
106
|
-
|
151
|
+
100% {
|
152
|
+
transform: translateX(0);
|
153
|
+
opacity: 1;
|
107
154
|
}
|
155
|
+
}
|
108
156
|
|
109
|
-
|
110
|
-
|
111
|
-
|
157
|
+
.toast.slide {
|
158
|
+
animation: slide-in 0.2s ease-out;
|
159
|
+
}
|
112
160
|
|
113
|
-
|
114
|
-
|
161
|
+
/* ZOOM */
|
162
|
+
@keyframes zoom-in {
|
163
|
+
0% {
|
164
|
+
transform: scale(0);
|
165
|
+
opacity: 0;
|
115
166
|
}
|
116
|
-
|
117
|
-
|
118
|
-
|
167
|
+
100% {
|
168
|
+
transform: scale(1);
|
169
|
+
opacity: 1;
|
119
170
|
}
|
171
|
+
}
|
120
172
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
@apply opacity-100;
|
125
|
-
}
|
126
|
-
}
|
173
|
+
.toast.zoom {
|
174
|
+
animation: zoom-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
175
|
+
}
|
127
176
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
177
|
+
/* FLIP */
|
178
|
+
@keyframes flip-in {
|
179
|
+
0% {
|
180
|
+
transform: rotateY(-90deg);
|
181
|
+
opacity: 0;
|
132
182
|
}
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
width: 100%;
|
137
|
-
}
|
138
|
-
to {
|
139
|
-
width: 0;
|
140
|
-
}
|
183
|
+
100% {
|
184
|
+
transform: rotateY(0);
|
185
|
+
opacity: 1;
|
141
186
|
}
|
142
|
-
|
187
|
+
}
|
188
|
+
|
189
|
+
.toast.flip {
|
190
|
+
animation: flip-in 0.5s ease-in-out;
|
191
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module RailsToastifyHelper
|
2
|
+
def rails_toastify_container
|
3
|
+
content_tag :div, '', id: 'toast-container', class: "toast-container #{RailsToastify.configuration.position}"
|
4
|
+
end
|
5
|
+
|
6
|
+
def rails_toastify_script
|
7
|
+
javascript_tag do
|
8
|
+
<<-JS.html_safe
|
9
|
+
document.addEventListener('DOMContentLoaded', function() {
|
10
|
+
window.RailsToastify = {
|
11
|
+
show: function(message, options) {
|
12
|
+
var config = #{RailsToastify.configuration.to_json};
|
13
|
+
options = options || {};
|
14
|
+
showToast(message, Object.assign({}, config, options));
|
15
|
+
}
|
16
|
+
};
|
17
|
+
});
|
18
|
+
JS
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,3 +1,7 @@
|
|
1
|
-
RailsToastify.setup do |
|
2
|
-
|
1
|
+
RailsToastify.setup do |configuration|
|
2
|
+
configuration.position = 'toast-container-bottom-right'
|
3
|
+
configuration.animation = 'zoom'
|
4
|
+
configuration.duration = 5000
|
5
|
+
configuration.theme = 'dark'
|
6
|
+
configuration.type = 'success'
|
3
7
|
end
|
@@ -1,7 +1,15 @@
|
|
1
1
|
module RailsToastify
|
2
2
|
class Engine < ::Rails::Engine
|
3
|
+
isolate_namespace RailsToastify
|
4
|
+
|
3
5
|
initializer 'rails_toastify.assets.precompile' do |app|
|
4
6
|
app.config.assets.precompile += %w(rails_toastify.js rails_toastify.css)
|
5
7
|
end
|
8
|
+
|
9
|
+
initializer 'rails_toastify.helpers' do
|
10
|
+
ActiveSupport.on_load(:action_view) do
|
11
|
+
include RailsToastifyHelper
|
12
|
+
end
|
13
|
+
end
|
6
14
|
end
|
7
15
|
end
|
data/lib/rails_toastify.rb
CHANGED
@@ -14,10 +14,24 @@ module RailsToastify
|
|
14
14
|
end
|
15
15
|
|
16
16
|
class Configuration
|
17
|
-
attr_accessor :
|
17
|
+
attr_accessor :position, :animation, :duration, :theme, :type
|
18
18
|
|
19
19
|
def initialize
|
20
|
-
@
|
20
|
+
@position = 'toast-container-bottom-right'
|
21
|
+
@animation = 'bounce'
|
22
|
+
@duration = 5000
|
23
|
+
@theme = 'light'
|
24
|
+
@type = 'default'
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_json
|
28
|
+
{
|
29
|
+
position: @position,
|
30
|
+
animation: @animation,
|
31
|
+
duration: @duration,
|
32
|
+
theme: @theme,
|
33
|
+
type: @type
|
34
|
+
}.to_json
|
21
35
|
end
|
22
36
|
end
|
23
37
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_toastify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elton Santos
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: "\U0001F389 Rails Toastify allows you to add notifications to your app
|
14
14
|
with ease. Pay Attention: this gem still is in development. Please CONTRIBUTE"
|
@@ -24,6 +24,7 @@ files:
|
|
24
24
|
- Rakefile
|
25
25
|
- app/assets/javascripts/rails_toastify.js
|
26
26
|
- app/assets/stylesheets/rails_toastify.css
|
27
|
+
- app/helpers/rails_toastify_helper.rb
|
27
28
|
- lib/generators/rails_toastify/install/install_generator.rb
|
28
29
|
- lib/generators/rails_toastify/install/templates/rails_toastify.rb
|
29
30
|
- lib/rails_toastify.rb
|