playbook_ui_docs 14.12.0.pre.alpha.PBNTR456fixedconftoastrailsautoclose5728 → 14.12.0.pre.alpha.PBNTR456fixedconftoastrailsautoclose5754
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78ad68a3a8cb94bf9de6d6caefa6d3918a6d6c469471e4dc32c88802a109feca
|
4
|
+
data.tar.gz: 65febeef99376d292a64ae2f677c65bbca8c9814a939d0d4d1c549347f6ec2dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ace02b69d3058994e0bf8b61569192e963feaf17b0b489b0285864ccb42f2b8580498c1a2d68654555de5e98d096d27e46fc4fc0e53e57bf8c5a26999947c484
|
7
|
+
data.tar.gz: cf1b1991c3ababd471f2bcc3404cd92b215d967ca0a473d2cac65e5b48646f3391b3b401479a6d03efa9215af844bd5c341ae9109f324409c66ab029487f163b
|
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
<%= pb_rails("fixed_confirmation_toast", props: {
|
5
5
|
auto_close: 3000,
|
6
|
+
classname: "toast-to-hide",
|
6
7
|
id: "toast-auto-close",
|
7
8
|
text: "I will disappear in 3 seconds.",
|
8
9
|
status: "tip",
|
@@ -21,54 +22,37 @@
|
|
21
22
|
}) %>
|
22
23
|
|
23
24
|
<script>
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
document.addEventListener('DOMContentLoaded', () => {
|
26
|
+
// Initialize toast elements and buttons
|
27
|
+
const toasts = {
|
28
|
+
'#toast-auto-close': document.querySelector("#toast-auto-close"),
|
29
|
+
'#toast-auto-close-closeable': document.querySelector("#toast-auto-close-closeable")
|
30
|
+
}
|
31
|
+
|
32
|
+
const buttons = {
|
33
|
+
'#toast-auto-close': document.querySelector("button[data-toast='#toast-auto-close']"),
|
34
|
+
'#toast-auto-close-closeable': document.querySelector("button[data-toast='#toast-auto-close-closeable']")
|
35
|
+
}
|
36
|
+
|
37
|
+
// Store original toasts and remove them from DOM
|
38
|
+
const originalToasts = {}
|
39
|
+
Object.entries(toasts).forEach(([id, toast]) => {
|
40
|
+
if (toast) {
|
41
|
+
originalToasts[id] = toast.cloneNode(true)
|
42
|
+
toast.remove()
|
28
43
|
}
|
29
|
-
|
30
|
-
const buttons = {
|
31
|
-
'#toast-auto-close': document.querySelector("button[data-toast='#toast-auto-close']"),
|
32
|
-
'#toast-auto-close-closeable': document.querySelector("button[data-toast='#toast-auto-close-closeable']")
|
33
|
-
}
|
34
|
-
|
35
|
-
const hideAllToastsUponPageLoad = () => {
|
36
|
-
Object.values(toasts).forEach(toast => {
|
37
|
-
if (toast) toast.style.display = "none"
|
38
|
-
})
|
39
|
-
}
|
40
|
-
|
41
|
-
const showAndAutoCloseToast = (toastId) => {
|
42
|
-
hideAllToastsUponPageLoad()
|
43
|
-
const toast = toasts[toastId]
|
44
|
-
|
45
|
-
if (toast) {
|
46
|
-
toast.style.display = "flex" // Show the selected toast
|
47
|
-
|
48
|
-
const autoCloseClass = Array.from(toast.classList).find(cls => cls.startsWith('auto_close_'))
|
49
|
-
if (autoCloseClass) {
|
50
|
-
const duration = parseInt(autoCloseClass.split('_')[2]) || 0; // Use 0 as fallback if parsing fails
|
51
|
-
|
52
|
-
if (toast.autoCloseTimeout) {
|
53
|
-
clearTimeout(toast.autoCloseTimeout)
|
54
|
-
}
|
44
|
+
})
|
55
45
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
46
|
+
// Set up button click handlers
|
47
|
+
Object.keys(buttons).forEach((toastId) => {
|
48
|
+
const button = buttons[toastId]
|
49
|
+
if (button) {
|
50
|
+
button.onclick = () => {
|
51
|
+
const newToast = originalToasts[toastId].cloneNode(true)
|
52
|
+
newToast.style.display = "flex"
|
53
|
+
document.body.appendChild(newToast)
|
60
54
|
}
|
61
55
|
}
|
62
|
-
|
63
|
-
Object.keys(buttons).forEach((key) => {
|
64
|
-
const button = buttons[key]
|
65
|
-
if (button) {
|
66
|
-
button.onclick = () => {
|
67
|
-
showAndAutoCloseToast(key)
|
68
|
-
}
|
69
|
-
}
|
70
|
-
})
|
71
|
-
|
72
|
-
hideAllToastsUponPageLoad()
|
73
56
|
})
|
74
|
-
|
57
|
+
})
|
58
|
+
</script>
|
@@ -1,3 +1,3 @@
|
|
1
|
-
Auto close is used when you want the confirmation toast to close automatically after a certain time. `auto_close` property will be a delay number in ms.
|
1
|
+
Auto close is used when you want the confirmation toast to close automatically after a certain time. `auto_close` property will be a delay number in ms. The `auto_close` property currently only works in rails when it is a closeable one (`closeable: true`).
|
2
2
|
|
3
|
-
|
3
|
+
The script tag in this code snippet is for demonstration purposes only. It clones the toast in order to have it appear with a button click prompt and not upon initial page load. In a typical production environment the event triggering a fixed confirmation toast to appear would be handled by a controller or a separate javascript file.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: playbook_ui_docs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 14.12.0.pre.alpha.
|
4
|
+
version: 14.12.0.pre.alpha.PBNTR456fixedconftoastrailsautoclose5754
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Power UX
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2025-01-
|
12
|
+
date: 2025-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: playbook_ui
|