odt-ui-rails 2.2.5 → 2.2.6

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: fcba58b390c748340a5bfd2d50e9f54c90684e481c5973801d6747a5dd5aa646
4
- data.tar.gz: f87d24815c3a9748d1afc89bb11687f655d2022890d9ca53f0589575e25ab20e
3
+ metadata.gz: ab34fa664bc14d7404f1775d69778c07beaa8e02a02986b249f99290cd678a24
4
+ data.tar.gz: acb1f1ec60f3532a9a8f2ab2d873a2cab4d01561afe86836bef75b766f0872bc
5
5
  SHA512:
6
- metadata.gz: 89b0db215f2b52c3e046d0b16ea1bd9098ff4f896f4e19f31d4d1c078173444e9143da6497d491baba8ce6761fc0c419e3d4d2251eb76bad0dfc157427595c17
7
- data.tar.gz: 607db973d0fea09189079c15e88c1810e45bed02f20c3b9bb6577521cc0c09776e5fac940a3f3c866de85f6d16f401553b07826ea12c486f91bedf3368787789
6
+ metadata.gz: e2c5806ac69d61d9fe95beba963735de017ae27356d089959d8ecb6c22aeaeace327ca1fcf89cefbd3730d1da9efd15748af951e73d2b628b3214973ddf314ae
7
+ data.tar.gz: 97d5a781fa5532a80c9283f469c6b8f49c2eb3ebebc6e09f3c9c2084eef29b5e3a001ff0bfbd1961933e4a68c96fdba3f74b89ab06ed242e951d1bba7934b9e7
data/README.md CHANGED
@@ -58,7 +58,7 @@
58
58
  Add the gem to your application's `Gemfile`:
59
59
 
60
60
  ```ruby
61
- gem "odt-ui-rails", "~> 2.2.5"
61
+ gem "odt-ui-rails", "~> 2.2.6"
62
62
  ```
63
63
 
64
64
  Install dependencies:
@@ -74,6 +74,7 @@ bin/rails g odt:install
74
74
  ```
75
75
 
76
76
  The generator will:
77
+
77
78
  1. Inject `<%= stylesheet_link_tag "odt_ui", "data-turbo-track": "reload" %>` into your `app/views/layouts/application.html.erb`.
78
79
  2. Configure Tailwind CSS v4 `@theme` (`odt_theme.css`) if Tailwind is detected.
79
80
  3. Copy `sig/odt_ui.rbs` for Ruby LSP IDE autocompletion.
@@ -104,7 +105,7 @@ If using Tailwind CSS v4 and you want ODT design token utilities (`bg-primary-50
104
105
  @import "./odt_theme.css";
105
106
  ```
106
107
 
107
- *(Note: `odt_theme.css` is placed in your tailwind assets folder by `bin/rails g odt:install`)*
108
+ _(Note: `odt_theme.css` is placed in your tailwind assets folder by `bin/rails g odt:install`)_
108
109
 
109
110
  ---
110
111
 
@@ -12,6 +12,29 @@ export default class extends Controller {
12
12
  this.mutationObserver = new MutationObserver(() => this.handleMutations())
13
13
  this.mutationObserver.observe(this.element, { childList: true })
14
14
  this.handleMutations()
15
+
16
+ this.boundTriggerHandler = (event) => {
17
+ const trigger = event.target.closest("[data-odt-toast-message], [data-odt-toast-title]")
18
+ if (trigger) {
19
+ event.preventDefault()
20
+ this.show({
21
+ title: trigger.dataset.odtToastTitle,
22
+ message: trigger.dataset.odtToastMessage,
23
+ type: trigger.dataset.odtToastType || "default",
24
+ variant: trigger.dataset.odtToastVariant || "elevated",
25
+ duration: Number(trigger.dataset.odtToastDuration) || 4000
26
+ })
27
+ }
28
+ }
29
+ document.addEventListener("click", this.boundTriggerHandler)
30
+
31
+ window.odtToast = {
32
+ show: (options) => this.show(options),
33
+ success: (title, message) => this.show({ title, message, type: "success" }),
34
+ error: (title, message) => this.show({ title, message, type: "danger" }),
35
+ warning: (title, message) => this.show({ title, message, type: "warning" }),
36
+ info: (title, message) => this.show({ title, message, type: "info" })
37
+ }
15
38
  }
16
39
 
17
40
  disconnect() {
@@ -21,6 +44,64 @@ export default class extends Controller {
21
44
  if (this.leaveTimeout) {
22
45
  clearTimeout(this.leaveTimeout)
23
46
  }
47
+ if (this.boundTriggerHandler) {
48
+ document.removeEventListener("click", this.boundTriggerHandler)
49
+ }
50
+ if (window.odtToast) {
51
+ delete window.odtToast
52
+ }
53
+ }
54
+
55
+ show(eventOrOptions = {}) {
56
+ const options = eventOrOptions?.params || eventOrOptions || {}
57
+ const title = options.title || ""
58
+ const message = options.message || ""
59
+ const type = options.type || "default"
60
+ const variant = options.variant || "elevated"
61
+ const duration = options.duration !== undefined ? Number(options.duration) : 4000
62
+
63
+ const toast = document.createElement("div")
64
+ toast.className = `odt-toast odt-toast--variant-${variant}`
65
+ toast.setAttribute("role", "status")
66
+ toast.setAttribute("data-controller", "odt-toast")
67
+ toast.setAttribute("data-odt-toast-duration-value", duration.toString())
68
+
69
+ const parts = []
70
+
71
+ const icons = {
72
+ success: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6L9 17l-5-5"/></svg>',
73
+ info: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>',
74
+ warning: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>',
75
+ danger: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>',
76
+ error: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>',
77
+ loading: '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12a9 9 0 11-6.219-8.56"/></svg>'
78
+ }
79
+
80
+ if (icons[type]) {
81
+ parts.push(`<span class="odt-toast__icon odt-toast__icon--${type}">${icons[type]}</span>`)
82
+ }
83
+
84
+ let bodyHtml = '<div class="odt-toast__body">'
85
+ if (title) {
86
+ bodyHtml += `<div class="odt-toast__title">${title}</div>`
87
+ }
88
+ if (message) {
89
+ bodyHtml += `<div class="odt-toast__description">${message}</div>`
90
+ }
91
+ bodyHtml += '</div>'
92
+ parts.push(bodyHtml)
93
+
94
+ parts.push(`
95
+ <button type="button" class="odt-toast__close" aria-label="Close" data-action="click->odt-toast#dismiss">
96
+ <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
97
+ <line x1="18" y1="6" x2="6" y2="18"></line>
98
+ <line x1="6" y1="6" x2="18" y2="18"></line>
99
+ </svg>
100
+ </button>
101
+ `)
102
+
103
+ toast.innerHTML = parts.join("")
104
+ this.element.appendChild(toast)
24
105
  }
25
106
 
26
107
  handleMutations() {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OdtUi
4
- VERSION = "2.2.5"
4
+ VERSION = "2.2.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odt-ui-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.5
4
+ version: 2.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pixel