faw_toast 1.0.0 → 1.2.0

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: 9d9054fe80f547f53c0c5bd6609cac4df141296d3ee4fbd28ba01ec3f74fe49b
4
- data.tar.gz: 559b7cb87dbaf08f34bf9b6bc9f6a2088b9b148eec850316967b3448eb9c968f
3
+ metadata.gz: b381797da514941ee2394cd7bcc634016d1af89942057800a7aab6c7a0c02435
4
+ data.tar.gz: 8d6e392357aea77ba878035fd476efc8f2d0f0db944abeccecc13e7dd2e738a4
5
5
  SHA512:
6
- metadata.gz: d0a8f13a9addd28afbf43dcb1c689d7a2ef418a9fce531e34bb7177afaad2289eb75b8c591894edb516ea1edbb9d1fec52518912fcb9de13b388597f1165e44c
7
- data.tar.gz: ad1c7c85ddfdd1364ba1ded85c704c6427c7198cc0d797b760cd877c929f14dd0a9a36fc837747d010cffb37200dbb864d706c259230fc74865218c558e50a32
6
+ metadata.gz: 2ad38aa056e63c5c9cc82f13f8958c68cc3afe233793589d324f833124427fb21843ee486d987c72ce9675fc0661c3342b8600123ab3d49d90942b253bc3c9a3
7
+ data.tar.gz: 340e8bd832e3b8280c2137be0be7def84f918e825e4476e9e3ed4e854a4d735e8c7b62e4e37835ab257fee1c4de388cd2f1c9de030c6474e4a3fd995d05af31c
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # FawToast
2
-
3
2
  A simple, configurable toast notification system for Rails applications. FawToast provides an easy way to display flash messages as toast notifications with minimal setup.
4
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/faw_toast.svg)](https://badge.fury.io/rb/faw_toast)
5
+
5
6
  ## Features
6
7
 
7
8
  - Easy integration with Rails 7+ applications
@@ -40,11 +41,23 @@ rails generate faw_toast:install
40
41
  This will:
41
42
  1. Create a configuration initializer at `config/initializers/faw_toast.rb`
42
43
  2. Add the toast container to your application layout
43
- 3. Import the required stylesheet and JavaScript controller
44
+
45
+ Include the css and javascript files in your `application.html.erb` layout file.
46
+
47
+ For `propshaft`
48
+ ```erb
49
+ <%= stylesheet_link_tag "faw_toast", "data-turbo-track": "reload" %>
50
+ <%= javascript_include_tag "faw_toast", "data-turbo-track": "reload", type: "module" %>
51
+ ```
52
+ and if you are using `sprockets` include the following lines in your `config/manifest.js`
53
+ ```javascript
54
+ //= link faw_toast.js
55
+ //= link faw_toast.css
56
+ ```
44
57
 
45
58
  ## Usage
46
59
 
47
- FawToast works with Rails flash messages. You can use it like this:
60
+ FawToast works with Rails flash messages. You can use it like this
48
61
 
49
62
  ```ruby
50
63
  # In your controller
@@ -55,6 +68,18 @@ def create
55
68
  end
56
69
  ```
57
70
 
71
+ ```ruby
72
+ # In your background job or service object
73
+ flash = {}
74
+ flash[type] = message
75
+ Turbo::StreamsChannel.broadcast_append_to(
76
+ channel,
77
+ target: "faw-toast-container",
78
+ partial: "faw_toast/toast",
79
+ locals: { flash: flash }
80
+ )
81
+ ```
82
+
58
83
  FawToast supports the following flash types out of the box:
59
84
  - `:success` - Green border
60
85
  - `:alert` - Red border
@@ -94,7 +119,7 @@ FawToast uses CSS animations to show and hide toast notifications automatically.
94
119
  2. The flash message content
95
120
  3. A progress bar that indicates how much time is left before the toast disappears
96
121
 
97
- The toast appears with a slide-in animation, stays visible for the configured duration, and then slides out automatically. No JavaScript interaction is required for the basic functionality.
122
+ The toast appears with a slide-in animation, stays visible for the configured duration, and then slides out automatically
98
123
 
99
124
  ## Development
100
125
 
@@ -1,12 +1,10 @@
1
- // Self-initializing toast handler
2
- document.addEventListener('DOMContentLoaded', function() {
3
- console.log('DOMContentLoaded');
4
- // Function to handle toast animations
1
+ document.addEventListener('DOMContentLoaded', faw_init);
2
+ document.addEventListener('turbo:load', faw_init);
3
+
4
+ function faw_init() {
5
5
  function setupToastListeners() {
6
- // Find all toast elements
7
6
  const toasts = document.querySelectorAll('.faw-toast');
8
7
 
9
- // Add animation end listeners to each toast
10
8
  toasts.forEach(function(toast) {
11
9
  toast.addEventListener('animationend', function(event) {
12
10
  // Only remove the toast when the slideOut animation completes
@@ -17,10 +15,8 @@ document.addEventListener('DOMContentLoaded', function() {
17
15
  });
18
16
  }
19
17
 
20
- // Initial setup
21
18
  setupToastListeners();
22
19
 
23
- // Also handle dynamically added toasts (for turbo/ajax)
24
20
  const observer = new MutationObserver(function(mutations) {
25
21
  mutations.forEach(function(mutation) {
26
22
  if (mutation.addedNodes.length) {
@@ -29,9 +25,8 @@ document.addEventListener('DOMContentLoaded', function() {
29
25
  });
30
26
  });
31
27
 
32
- // Start observing the document for added nodes
33
28
  observer.observe(document.body, {
34
29
  childList: true,
35
30
  subtree: true
36
31
  });
37
- });
32
+ }
@@ -0,0 +1,88 @@
1
+ .faw-toast-container {
2
+ position: fixed;
3
+ z-index: 9999;
4
+ pointer-events: none;
5
+ display: flex;
6
+ flex-direction: column;
7
+ gap: 0.5rem; }
8
+ .faw-toast-container.faw-toast-top-right {
9
+ top: 1rem;
10
+ right: 1rem; }
11
+ .faw-toast-container.faw-toast-top-left {
12
+ top: 1rem;
13
+ left: 1rem; }
14
+ .faw-toast-container.faw-toast-bottom-right {
15
+ bottom: 1rem;
16
+ right: 1rem; }
17
+ .faw-toast-container.faw-toast-bottom-left {
18
+ bottom: 1rem;
19
+ left: 1rem; }
20
+ .faw-toast-container.faw-toast-top-center {
21
+ top: 1rem;
22
+ left: 50%;
23
+ transform: translateX(-50%); }
24
+ .faw-toast-container.faw-toast-bottom-center {
25
+ bottom: 1rem;
26
+ left: 50%;
27
+ transform: translateX(-50%); }
28
+
29
+ .faw-toast {
30
+ margin-bottom: 10px;
31
+ padding: 1rem;
32
+ border-radius: 4px;
33
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
34
+ position: relative;
35
+ overflow: hidden;
36
+ animation: faw-toast-slideIn 0.3s ease-in-out, faw-toast-slideOut 0.3s ease-in-out var(--faw-toast-duration) forwards;
37
+ max-width: 24rem;
38
+ width: 100%;
39
+ pointer-events: auto;
40
+ background-color: white; }
41
+ .faw-toast.faw-toast-border-l-10 {
42
+ border-left-width: 10px;
43
+ border-left-style: solid; }
44
+ .faw-toast.faw-toast-border-green-500 {
45
+ border-left-color: #10b981; }
46
+ .faw-toast.faw-toast-border-red-500 {
47
+ border-left-color: #ef4444; }
48
+ .faw-toast.faw-toast-border-sky-600 {
49
+ border-left-color: #0284c7; }
50
+ .faw-toast.faw-toast-border-indigo-500 {
51
+ border-left-color: #6366f1; }
52
+ .faw-toast .faw-toast-content {
53
+ flex: 1; }
54
+ .faw-toast .faw-toast-close {
55
+ cursor: pointer;
56
+ color: #6b7280; }
57
+ .faw-toast .faw-toast-close:hover {
58
+ color: #111827; }
59
+ .faw-toast .faw-toast-progress {
60
+ position: absolute;
61
+ bottom: 0;
62
+ left: 0;
63
+ height: 3px;
64
+ background-color: rgba(0, 0, 0, 0.2);
65
+ width: 100%;
66
+ animation: faw-toast-progress var(--faw-toast-duration) linear; }
67
+
68
+ @keyframes faw-toast-slideIn {
69
+ from {
70
+ transform: translateX(100%);
71
+ opacity: 0; }
72
+ to {
73
+ transform: translateX(0);
74
+ opacity: 1; } }
75
+ @keyframes faw-toast-slideOut {
76
+ from {
77
+ transform: translateX(0);
78
+ opacity: 1; }
79
+ to {
80
+ transform: translateX(100%);
81
+ opacity: 0; } }
82
+ @keyframes faw-toast-progress {
83
+ from {
84
+ width: 100%; }
85
+ to {
86
+ width: 0; } }
87
+
88
+ /*# sourceMappingURL=faw_toast.css.map */
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "mappings": "AAAA,oBAAqB;EACnB,QAAQ,EAAE,KAAK;EACf,OAAO,EAAE,IAAI;EACb,cAAc,EAAE,IAAI;EACpB,OAAO,EAAE,IAAI;EACb,cAAc,EAAE,MAAM;EACtB,GAAG,EAAE,MAAM;EAEX,wCAAsB;IACpB,GAAG,EAAE,IAAI;IACT,KAAK,EAAE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4BASC;EARC,IAAK;IACH,SAAS,EAAE,gBAAgB;IAC3B,OAAO,EAAE,CAAC;EAEZ,EAAG;IACD,SAAS,EAAE,aAAa;IACxB,OAAO,EAAE,CAAC;AAId,6BASC;EARC,IAAK;IACH,SAAS,EAAE,aAAa;IACxB,OAAO,EAAE,CAAC;EAEZ,EAAG;IACD,SAAS,EAAE,gBAAgB;IAC3B,OAAO,EAAE,CAAC;AAId,6BAOC;EANC,IAAK;IACH,KAAK,EAAE,IAAI;EAEb,EAAG;IACD,KAAK,EAAE,CAAC",
4
+ "sources": ["faw_toast.scss"],
5
+ "names": [],
6
+ "file": "faw_toast.css"
7
+ }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FawToast
4
- VERSION = "1.0.0"
4
+ VERSION = "1.2.0"
5
5
  end
@@ -37,44 +37,6 @@ module FawToast
37
37
  say "Please manually import the FawToast stylesheet in your application", :red
38
38
  end
39
39
  end
40
-
41
- def add_javascript_import
42
- if File.exist?("app/javascript/application.js")
43
- append_to_file "app/javascript/application.js" do
44
- "import \"faw_toast\"\n"
45
- end
46
- elsif File.exist?("app/assets/javascripts/application.js")
47
- append_to_file "app/assets/javascripts/application.js" do
48
- "//= require faw_toast\n"
49
- end
50
- else
51
- say "Please manually import the FawToast JavaScript in your application", :red
52
- end
53
- end
54
-
55
- def update_tsconfig
56
- gem_path = `bundle show faw_toast`.chomp
57
-
58
- # Default tsconfig structure if file doesn't exist
59
- tsconfig = if File.exist?("tsconfig.json")
60
- JSON.parse(File.read("tsconfig.json"))
61
- else
62
- {
63
- "compilerOptions" => {
64
- "baseUrl" => ".",
65
- "paths" => {}
66
- }
67
- }
68
- end
69
-
70
- tsconfig["compilerOptions"] ||= {}
71
- tsconfig["compilerOptions"]["paths"] ||= {}
72
- tsconfig["compilerOptions"]["paths"]["faw_toast"] = ["#{gem_path}/app/javascript/faw_toast.js"]
73
-
74
- File.write("tsconfig.json", JSON.pretty_generate(tsconfig))
75
-
76
- say "Updated tsconfig.json with FawToast paths", :green
77
- end
78
40
  end
79
41
  end
80
42
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faw_toast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - alexwebgr
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2025-04-26 00:00:00.000000000 Z
12
12
  dependencies:
@@ -14,16 +14,22 @@ dependencies:
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '7.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '9.0'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '7.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '9.0'
27
33
  description: FawToast provides an easy way to display flash messages as toast notifications
28
34
  in Rails applications
29
35
  email:
@@ -35,8 +41,10 @@ files:
35
41
  - LICENSE.txt
36
42
  - README.md
37
43
  - Rakefile
44
+ - app/assets/javascripts/faw_toast.js
45
+ - app/assets/stylesheets/faw_toast.css
46
+ - app/assets/stylesheets/faw_toast.css.map
38
47
  - app/assets/stylesheets/faw_toast.scss
39
- - app/javascript/faw_toast.js
40
48
  - app/views/faw_toast/_toast.html.erb
41
49
  - lib/faw_toast.rb
42
50
  - lib/faw_toast/configuration.rb