stimulus-overlay-helpers 0.0.3 → 1.1.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 +4 -4
- data/README.md +14 -0
- data/lib/stimulus_overlay_helpers/view_helpers.rb +59 -7
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5011229ca32b328095ee8199121506da0aeda54afddde3e3f6bf07df8352f22e
|
|
4
|
+
data.tar.gz: 634dac393fccc55dd395b92f1173f0133448910cd33946cf4be66e1da858dc5b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e538d62c39cda1f269ec99366b0f42d6ab7ee30b79ae2a6306126fa267218e9916de0937ff4a65960e4147644c1901a99d4137f1d0712a1972be6ef599ddd555
|
|
7
|
+
data.tar.gz: 252cda43827e3659b3bd9b3c62d0695a3e0a3be324b2d530929c5a3fd5979168120ac077a366678e97879fad2bd8b64a2cbc97c1a0c0330bc6889465adc17328
|
data/README.md
CHANGED
|
@@ -32,6 +32,20 @@ StimulusDropdown.configure do |config|
|
|
|
32
32
|
end
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
**Z-index issues / `panel_at_place` option**
|
|
36
|
+
|
|
37
|
+
If an overlay should appear above all other elements, it should be rendered close to the root level because `z-index` is always relative to the current stacking context.
|
|
38
|
+
|
|
39
|
+
By default, unless `true` is passed to the helper’s `panel_at_place` argument, the overlay is rendered via `yield :overlays_box` in the layout:
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
```haml
|
|
43
|
+
#overlays-box
|
|
44
|
+
= yield :overlays_box
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This matches the behavior of the [Svelte overlays from `@csedl/hotwire-svelte-helpers`](https://www.npmjs.com/package/@csedl/hotwire-svelte-helpers).
|
|
48
|
+
|
|
35
49
|
## Usage Examples
|
|
36
50
|
|
|
37
51
|
```haml
|
|
@@ -2,11 +2,11 @@ module StimulusOverlayHelpers
|
|
|
2
2
|
module ViewHelpers
|
|
3
3
|
#== dropdown helper
|
|
4
4
|
# @param [button_content] Proc or String for content of the button element
|
|
5
|
-
# @param [panel_at_place] true (default: false) => it would render the panel into content_for(:
|
|
5
|
+
# @param [panel_at_place] true (default: false) => it would render the panel into content_for(:overlays_box) on sticky parts (left-menu / top-bar) panels should be at place for avoiding that the panel would scroll with the content
|
|
6
6
|
# @block [panel_content] Panel Content as block
|
|
7
7
|
# what it does:
|
|
8
8
|
# * a) wraps the button_content in element like: %button{ data: { controller: 'dropdown', ... } } and renders it at place
|
|
9
|
-
# * b) wraps the panel_content in a corresponding element and renders it to the
|
|
9
|
+
# * b) wraps the panel_content in a corresponding element and renders it to the overlays_box (because of z-index-hierarchy)
|
|
10
10
|
# * c) the stimulus controller always adds the class .dropdown-panel to the panel
|
|
11
11
|
def dropdown(button_content, title = nil, options = {}, &panel_content)
|
|
12
12
|
if title.is_a?(Hash)
|
|
@@ -26,7 +26,7 @@ module StimulusOverlayHelpers
|
|
|
26
26
|
|
|
27
27
|
button_options = options.dup
|
|
28
28
|
button_options[:class] = [options[:class], 'dropdown-button'].compact.join(' ')
|
|
29
|
-
button_options = button_options.merge(data: { controller: '
|
|
29
|
+
button_options = button_options.merge(data: { controller: 'hotwire-svelte-helpers-dropdown', panel_id: id })
|
|
30
30
|
|
|
31
31
|
button_content = capture(&button_content) if button_content.is_a?(Proc)
|
|
32
32
|
btn = content_tag(:div, button_content, button_options)
|
|
@@ -57,11 +57,64 @@ module StimulusOverlayHelpers
|
|
|
57
57
|
if panel_at_place
|
|
58
58
|
btn + panel
|
|
59
59
|
else
|
|
60
|
-
content_for(:
|
|
60
|
+
content_for(:overlays_box, panel)
|
|
61
61
|
btn
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
+
def modal(button_content, title = nil, options = {}, &panel_content)
|
|
66
|
+
if title.is_a?(Hash)
|
|
67
|
+
options = title.dup
|
|
68
|
+
title = nil
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
panel_at_place = options.delete(:panel_at_place)
|
|
72
|
+
|
|
73
|
+
id = "modal-overlay-#{SecureRandom.hex(4)}"
|
|
74
|
+
|
|
75
|
+
src = options.delete(:src)
|
|
76
|
+
|
|
77
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
78
|
+
# create the Button
|
|
79
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
80
|
+
|
|
81
|
+
button_options = options.dup
|
|
82
|
+
button_options[:class] = [options[:class], 'modal-button'].compact.join(' ')
|
|
83
|
+
button_options = button_options.merge(data: { controller: 'hotwire-svelte-helpers-modal', panel_id: id })
|
|
84
|
+
|
|
85
|
+
button_content = capture(&button_content) if button_content.is_a?(Proc)
|
|
86
|
+
btn = content_tag(:div, button_content, button_options)
|
|
87
|
+
|
|
88
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
89
|
+
# create the overlay
|
|
90
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
91
|
+
|
|
92
|
+
panel_options = options.dup
|
|
93
|
+
panel_options[:class] = [options[:class], 'modal-panel'].compact.join(' ')
|
|
94
|
+
panel_options['data-src'] = src if src
|
|
95
|
+
close_btn_proc = StimulusOverlayHelpers.close_button_proc
|
|
96
|
+
|
|
97
|
+
overlay = content_tag(:div, class: 'modal-overlay', style: 'display:none;', id: id) do
|
|
98
|
+
content_tag(:div, panel_options) do
|
|
99
|
+
safe_join([
|
|
100
|
+
content_tag(:div, class: 'header') do
|
|
101
|
+
concat content_tag(:div, title, class: 'title')
|
|
102
|
+
concat content_tag(:div, class: 'buttons') { close_btn_proc.present? ? close_btn_proc.call(self) : content_tag(:span, 'X', class: 'close-button') }
|
|
103
|
+
end,
|
|
104
|
+
content_tag(:div, class: 'content') do
|
|
105
|
+
capture(&panel_content) if block_given?
|
|
106
|
+
end
|
|
107
|
+
])
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
if panel_at_place
|
|
112
|
+
btn + overlay
|
|
113
|
+
else
|
|
114
|
+
content_for(:overlays_box, overlay)
|
|
115
|
+
btn
|
|
116
|
+
end
|
|
117
|
+
end
|
|
65
118
|
|
|
66
119
|
def tooltip(label, options = {}, &content)
|
|
67
120
|
|
|
@@ -86,7 +139,7 @@ module StimulusOverlayHelpers
|
|
|
86
139
|
label_options = options.dup
|
|
87
140
|
label_options[:id] = options.delete(:id)
|
|
88
141
|
label_options[:class] = [options[:class], label_class].compact.join(' ')
|
|
89
|
-
label_options = label_options.merge(data: { controller: '
|
|
142
|
+
label_options = label_options.merge(data: { controller: 'hotwire-svelte-helpers-tooltip', panel_id: id, delay: delay })
|
|
90
143
|
|
|
91
144
|
label_element = if block_given? && cont.present?
|
|
92
145
|
content_tag(:span, label_options) do
|
|
@@ -118,14 +171,13 @@ module StimulusOverlayHelpers
|
|
|
118
171
|
# return the result
|
|
119
172
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
120
173
|
|
|
121
|
-
|
|
122
174
|
if !panel_element
|
|
123
175
|
label_element
|
|
124
176
|
elsif panel_at_place
|
|
125
177
|
r = label_element
|
|
126
178
|
r << panel_element
|
|
127
179
|
else
|
|
128
|
-
content_for(:
|
|
180
|
+
content_for(:overlays_box) do
|
|
129
181
|
panel_element
|
|
130
182
|
end
|
|
131
183
|
label_element
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stimulus-overlay-helpers
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Christian Sedlmair
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email: christian@sedlmair.ch
|