rails_toastify 1.0.0 → 1.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfc517981d8a050d33fffb5adb0a1b570991332062839d0f68bc28795c2a36b8
4
- data.tar.gz: 291c73972c9f7d278676f95f42153bc2fcddf6bfb78ecb007712abf0c71b49b0
3
+ metadata.gz: 9e701bb2d6bfd26a8e51e688c051448bb68f6b09d5b0edd60e047e1c3609000f
4
+ data.tar.gz: f43ef70a87f3b816c5deeab1e9ad8969d800c3ea429c9aea797539c71bfaa788
5
5
  SHA512:
6
- metadata.gz: 1e04322f2c8a0c85f4436e3de91ebbe782d23e31965b1ad101cd1ab4c64ebfdfd8a41b05e078ad1cf0e2e0ca68867d538344979b13c88d6f3b6907c41f9d178a
7
- data.tar.gz: 23a755965aaa27fb5aa8f33683cbbf701919806310074414faa8831167423237ab0659f30936891c9a7ed079bb24c5f49607b3e033050d16d7fd4cd658b97469
6
+ metadata.gz: 6237ad77aea9dc367aa4a21590cbcd95b01680cef1370d6db7914d9f257499c2d13cc299f958a2f722a5db9d71969d321799a680b3530f63b686c9828d779399
7
+ data.tar.gz: 2c05603ad580b88f8be579fa649a8f1a1d67c8090291a7cf5e9496844fc7b2690e94447da39e535d57cdcf7eb972304547ef40e3992cea54009cf3e08dbeaae3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 1.1.0
2
+
3
+ - Add others configurations (position, animation, duration, theme and type)
4
+ - Change CSS to new configurations
5
+ - Change JS to new configurations
6
+ - Add default configurations
7
+
1
8
  ## 1.0.0
2
9
 
3
10
  - Version stable tested and approved
@@ -1,72 +1,76 @@
1
- document.addEventListener('DOMContentLoaded', () => {
2
- window.RailsToastify = {
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
- let startTime = Date.now();
9
- let remainingTime = duration;
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
- const hideToast = () => {
12
- toast.classList.add('hide');
13
- toast.addEventListener('transitionend', () => toast.remove());
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
- let timeoutId = setTimeout(hideToast, remainingTime);
18
+ toastContainer.appendChild(toast);
19
+ toastIdCounter++;
17
20
 
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
- });
21
+ const progressBar = toast.querySelector('.progress-bar');
22
+ progressBar.style.width = '100%';
24
23
 
25
- toast.addEventListener('mouseout', () => {
26
- startTime = Date.now();
27
- toast.querySelector('.toast__progress-bar').style.animationPlayState = 'running';
28
- timeoutId = setTimeout(hideToast, remainingTime);
29
- });
30
- }
31
- };
24
+ let remainingTime = options.duration;
25
+ let lastUpdateTime = Date.now();
26
+ let paused = false;
27
+ let intervalId;
32
28
 
33
- function createToastContainer() {
34
- const container = document.createElement('div');
35
- container.className = 'toast-container';
36
- document.body.appendChild(container);
37
- return container;
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
- function createToast(message, type, duration) {
41
- const toast = document.createElement('div');
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
- const closeButton = document.createElement('button');
46
- closeButton.className = 'toast__close-button';
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>';
48
- closeButton.addEventListener('click', () => {
49
- toast.classList.add('hide');
50
- toast.addEventListener('transitionend', () => toast.remove());
51
- });
52
-
53
- const progressBar = document.createElement('div');
54
- progressBar.className = `toast__progress-bar toast__progress-bar--${type}`;
55
- progressBar.style.animationDuration = `${duration}ms`;
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
- const body = document.createElement('div');
58
- body.className = 'toast__body';
59
- body.textContent = message;
51
+ toast.addEventListener('mouseover', () => {
52
+ paused = true;
53
+ });
60
54
 
61
- toast.appendChild(body);
62
- toast.appendChild(closeButton);
63
- toast.appendChild(progressBar);
55
+ toast.addEventListener('mouseout', () => {
56
+ paused = false;
57
+ lastUpdateTime = Date.now();
58
+ });
64
59
 
65
- toast.addEventListener('click', () => {
66
- toast.classList.add('hide');
67
- toast.addEventListener('transitionend', () => toast.remove());
68
- });
60
+ intervalId = setInterval(updateProgressBar, 100);
61
+ }
69
62
 
70
- return toast;
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
- <% if RailsToastify.configuration.framework == :bootstrap %>
2
- .toast-container {
3
- position: fixed;
4
- z-index: 9999;
5
- pointer-events: none;
6
- top: 20px;
7
- right: 20px;
8
- }
9
-
10
- .toast {
11
- display: flex;
12
- align-items: center;
13
- background-color: #fff;
14
- border-radius: 4px;
15
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.06);
16
- padding: 16px;
17
- margin: 8px;
18
- color: #333;
19
- position: relative;
20
- transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out;
21
- transform: translateX(100%);
22
- max-width: 300px;
23
- pointer-events: auto;
24
- }
25
-
26
- .toast.show {
27
- transform: translateX(0);
28
- }
29
-
30
- .toast.hide {
31
- transform: translateX(100%);
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
- .toast__progress-bar {
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
- <% elsif RailsToastify.configuration.framework == :tailwind %>
86
- .toast-container {
87
- @apply fixed z-50 pointer-events-none top-4 right-4;
133
+ 90% {
134
+ transform: translate3d(-5px, 0, 0);
88
135
  }
89
-
90
- .toast {
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
- .toast.show {
97
- transform: translateX(0);
98
- }
141
+ .toast.bounce {
142
+ animation: bounce-all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
143
+ }
99
144
 
100
- .toast.hide {
145
+ /* SLIDE */
146
+ @keyframes slide-in {
147
+ 0% {
101
148
  transform: translateX(100%);
102
149
  opacity: 0;
103
150
  }
104
-
105
- .toast--success .toast__progress-bar {
106
- @apply bg-green-500;
151
+ 100% {
152
+ transform: translateX(0);
153
+ opacity: 1;
107
154
  }
155
+ }
108
156
 
109
- .toast--error .toast__progress-bar {
110
- @apply bg-red-500;
111
- }
157
+ .toast.slide {
158
+ animation: slide-in 0.2s ease-out;
159
+ }
112
160
 
113
- .toast--info .toast__progress-bar {
114
- @apply bg-blue-500;
161
+ /* ZOOM */
162
+ @keyframes zoom-in {
163
+ 0% {
164
+ transform: scale(0);
165
+ opacity: 0;
115
166
  }
116
-
117
- .toast--warning .toast__progress-bar {
118
- @apply bg-yellow-500;
167
+ 100% {
168
+ transform: scale(1);
169
+ opacity: 1;
119
170
  }
171
+ }
120
172
 
121
- .toast__close-button {
122
- @apply text-gray-800 bg-transparent border-none p-0 cursor-pointer opacity-70 transition-opacity duration-300 self-start ml-auto;
123
- &:hover {
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
- .toast__progress-bar {
129
- @apply absolute bottom-0 left-0 w-full h-1;
130
- animation: progress-bar 5s linear forwards;
131
- animation-play-state: running;
177
+ /* FLIP */
178
+ @keyframes flip-in {
179
+ 0% {
180
+ transform: rotateY(-90deg);
181
+ opacity: 0;
132
182
  }
133
-
134
- @keyframes progress-bar {
135
- from {
136
- width: 100%;
137
- }
138
- to {
139
- width: 0;
140
- }
183
+ 100% {
184
+ transform: rotateY(0);
185
+ opacity: 1;
141
186
  }
142
- <% end %>
187
+ }
188
+
189
+ .toast.flip {
190
+ animation: flip-in 0.5s ease-in-out;
191
+ }
@@ -0,0 +1,29 @@
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
+ config: #{RailsToastify.configuration.to_h.to_json},
12
+ show: function(message, options) {
13
+ options = Object.assign({}, this.config, options || {});
14
+ showToast(message, options);
15
+ }
16
+ };
17
+ });
18
+ JS
19
+ end
20
+ end
21
+
22
+ def show_toast(message, options = {})
23
+ javascript_tag do
24
+ <<-JS.html_safe
25
+ RailsToastify.show(#{message.to_json}, #{options.to_json});
26
+ JS
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,7 @@
1
- RailsToastify.setup do |config|
2
- config.framework = :tailwind #or :bootstrap
1
+ RailsToastify.setup do |configuration|
2
+ configuration.position = 'toast-container-top-right'
3
+ configuration.animation = 'bounce'
4
+ configuration.duration = 5000
5
+ configuration.theme = 'light'
6
+ configuration.type = 'default'
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsToastify
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.1"
5
5
  end
@@ -14,10 +14,24 @@ module RailsToastify
14
14
  end
15
15
 
16
16
  class Configuration
17
- attr_accessor :framework
17
+ attr_accessor :position, :animation, :duration, :theme, :type
18
18
 
19
19
  def initialize
20
- @framework = :tailwind
20
+ @position = 'toast-container-top-right'
21
+ @animation = 'bounce'
22
+ @duration = 5000
23
+ @theme = 'light'
24
+ @type = 'default'
25
+ end
26
+
27
+ def to_h
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.0.0
4
+ version: 1.1.1
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-07-03 00:00:00.000000000 Z
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