├── .gitignore
├── LICENSE
├── README.md
├── builds
├── cdn.js
└── module.js
├── dist
├── notifications.esm.js
└── notifications.min.js
├── package-lock.json
├── package.json
├── scripts
└── build.js
└── src
├── createNotification.js
├── handleAutoClose.js
├── handleAutoRemove.js
├── handleClassNames.js
├── index.js
├── useFile.js
└── useTemplate.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # misc
9 | .DS_Store
10 | *.pem
11 |
12 | # debug
13 | npm-debug.log*
14 | yarn-debug.log*
15 | yarn-error.log*
16 |
17 | # local env files
18 | .env.local
19 | .env.development.local
20 | .env.test.local
21 | .env.production.local
22 |
23 | # testing
24 | index.html
25 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Mark Mead
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.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Alpine JS Notifications
2 |
3 | Simple notifications in your projects using Alpine JS 🙋♀️
4 |
5 | ## Install
6 |
7 | ### With a CDN
8 |
9 | ```html
10 |
14 |
15 |
16 | ```
17 |
18 | ### With a Package Manager
19 |
20 | ```shell
21 | yarn add -D alpinejs-notify
22 |
23 | npm install -D alpinejs-notify
24 | ```
25 |
26 | ```js
27 | import Alpine from 'alpinejs'
28 | import notifications from 'alpinejs-notify'
29 |
30 | Alpine.plugin(notifications)
31 |
32 | Alpine.start()
33 | ```
34 |
35 | ## Example
36 |
37 | Let's create a simple notification that appears in the top right of the page and
38 | disappears after 5s.
39 |
40 | ```html
41 |
42 |
46 |
47 |
55 | Notify
56 |
57 |
58 |
59 |
60 | {notificationText}
61 |
62 |
63 |
64 | ```
65 |
66 | ### Options
67 |
68 | `notificationText`
69 |
70 | This is the string that will be rendered in the notification.
71 |
72 | _It is not part of the {}_
73 |
74 | `wrapperId`
75 |
76 | This is the wrapping element of the notification.
77 |
78 | `templateId`
79 |
80 | This is the notification component HTML that will be added to the wrapper.
81 |
82 | `templateFile`
83 |
84 | This is an alternative choice to `templateId` which will get the notification
85 | component HTML from the file specified.
86 |
87 | `autoClose`
88 |
89 | This will set the attribute `data-notify-show` to `false` once the duration (in
90 | milliseconds) is up.
91 |
92 | `autoRemove`
93 |
94 | Here you have two options.
95 |
96 | **Duration**
97 |
98 | If you use a duration (in milliseconds) then it will remove the notification
99 | from the DOM once duration is up.
100 |
101 | This works for most situations, however it can get a little tricky calculating
102 | when the removal should happen when working with animations. This is what the
103 | boolean approach solves.
104 |
105 | **Boolean**
106 |
107 | Using a boolean will trigger the removal of the notification once the animation
108 | has ended. It will play the animation in full and then remove once complete.
109 |
110 | `classNames`
111 |
112 | A string of classes to add to the notification.
113 |
114 | ### Default Options
115 |
116 | You don't need to pass the same options for multiple notifications. If all your
117 | notifications are using the options from the example you can do this instead.
118 |
119 | ```html
120 |
128 | ```
129 |
130 | Then all notifications that don't specify their own `notificationOptions` will
131 | use this.
132 |
133 | ## Animating Notifications
134 |
135 | In this example I'll be using Tailwind CSS, but you can easily replicate this
136 | with CSS.
137 |
138 | Let's say you want the notification to slide in from the right and then slide
139 | out, you could do the following.
140 |
141 | ```html
142 |
143 |
147 | {notificationText}
148 |
149 |
150 | ```
151 |
152 | The `animate-slide-` classes have been added to the Tailwind CSS config.
153 |
154 | ```js
155 | module.exports = {
156 | theme: {
157 | extend: {
158 | animation: {
159 | 'slide-in': 'slide-in 0.15s ease-in forwards',
160 | 'slide-out': 'slide-out 0.15s ease-in forwards',
161 | },
162 | keyframes: {
163 | 'slide-in': {
164 | '0%': { transform: 'translateX(100%)' },
165 | '100%': { transform: 'translateX(0)' },
166 | },
167 | 'slide-out': {
168 | '0%': { transform: 'translateX(0)' },
169 | '100%': { transform: 'translateX(100%)' },
170 | },
171 | },
172 | },
173 | },
174 | }
175 | ```
176 |
177 | ## Dismiss Notification
178 |
179 | If you want to have dismissible notifications you can add Alpine JS logic to
180 | your notification template.
181 |
182 | ```html
183 |
184 |
189 | {notificationText}
190 |
191 | Close
192 |
193 |
194 |
195 | ```
196 |
197 | ## Using a File
198 |
199 | If preferred, you can create HTML files for your notification templates.
200 |
201 | ```html
202 |
203 |
204 |
212 | Notify
213 |
214 | ```
215 |
216 | This is now looking for a file called `notification.html` which might look
217 | something like this.
218 |
219 | ```html
220 | {notificationText}
221 | ```
222 |
223 | It works the exact same as `templateId` but it means you don't have ``
224 | tags in your HTML for your notification templates.
225 |
226 | ## Stats
227 |
228 | 
229 | 
230 | 
231 | 
232 |
--------------------------------------------------------------------------------
/builds/cdn.js:
--------------------------------------------------------------------------------
1 | import notify from '../src/index.js'
2 |
3 | document.addEventListener('alpine:init', () => window.Alpine.plugin(notify))
4 |
--------------------------------------------------------------------------------
/builds/module.js:
--------------------------------------------------------------------------------
1 | import notify from '../src/index.js'
2 |
3 | export default notify
4 |
--------------------------------------------------------------------------------
/dist/notifications.esm.js:
--------------------------------------------------------------------------------
1 | function n(t,e){setTimeout(function(){t.setAttribute("data-notify-show",!1)},e)}function a(t,e){if(typeof e=="boolean"){t.addEventListener("animationend",function(){JSON.parse(t.getAttribute("data-notify-show"))===!1&&t.remove()});return}setTimeout(function(){t.remove()},e)}function m(t,e){t.split(" ").forEach(r=>e.classList.add(r))}function i(t,e){async function o(){let l=await(await fetch(e.templateFile)).text(),s=await new DOMParser().parseFromString(l.replace("{notificationText}",t),"text/html").body.firstChild;notificationWrapper.appendChild(s),s.setAttribute("data-notify-show",!0),e.autoClose&&n(s,e.autoClose),e.autoRemove&&a(s,e.autoRemove),e.classNames&&m(e.classNames,s)}o()}function p(t,e,o){let r=document.getElementById(t),l=document.getElementById(e),s=new DOMParser().parseFromString(l.innerHTML.replace("{notificationText}",o),"text/html").body.firstChild;return r.appendChild(s),s.setAttribute("data-notify-show",!0),s}function f(t,e){let o=p(e.wrapperId,e.templateId,t);e.autoClose&&n(o,e.autoClose),e.autoRemove&&a(o,e.autoRemove),e.classNames&&m(e.classNames,o)}function u(t){t.magic("notify",()=>(e,o)=>{let r=o?.wrapperId?o:window.notificationOptions;if(r.templateFile)return i(e,r);if(r.templateId)return f(e,r)})}var L=u;export{L as default};
2 |
--------------------------------------------------------------------------------
/dist/notifications.min.js:
--------------------------------------------------------------------------------
1 | (()=>{function n(t,e){setTimeout(function(){t.setAttribute("data-notify-show",!1)},e)}function a(t,e){if(typeof e=="boolean"){t.addEventListener("animationend",function(){JSON.parse(t.getAttribute("data-notify-show"))===!1&&t.remove()});return}setTimeout(function(){t.remove()},e)}function m(t,e){t.split(" ").forEach(r=>e.classList.add(r))}function l(t,e){async function o(){let i=await(await fetch(e.templateFile)).text(),s=await new DOMParser().parseFromString(i.replace("{notificationText}",t),"text/html").body.firstChild;notificationWrapper.appendChild(s),s.setAttribute("data-notify-show",!0),e.autoClose&&n(s,e.autoClose),e.autoRemove&&a(s,e.autoRemove),e.classNames&&m(e.classNames,s)}o()}function p(t,e,o){let r=document.getElementById(t),i=document.getElementById(e),s=new DOMParser().parseFromString(i.innerHTML.replace("{notificationText}",o),"text/html").body.firstChild;return r.appendChild(s),s.setAttribute("data-notify-show",!0),s}function u(t,e){let o=p(e.wrapperId,e.templateId,t);e.autoClose&&n(o,e.autoClose),e.autoRemove&&a(o,e.autoRemove),e.classNames&&m(e.classNames,o)}function f(t){t.magic("notify",()=>(e,o)=>{let r=o?.wrapperId?o:window.notificationOptions;if(r.templateFile)return l(e,r);if(r.templateId)return u(e,r)})}document.addEventListener("alpine:init",()=>window.Alpine.plugin(f));})();
2 |
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "alpinejs-notify",
3 | "version": "1.0.4",
4 | "lockfileVersion": 2,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "alpinejs-notify",
9 | "version": "1.0.4",
10 | "devDependencies": {
11 | "esbuild": "^0.25.0"
12 | }
13 | },
14 | "node_modules/@esbuild/aix-ppc64": {
15 | "version": "0.25.0",
16 | "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.0.tgz",
17 | "integrity": "sha512-O7vun9Sf8DFjH2UtqK8Ku3LkquL9SZL8OLY1T5NZkA34+wG3OQF7cl4Ql8vdNzM6fzBbYfLaiRLIOZ+2FOCgBQ==",
18 | "cpu": [
19 | "ppc64"
20 | ],
21 | "dev": true,
22 | "license": "MIT",
23 | "optional": true,
24 | "os": [
25 | "aix"
26 | ],
27 | "engines": {
28 | "node": ">=18"
29 | }
30 | },
31 | "node_modules/@esbuild/android-arm": {
32 | "version": "0.25.0",
33 | "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.0.tgz",
34 | "integrity": "sha512-PTyWCYYiU0+1eJKmw21lWtC+d08JDZPQ5g+kFyxP0V+es6VPPSUhM6zk8iImp2jbV6GwjX4pap0JFbUQN65X1g==",
35 | "cpu": [
36 | "arm"
37 | ],
38 | "dev": true,
39 | "license": "MIT",
40 | "optional": true,
41 | "os": [
42 | "android"
43 | ],
44 | "engines": {
45 | "node": ">=18"
46 | }
47 | },
48 | "node_modules/@esbuild/android-arm64": {
49 | "version": "0.25.0",
50 | "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.0.tgz",
51 | "integrity": "sha512-grvv8WncGjDSyUBjN9yHXNt+cq0snxXbDxy5pJtzMKGmmpPxeAmAhWxXI+01lU5rwZomDgD3kJwulEnhTRUd6g==",
52 | "cpu": [
53 | "arm64"
54 | ],
55 | "dev": true,
56 | "license": "MIT",
57 | "optional": true,
58 | "os": [
59 | "android"
60 | ],
61 | "engines": {
62 | "node": ">=18"
63 | }
64 | },
65 | "node_modules/@esbuild/android-x64": {
66 | "version": "0.25.0",
67 | "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.0.tgz",
68 | "integrity": "sha512-m/ix7SfKG5buCnxasr52+LI78SQ+wgdENi9CqyCXwjVR2X4Jkz+BpC3le3AoBPYTC9NHklwngVXvbJ9/Akhrfg==",
69 | "cpu": [
70 | "x64"
71 | ],
72 | "dev": true,
73 | "license": "MIT",
74 | "optional": true,
75 | "os": [
76 | "android"
77 | ],
78 | "engines": {
79 | "node": ">=18"
80 | }
81 | },
82 | "node_modules/@esbuild/darwin-arm64": {
83 | "version": "0.25.0",
84 | "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.0.tgz",
85 | "integrity": "sha512-mVwdUb5SRkPayVadIOI78K7aAnPamoeFR2bT5nszFUZ9P8UpK4ratOdYbZZXYSqPKMHfS1wdHCJk1P1EZpRdvw==",
86 | "cpu": [
87 | "arm64"
88 | ],
89 | "dev": true,
90 | "license": "MIT",
91 | "optional": true,
92 | "os": [
93 | "darwin"
94 | ],
95 | "engines": {
96 | "node": ">=18"
97 | }
98 | },
99 | "node_modules/@esbuild/darwin-x64": {
100 | "version": "0.25.0",
101 | "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.0.tgz",
102 | "integrity": "sha512-DgDaYsPWFTS4S3nWpFcMn/33ZZwAAeAFKNHNa1QN0rI4pUjgqf0f7ONmXf6d22tqTY+H9FNdgeaAa+YIFUn2Rg==",
103 | "cpu": [
104 | "x64"
105 | ],
106 | "dev": true,
107 | "license": "MIT",
108 | "optional": true,
109 | "os": [
110 | "darwin"
111 | ],
112 | "engines": {
113 | "node": ">=18"
114 | }
115 | },
116 | "node_modules/@esbuild/freebsd-arm64": {
117 | "version": "0.25.0",
118 | "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.0.tgz",
119 | "integrity": "sha512-VN4ocxy6dxefN1MepBx/iD1dH5K8qNtNe227I0mnTRjry8tj5MRk4zprLEdG8WPyAPb93/e4pSgi1SoHdgOa4w==",
120 | "cpu": [
121 | "arm64"
122 | ],
123 | "dev": true,
124 | "license": "MIT",
125 | "optional": true,
126 | "os": [
127 | "freebsd"
128 | ],
129 | "engines": {
130 | "node": ">=18"
131 | }
132 | },
133 | "node_modules/@esbuild/freebsd-x64": {
134 | "version": "0.25.0",
135 | "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.0.tgz",
136 | "integrity": "sha512-mrSgt7lCh07FY+hDD1TxiTyIHyttn6vnjesnPoVDNmDfOmggTLXRv8Id5fNZey1gl/V2dyVK1VXXqVsQIiAk+A==",
137 | "cpu": [
138 | "x64"
139 | ],
140 | "dev": true,
141 | "license": "MIT",
142 | "optional": true,
143 | "os": [
144 | "freebsd"
145 | ],
146 | "engines": {
147 | "node": ">=18"
148 | }
149 | },
150 | "node_modules/@esbuild/linux-arm": {
151 | "version": "0.25.0",
152 | "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.0.tgz",
153 | "integrity": "sha512-vkB3IYj2IDo3g9xX7HqhPYxVkNQe8qTK55fraQyTzTX/fxaDtXiEnavv9geOsonh2Fd2RMB+i5cbhu2zMNWJwg==",
154 | "cpu": [
155 | "arm"
156 | ],
157 | "dev": true,
158 | "license": "MIT",
159 | "optional": true,
160 | "os": [
161 | "linux"
162 | ],
163 | "engines": {
164 | "node": ">=18"
165 | }
166 | },
167 | "node_modules/@esbuild/linux-arm64": {
168 | "version": "0.25.0",
169 | "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.0.tgz",
170 | "integrity": "sha512-9QAQjTWNDM/Vk2bgBl17yWuZxZNQIF0OUUuPZRKoDtqF2k4EtYbpyiG5/Dk7nqeK6kIJWPYldkOcBqjXjrUlmg==",
171 | "cpu": [
172 | "arm64"
173 | ],
174 | "dev": true,
175 | "license": "MIT",
176 | "optional": true,
177 | "os": [
178 | "linux"
179 | ],
180 | "engines": {
181 | "node": ">=18"
182 | }
183 | },
184 | "node_modules/@esbuild/linux-ia32": {
185 | "version": "0.25.0",
186 | "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.0.tgz",
187 | "integrity": "sha512-43ET5bHbphBegyeqLb7I1eYn2P/JYGNmzzdidq/w0T8E2SsYL1U6un2NFROFRg1JZLTzdCoRomg8Rvf9M6W6Gg==",
188 | "cpu": [
189 | "ia32"
190 | ],
191 | "dev": true,
192 | "license": "MIT",
193 | "optional": true,
194 | "os": [
195 | "linux"
196 | ],
197 | "engines": {
198 | "node": ">=18"
199 | }
200 | },
201 | "node_modules/@esbuild/linux-loong64": {
202 | "version": "0.25.0",
203 | "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.0.tgz",
204 | "integrity": "sha512-fC95c/xyNFueMhClxJmeRIj2yrSMdDfmqJnyOY4ZqsALkDrrKJfIg5NTMSzVBr5YW1jf+l7/cndBfP3MSDpoHw==",
205 | "cpu": [
206 | "loong64"
207 | ],
208 | "dev": true,
209 | "license": "MIT",
210 | "optional": true,
211 | "os": [
212 | "linux"
213 | ],
214 | "engines": {
215 | "node": ">=18"
216 | }
217 | },
218 | "node_modules/@esbuild/linux-mips64el": {
219 | "version": "0.25.0",
220 | "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.0.tgz",
221 | "integrity": "sha512-nkAMFju7KDW73T1DdH7glcyIptm95a7Le8irTQNO/qtkoyypZAnjchQgooFUDQhNAy4iu08N79W4T4pMBwhPwQ==",
222 | "cpu": [
223 | "mips64el"
224 | ],
225 | "dev": true,
226 | "license": "MIT",
227 | "optional": true,
228 | "os": [
229 | "linux"
230 | ],
231 | "engines": {
232 | "node": ">=18"
233 | }
234 | },
235 | "node_modules/@esbuild/linux-ppc64": {
236 | "version": "0.25.0",
237 | "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.0.tgz",
238 | "integrity": "sha512-NhyOejdhRGS8Iwv+KKR2zTq2PpysF9XqY+Zk77vQHqNbo/PwZCzB5/h7VGuREZm1fixhs4Q/qWRSi5zmAiO4Fw==",
239 | "cpu": [
240 | "ppc64"
241 | ],
242 | "dev": true,
243 | "license": "MIT",
244 | "optional": true,
245 | "os": [
246 | "linux"
247 | ],
248 | "engines": {
249 | "node": ">=18"
250 | }
251 | },
252 | "node_modules/@esbuild/linux-riscv64": {
253 | "version": "0.25.0",
254 | "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.0.tgz",
255 | "integrity": "sha512-5S/rbP5OY+GHLC5qXp1y/Mx//e92L1YDqkiBbO9TQOvuFXM+iDqUNG5XopAnXoRH3FjIUDkeGcY1cgNvnXp/kA==",
256 | "cpu": [
257 | "riscv64"
258 | ],
259 | "dev": true,
260 | "license": "MIT",
261 | "optional": true,
262 | "os": [
263 | "linux"
264 | ],
265 | "engines": {
266 | "node": ">=18"
267 | }
268 | },
269 | "node_modules/@esbuild/linux-s390x": {
270 | "version": "0.25.0",
271 | "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.0.tgz",
272 | "integrity": "sha512-XM2BFsEBz0Fw37V0zU4CXfcfuACMrppsMFKdYY2WuTS3yi8O1nFOhil/xhKTmE1nPmVyvQJjJivgDT+xh8pXJA==",
273 | "cpu": [
274 | "s390x"
275 | ],
276 | "dev": true,
277 | "license": "MIT",
278 | "optional": true,
279 | "os": [
280 | "linux"
281 | ],
282 | "engines": {
283 | "node": ">=18"
284 | }
285 | },
286 | "node_modules/@esbuild/linux-x64": {
287 | "version": "0.25.0",
288 | "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.0.tgz",
289 | "integrity": "sha512-9yl91rHw/cpwMCNytUDxwj2XjFpxML0y9HAOH9pNVQDpQrBxHy01Dx+vaMu0N1CKa/RzBD2hB4u//nfc+Sd3Cw==",
290 | "cpu": [
291 | "x64"
292 | ],
293 | "dev": true,
294 | "license": "MIT",
295 | "optional": true,
296 | "os": [
297 | "linux"
298 | ],
299 | "engines": {
300 | "node": ">=18"
301 | }
302 | },
303 | "node_modules/@esbuild/netbsd-arm64": {
304 | "version": "0.25.0",
305 | "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.0.tgz",
306 | "integrity": "sha512-RuG4PSMPFfrkH6UwCAqBzauBWTygTvb1nxWasEJooGSJ/NwRw7b2HOwyRTQIU97Hq37l3npXoZGYMy3b3xYvPw==",
307 | "cpu": [
308 | "arm64"
309 | ],
310 | "dev": true,
311 | "license": "MIT",
312 | "optional": true,
313 | "os": [
314 | "netbsd"
315 | ],
316 | "engines": {
317 | "node": ">=18"
318 | }
319 | },
320 | "node_modules/@esbuild/netbsd-x64": {
321 | "version": "0.25.0",
322 | "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.0.tgz",
323 | "integrity": "sha512-jl+qisSB5jk01N5f7sPCsBENCOlPiS/xptD5yxOx2oqQfyourJwIKLRA2yqWdifj3owQZCL2sn6o08dBzZGQzA==",
324 | "cpu": [
325 | "x64"
326 | ],
327 | "dev": true,
328 | "license": "MIT",
329 | "optional": true,
330 | "os": [
331 | "netbsd"
332 | ],
333 | "engines": {
334 | "node": ">=18"
335 | }
336 | },
337 | "node_modules/@esbuild/openbsd-arm64": {
338 | "version": "0.25.0",
339 | "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.0.tgz",
340 | "integrity": "sha512-21sUNbq2r84YE+SJDfaQRvdgznTD8Xc0oc3p3iW/a1EVWeNj/SdUCbm5U0itZPQYRuRTW20fPMWMpcrciH2EJw==",
341 | "cpu": [
342 | "arm64"
343 | ],
344 | "dev": true,
345 | "license": "MIT",
346 | "optional": true,
347 | "os": [
348 | "openbsd"
349 | ],
350 | "engines": {
351 | "node": ">=18"
352 | }
353 | },
354 | "node_modules/@esbuild/openbsd-x64": {
355 | "version": "0.25.0",
356 | "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.0.tgz",
357 | "integrity": "sha512-2gwwriSMPcCFRlPlKx3zLQhfN/2WjJ2NSlg5TKLQOJdV0mSxIcYNTMhk3H3ulL/cak+Xj0lY1Ym9ysDV1igceg==",
358 | "cpu": [
359 | "x64"
360 | ],
361 | "dev": true,
362 | "license": "MIT",
363 | "optional": true,
364 | "os": [
365 | "openbsd"
366 | ],
367 | "engines": {
368 | "node": ">=18"
369 | }
370 | },
371 | "node_modules/@esbuild/sunos-x64": {
372 | "version": "0.25.0",
373 | "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.0.tgz",
374 | "integrity": "sha512-bxI7ThgLzPrPz484/S9jLlvUAHYMzy6I0XiU1ZMeAEOBcS0VePBFxh1JjTQt3Xiat5b6Oh4x7UC7IwKQKIJRIg==",
375 | "cpu": [
376 | "x64"
377 | ],
378 | "dev": true,
379 | "license": "MIT",
380 | "optional": true,
381 | "os": [
382 | "sunos"
383 | ],
384 | "engines": {
385 | "node": ">=18"
386 | }
387 | },
388 | "node_modules/@esbuild/win32-arm64": {
389 | "version": "0.25.0",
390 | "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.0.tgz",
391 | "integrity": "sha512-ZUAc2YK6JW89xTbXvftxdnYy3m4iHIkDtK3CLce8wg8M2L+YZhIvO1DKpxrd0Yr59AeNNkTiic9YLf6FTtXWMw==",
392 | "cpu": [
393 | "arm64"
394 | ],
395 | "dev": true,
396 | "license": "MIT",
397 | "optional": true,
398 | "os": [
399 | "win32"
400 | ],
401 | "engines": {
402 | "node": ">=18"
403 | }
404 | },
405 | "node_modules/@esbuild/win32-ia32": {
406 | "version": "0.25.0",
407 | "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.0.tgz",
408 | "integrity": "sha512-eSNxISBu8XweVEWG31/JzjkIGbGIJN/TrRoiSVZwZ6pkC6VX4Im/WV2cz559/TXLcYbcrDN8JtKgd9DJVIo8GA==",
409 | "cpu": [
410 | "ia32"
411 | ],
412 | "dev": true,
413 | "license": "MIT",
414 | "optional": true,
415 | "os": [
416 | "win32"
417 | ],
418 | "engines": {
419 | "node": ">=18"
420 | }
421 | },
422 | "node_modules/@esbuild/win32-x64": {
423 | "version": "0.25.0",
424 | "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.0.tgz",
425 | "integrity": "sha512-ZENoHJBxA20C2zFzh6AI4fT6RraMzjYw4xKWemRTRmRVtN9c5DcH9r/f2ihEkMjOW5eGgrwCslG/+Y/3bL+DHQ==",
426 | "cpu": [
427 | "x64"
428 | ],
429 | "dev": true,
430 | "license": "MIT",
431 | "optional": true,
432 | "os": [
433 | "win32"
434 | ],
435 | "engines": {
436 | "node": ">=18"
437 | }
438 | },
439 | "node_modules/esbuild": {
440 | "version": "0.25.0",
441 | "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.0.tgz",
442 | "integrity": "sha512-BXq5mqc8ltbaN34cDqWuYKyNhX8D/Z0J1xdtdQ8UcIIIyJyz+ZMKUt58tF3SrZ85jcfN/PZYhjR5uDQAYNVbuw==",
443 | "dev": true,
444 | "hasInstallScript": true,
445 | "license": "MIT",
446 | "bin": {
447 | "esbuild": "bin/esbuild"
448 | },
449 | "engines": {
450 | "node": ">=18"
451 | },
452 | "optionalDependencies": {
453 | "@esbuild/aix-ppc64": "0.25.0",
454 | "@esbuild/android-arm": "0.25.0",
455 | "@esbuild/android-arm64": "0.25.0",
456 | "@esbuild/android-x64": "0.25.0",
457 | "@esbuild/darwin-arm64": "0.25.0",
458 | "@esbuild/darwin-x64": "0.25.0",
459 | "@esbuild/freebsd-arm64": "0.25.0",
460 | "@esbuild/freebsd-x64": "0.25.0",
461 | "@esbuild/linux-arm": "0.25.0",
462 | "@esbuild/linux-arm64": "0.25.0",
463 | "@esbuild/linux-ia32": "0.25.0",
464 | "@esbuild/linux-loong64": "0.25.0",
465 | "@esbuild/linux-mips64el": "0.25.0",
466 | "@esbuild/linux-ppc64": "0.25.0",
467 | "@esbuild/linux-riscv64": "0.25.0",
468 | "@esbuild/linux-s390x": "0.25.0",
469 | "@esbuild/linux-x64": "0.25.0",
470 | "@esbuild/netbsd-arm64": "0.25.0",
471 | "@esbuild/netbsd-x64": "0.25.0",
472 | "@esbuild/openbsd-arm64": "0.25.0",
473 | "@esbuild/openbsd-x64": "0.25.0",
474 | "@esbuild/sunos-x64": "0.25.0",
475 | "@esbuild/win32-arm64": "0.25.0",
476 | "@esbuild/win32-ia32": "0.25.0",
477 | "@esbuild/win32-x64": "0.25.0"
478 | }
479 | }
480 | },
481 | "dependencies": {
482 | "@esbuild/aix-ppc64": {
483 | "version": "0.25.0",
484 | "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.0.tgz",
485 | "integrity": "sha512-O7vun9Sf8DFjH2UtqK8Ku3LkquL9SZL8OLY1T5NZkA34+wG3OQF7cl4Ql8vdNzM6fzBbYfLaiRLIOZ+2FOCgBQ==",
486 | "dev": true,
487 | "optional": true
488 | },
489 | "@esbuild/android-arm": {
490 | "version": "0.25.0",
491 | "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.0.tgz",
492 | "integrity": "sha512-PTyWCYYiU0+1eJKmw21lWtC+d08JDZPQ5g+kFyxP0V+es6VPPSUhM6zk8iImp2jbV6GwjX4pap0JFbUQN65X1g==",
493 | "dev": true,
494 | "optional": true
495 | },
496 | "@esbuild/android-arm64": {
497 | "version": "0.25.0",
498 | "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.0.tgz",
499 | "integrity": "sha512-grvv8WncGjDSyUBjN9yHXNt+cq0snxXbDxy5pJtzMKGmmpPxeAmAhWxXI+01lU5rwZomDgD3kJwulEnhTRUd6g==",
500 | "dev": true,
501 | "optional": true
502 | },
503 | "@esbuild/android-x64": {
504 | "version": "0.25.0",
505 | "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.0.tgz",
506 | "integrity": "sha512-m/ix7SfKG5buCnxasr52+LI78SQ+wgdENi9CqyCXwjVR2X4Jkz+BpC3le3AoBPYTC9NHklwngVXvbJ9/Akhrfg==",
507 | "dev": true,
508 | "optional": true
509 | },
510 | "@esbuild/darwin-arm64": {
511 | "version": "0.25.0",
512 | "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.0.tgz",
513 | "integrity": "sha512-mVwdUb5SRkPayVadIOI78K7aAnPamoeFR2bT5nszFUZ9P8UpK4ratOdYbZZXYSqPKMHfS1wdHCJk1P1EZpRdvw==",
514 | "dev": true,
515 | "optional": true
516 | },
517 | "@esbuild/darwin-x64": {
518 | "version": "0.25.0",
519 | "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.0.tgz",
520 | "integrity": "sha512-DgDaYsPWFTS4S3nWpFcMn/33ZZwAAeAFKNHNa1QN0rI4pUjgqf0f7ONmXf6d22tqTY+H9FNdgeaAa+YIFUn2Rg==",
521 | "dev": true,
522 | "optional": true
523 | },
524 | "@esbuild/freebsd-arm64": {
525 | "version": "0.25.0",
526 | "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.0.tgz",
527 | "integrity": "sha512-VN4ocxy6dxefN1MepBx/iD1dH5K8qNtNe227I0mnTRjry8tj5MRk4zprLEdG8WPyAPb93/e4pSgi1SoHdgOa4w==",
528 | "dev": true,
529 | "optional": true
530 | },
531 | "@esbuild/freebsd-x64": {
532 | "version": "0.25.0",
533 | "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.0.tgz",
534 | "integrity": "sha512-mrSgt7lCh07FY+hDD1TxiTyIHyttn6vnjesnPoVDNmDfOmggTLXRv8Id5fNZey1gl/V2dyVK1VXXqVsQIiAk+A==",
535 | "dev": true,
536 | "optional": true
537 | },
538 | "@esbuild/linux-arm": {
539 | "version": "0.25.0",
540 | "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.0.tgz",
541 | "integrity": "sha512-vkB3IYj2IDo3g9xX7HqhPYxVkNQe8qTK55fraQyTzTX/fxaDtXiEnavv9geOsonh2Fd2RMB+i5cbhu2zMNWJwg==",
542 | "dev": true,
543 | "optional": true
544 | },
545 | "@esbuild/linux-arm64": {
546 | "version": "0.25.0",
547 | "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.0.tgz",
548 | "integrity": "sha512-9QAQjTWNDM/Vk2bgBl17yWuZxZNQIF0OUUuPZRKoDtqF2k4EtYbpyiG5/Dk7nqeK6kIJWPYldkOcBqjXjrUlmg==",
549 | "dev": true,
550 | "optional": true
551 | },
552 | "@esbuild/linux-ia32": {
553 | "version": "0.25.0",
554 | "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.0.tgz",
555 | "integrity": "sha512-43ET5bHbphBegyeqLb7I1eYn2P/JYGNmzzdidq/w0T8E2SsYL1U6un2NFROFRg1JZLTzdCoRomg8Rvf9M6W6Gg==",
556 | "dev": true,
557 | "optional": true
558 | },
559 | "@esbuild/linux-loong64": {
560 | "version": "0.25.0",
561 | "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.0.tgz",
562 | "integrity": "sha512-fC95c/xyNFueMhClxJmeRIj2yrSMdDfmqJnyOY4ZqsALkDrrKJfIg5NTMSzVBr5YW1jf+l7/cndBfP3MSDpoHw==",
563 | "dev": true,
564 | "optional": true
565 | },
566 | "@esbuild/linux-mips64el": {
567 | "version": "0.25.0",
568 | "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.0.tgz",
569 | "integrity": "sha512-nkAMFju7KDW73T1DdH7glcyIptm95a7Le8irTQNO/qtkoyypZAnjchQgooFUDQhNAy4iu08N79W4T4pMBwhPwQ==",
570 | "dev": true,
571 | "optional": true
572 | },
573 | "@esbuild/linux-ppc64": {
574 | "version": "0.25.0",
575 | "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.0.tgz",
576 | "integrity": "sha512-NhyOejdhRGS8Iwv+KKR2zTq2PpysF9XqY+Zk77vQHqNbo/PwZCzB5/h7VGuREZm1fixhs4Q/qWRSi5zmAiO4Fw==",
577 | "dev": true,
578 | "optional": true
579 | },
580 | "@esbuild/linux-riscv64": {
581 | "version": "0.25.0",
582 | "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.0.tgz",
583 | "integrity": "sha512-5S/rbP5OY+GHLC5qXp1y/Mx//e92L1YDqkiBbO9TQOvuFXM+iDqUNG5XopAnXoRH3FjIUDkeGcY1cgNvnXp/kA==",
584 | "dev": true,
585 | "optional": true
586 | },
587 | "@esbuild/linux-s390x": {
588 | "version": "0.25.0",
589 | "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.0.tgz",
590 | "integrity": "sha512-XM2BFsEBz0Fw37V0zU4CXfcfuACMrppsMFKdYY2WuTS3yi8O1nFOhil/xhKTmE1nPmVyvQJjJivgDT+xh8pXJA==",
591 | "dev": true,
592 | "optional": true
593 | },
594 | "@esbuild/linux-x64": {
595 | "version": "0.25.0",
596 | "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.0.tgz",
597 | "integrity": "sha512-9yl91rHw/cpwMCNytUDxwj2XjFpxML0y9HAOH9pNVQDpQrBxHy01Dx+vaMu0N1CKa/RzBD2hB4u//nfc+Sd3Cw==",
598 | "dev": true,
599 | "optional": true
600 | },
601 | "@esbuild/netbsd-arm64": {
602 | "version": "0.25.0",
603 | "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.0.tgz",
604 | "integrity": "sha512-RuG4PSMPFfrkH6UwCAqBzauBWTygTvb1nxWasEJooGSJ/NwRw7b2HOwyRTQIU97Hq37l3npXoZGYMy3b3xYvPw==",
605 | "dev": true,
606 | "optional": true
607 | },
608 | "@esbuild/netbsd-x64": {
609 | "version": "0.25.0",
610 | "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.0.tgz",
611 | "integrity": "sha512-jl+qisSB5jk01N5f7sPCsBENCOlPiS/xptD5yxOx2oqQfyourJwIKLRA2yqWdifj3owQZCL2sn6o08dBzZGQzA==",
612 | "dev": true,
613 | "optional": true
614 | },
615 | "@esbuild/openbsd-arm64": {
616 | "version": "0.25.0",
617 | "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.0.tgz",
618 | "integrity": "sha512-21sUNbq2r84YE+SJDfaQRvdgznTD8Xc0oc3p3iW/a1EVWeNj/SdUCbm5U0itZPQYRuRTW20fPMWMpcrciH2EJw==",
619 | "dev": true,
620 | "optional": true
621 | },
622 | "@esbuild/openbsd-x64": {
623 | "version": "0.25.0",
624 | "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.0.tgz",
625 | "integrity": "sha512-2gwwriSMPcCFRlPlKx3zLQhfN/2WjJ2NSlg5TKLQOJdV0mSxIcYNTMhk3H3ulL/cak+Xj0lY1Ym9ysDV1igceg==",
626 | "dev": true,
627 | "optional": true
628 | },
629 | "@esbuild/sunos-x64": {
630 | "version": "0.25.0",
631 | "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.0.tgz",
632 | "integrity": "sha512-bxI7ThgLzPrPz484/S9jLlvUAHYMzy6I0XiU1ZMeAEOBcS0VePBFxh1JjTQt3Xiat5b6Oh4x7UC7IwKQKIJRIg==",
633 | "dev": true,
634 | "optional": true
635 | },
636 | "@esbuild/win32-arm64": {
637 | "version": "0.25.0",
638 | "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.0.tgz",
639 | "integrity": "sha512-ZUAc2YK6JW89xTbXvftxdnYy3m4iHIkDtK3CLce8wg8M2L+YZhIvO1DKpxrd0Yr59AeNNkTiic9YLf6FTtXWMw==",
640 | "dev": true,
641 | "optional": true
642 | },
643 | "@esbuild/win32-ia32": {
644 | "version": "0.25.0",
645 | "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.0.tgz",
646 | "integrity": "sha512-eSNxISBu8XweVEWG31/JzjkIGbGIJN/TrRoiSVZwZ6pkC6VX4Im/WV2cz559/TXLcYbcrDN8JtKgd9DJVIo8GA==",
647 | "dev": true,
648 | "optional": true
649 | },
650 | "@esbuild/win32-x64": {
651 | "version": "0.25.0",
652 | "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.0.tgz",
653 | "integrity": "sha512-ZENoHJBxA20C2zFzh6AI4fT6RraMzjYw4xKWemRTRmRVtN9c5DcH9r/f2ihEkMjOW5eGgrwCslG/+Y/3bL+DHQ==",
654 | "dev": true,
655 | "optional": true
656 | },
657 | "esbuild": {
658 | "version": "0.25.0",
659 | "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.0.tgz",
660 | "integrity": "sha512-BXq5mqc8ltbaN34cDqWuYKyNhX8D/Z0J1xdtdQ8UcIIIyJyz+ZMKUt58tF3SrZ85jcfN/PZYhjR5uDQAYNVbuw==",
661 | "dev": true,
662 | "requires": {
663 | "@esbuild/aix-ppc64": "0.25.0",
664 | "@esbuild/android-arm": "0.25.0",
665 | "@esbuild/android-arm64": "0.25.0",
666 | "@esbuild/android-x64": "0.25.0",
667 | "@esbuild/darwin-arm64": "0.25.0",
668 | "@esbuild/darwin-x64": "0.25.0",
669 | "@esbuild/freebsd-arm64": "0.25.0",
670 | "@esbuild/freebsd-x64": "0.25.0",
671 | "@esbuild/linux-arm": "0.25.0",
672 | "@esbuild/linux-arm64": "0.25.0",
673 | "@esbuild/linux-ia32": "0.25.0",
674 | "@esbuild/linux-loong64": "0.25.0",
675 | "@esbuild/linux-mips64el": "0.25.0",
676 | "@esbuild/linux-ppc64": "0.25.0",
677 | "@esbuild/linux-riscv64": "0.25.0",
678 | "@esbuild/linux-s390x": "0.25.0",
679 | "@esbuild/linux-x64": "0.25.0",
680 | "@esbuild/netbsd-arm64": "0.25.0",
681 | "@esbuild/netbsd-x64": "0.25.0",
682 | "@esbuild/openbsd-arm64": "0.25.0",
683 | "@esbuild/openbsd-x64": "0.25.0",
684 | "@esbuild/sunos-x64": "0.25.0",
685 | "@esbuild/win32-arm64": "0.25.0",
686 | "@esbuild/win32-ia32": "0.25.0",
687 | "@esbuild/win32-x64": "0.25.0"
688 | }
689 | }
690 | }
691 | }
692 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "alpinejs-notify",
3 | "version": "1.0.4",
4 | "description": "Simple notifications in your projects using Alpine JS 🙋♀️",
5 | "keywords": [
6 | "Alpine",
7 | "Alpine JS",
8 | "Alpine JS Plugin",
9 | "Alpine JS Plugins",
10 | "Alpine JS Notifications",
11 | "JavaScript Notifications"
12 | ],
13 | "module": "dist/notifications.esm.js",
14 | "unpkg": "dist/notifications.min.js",
15 | "scripts": {
16 | "build": "node scripts/build.js"
17 | },
18 | "devDependencies": {
19 | "esbuild": "^0.25.0"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/scripts/build.js:
--------------------------------------------------------------------------------
1 | buildPlugin({
2 | entryPoints: ['builds/cdn.js'],
3 | outfile: 'dist/notifications.min.js',
4 | })
5 |
6 | buildPlugin({
7 | entryPoints: ['builds/module.js'],
8 | outfile: 'dist/notifications.esm.js',
9 | platform: 'neutral',
10 | mainFields: ['main', 'module'],
11 | })
12 |
13 | function buildPlugin(buildOptions) {
14 | return require('esbuild').buildSync({
15 | ...buildOptions,
16 | minify: true,
17 | bundle: true,
18 | })
19 | }
20 |
--------------------------------------------------------------------------------
/src/createNotification.js:
--------------------------------------------------------------------------------
1 | export function createNotification(wrapperId, templateId, notificationText) {
2 | const notificationWrapper = document.getElementById(wrapperId)
3 | const notificationTemplate = document.getElementById(templateId)
4 | const notificationComponent = new DOMParser().parseFromString(
5 | notificationTemplate.innerHTML.replace(
6 | '{notificationText}',
7 | notificationText
8 | ),
9 | 'text/html'
10 | ).body.firstChild
11 |
12 | notificationWrapper.appendChild(notificationComponent)
13 |
14 | notificationComponent.setAttribute('data-notify-show', true)
15 |
16 | return notificationComponent
17 | }
18 |
--------------------------------------------------------------------------------
/src/handleAutoClose.js:
--------------------------------------------------------------------------------
1 | export function handleAutoClose(notificationComponent, autoClose) {
2 | setTimeout(function () {
3 | notificationComponent.setAttribute('data-notify-show', false)
4 | }, autoClose)
5 | }
6 |
--------------------------------------------------------------------------------
/src/handleAutoRemove.js:
--------------------------------------------------------------------------------
1 | export function handleAutoRemove(notificationComponent, autoRemove) {
2 | if (typeof autoRemove === 'boolean') {
3 | notificationComponent.addEventListener('animationend', function () {
4 | if (
5 | JSON.parse(notificationComponent.getAttribute('data-notify-show')) ===
6 | false
7 | ) {
8 | notificationComponent.remove()
9 | }
10 | })
11 |
12 | return
13 | }
14 |
15 | setTimeout(function () {
16 | notificationComponent.remove()
17 | }, autoRemove)
18 | }
19 |
--------------------------------------------------------------------------------
/src/handleClassNames.js:
--------------------------------------------------------------------------------
1 | export function handleClassNames(classNames, notificationComponent) {
2 | const classNamesArray = classNames.split(' ')
3 |
4 | classNamesArray.forEach((className) =>
5 | notificationComponent.classList.add(className)
6 | )
7 | }
8 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import { useFile } from './useFile'
2 | import { useTemplate } from './useTemplate'
3 |
4 | export default function (Alpine) {
5 | Alpine.magic('notify', () => (notificationText, notificationOptions) => {
6 | const notificationData = notificationOptions?.wrapperId
7 | ? notificationOptions
8 | : window.notificationOptions
9 |
10 | if (notificationData.templateFile) {
11 | return useFile(notificationText, notificationData)
12 | }
13 |
14 | if (notificationData.templateId) {
15 | return useTemplate(notificationText, notificationData)
16 | }
17 | })
18 | }
19 |
--------------------------------------------------------------------------------
/src/useFile.js:
--------------------------------------------------------------------------------
1 | import { handleAutoClose } from './handleAutoClose'
2 | import { handleAutoRemove } from './handleAutoRemove'
3 | import { handleClassNames } from './handleClassNames'
4 |
5 | export function useFile(notificationText, notificationData) {
6 | async function fetchTemplate() {
7 | const fetchResponse = await fetch(notificationData.templateFile)
8 | const notificationTemplate = await fetchResponse.text()
9 | const notificationComponent = await new DOMParser().parseFromString(
10 | notificationTemplate.replace('{notificationText}', notificationText),
11 | 'text/html'
12 | ).body.firstChild
13 |
14 | notificationWrapper.appendChild(notificationComponent)
15 |
16 | notificationComponent.setAttribute('data-notify-show', true)
17 |
18 | if (notificationData.autoClose) {
19 | handleAutoClose(notificationComponent, notificationData.autoClose)
20 | }
21 |
22 | if (notificationData.autoRemove) {
23 | handleAutoRemove(notificationComponent, notificationData.autoRemove)
24 | }
25 |
26 | if (notificationData.classNames) {
27 | handleClassNames(notificationData.classNames, notificationComponent)
28 | }
29 | }
30 |
31 | fetchTemplate()
32 | }
33 |
--------------------------------------------------------------------------------
/src/useTemplate.js:
--------------------------------------------------------------------------------
1 | import { handleAutoClose } from './handleAutoClose'
2 | import { handleAutoRemove } from './handleAutoRemove'
3 | import { handleClassNames } from './handleClassNames'
4 | import { createNotification } from './createNotification'
5 |
6 | export function useTemplate(notificationText, notificationData) {
7 | const notificationComponent = createNotification(
8 | notificationData.wrapperId,
9 | notificationData.templateId,
10 | notificationText
11 | )
12 |
13 | if (notificationData.autoClose) {
14 | handleAutoClose(notificationComponent, notificationData.autoClose)
15 | }
16 |
17 | if (notificationData.autoRemove) {
18 | handleAutoRemove(notificationComponent, notificationData.autoRemove)
19 | }
20 |
21 | if (notificationData.classNames) {
22 | handleClassNames(notificationData.classNames, notificationComponent)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------