stimulus-overlay-helpers 2.0.0 → 3.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 +1 -1
- data/lib/stimulus-overlay-helpers.rb +3 -1
- data/lib/stimulus_overlay_helpers/view_helpers.rb +77 -77
- metadata +3 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 39101cef1d9fef4cba42c3dc3e19766b1936cadb91c04b8120cb40d436959764
|
|
4
|
+
data.tar.gz: 583c4630ee41e316dab54038034d849b0dd858132fb08804b802ab56a39d29da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 756f24cf638fcde7836f0ca95419c526b26c646d2d6cf92ebe3796a8ddabd0ab097b3bee8969b3bcabf714a260a13f20804f9154e672c87087a31cb577c47561
|
|
7
|
+
data.tar.gz: da5451bfbb0c43d1cb1fa35cd92cb7e02cb9b0a0af5575ce29d5300c5676c4339d1e59f1aebba97519bdf3a65b9c32d606a9e02501340cf79ebcf834c4c567ef
|
data/README.md
CHANGED
|
@@ -4,7 +4,7 @@ require 'stimulus_overlay_helpers/view_helpers'
|
|
|
4
4
|
# Provides helpers and configuration for Stimulus overlay behavior.
|
|
5
5
|
module StimulusOverlayHelpers
|
|
6
6
|
class << self
|
|
7
|
-
attr_accessor :close_button_proc
|
|
7
|
+
attr_accessor :close_button_proc, :dropdown_arrow
|
|
8
8
|
|
|
9
9
|
def configure
|
|
10
10
|
yield self
|
|
@@ -12,9 +12,11 @@ module StimulusOverlayHelpers
|
|
|
12
12
|
|
|
13
13
|
def reset_config!
|
|
14
14
|
self.close_button_proc = nil
|
|
15
|
+
self.dropdown_arrow = true
|
|
15
16
|
end
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
# Default fallback if no config is set
|
|
19
20
|
self.close_button_proc = nil
|
|
21
|
+
self.dropdown_arrow = false
|
|
20
22
|
end
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
module StimulusOverlayHelpers
|
|
2
2
|
module ViewHelpers
|
|
3
|
+
|
|
4
|
+
|
|
3
5
|
#== dropdown helper
|
|
4
6
|
# @param [button_content] Proc or String for content of the button element
|
|
5
7
|
# @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
|
|
@@ -8,6 +10,10 @@ module StimulusOverlayHelpers
|
|
|
8
10
|
# * a) wraps the button_content in element like: %button{ data: { controller: 'dropdown', ... } } and renders it at place
|
|
9
11
|
# * b) wraps the panel_content in a corresponding element and renders it to the overlays_box (because of z-index-hierarchy)
|
|
10
12
|
# * c) the stimulus controller always adds the class .dropdown-panel to the panel
|
|
13
|
+
# * options:
|
|
14
|
+
# ** class: custom class for the dropdown-button
|
|
15
|
+
# ** panel_class: custom class for the dropdown-panel
|
|
16
|
+
# ** src: custom src for the dropdown-panel, triggers a GET xhr request that fills up the panel
|
|
11
17
|
def dropdown(button_content, title = nil, options = {}, &panel_content)
|
|
12
18
|
if title.is_a?(Hash)
|
|
13
19
|
options = title.dup
|
|
@@ -15,34 +21,29 @@ module StimulusOverlayHelpers
|
|
|
15
21
|
end
|
|
16
22
|
|
|
17
23
|
panel_at_place = options.delete(:panel_at_place)
|
|
24
|
+
src = options.delete(:src)
|
|
25
|
+
button_class = [options.delete(:button_class), 'dropdown-button', options[:class]].compact.join(' ')
|
|
26
|
+
panel_class = [options.delete(:class), 'dropdown-panel'].compact.join(' ')
|
|
27
|
+
close_btn_proc = StimulusOverlayHelpers.close_button_proc
|
|
18
28
|
|
|
19
29
|
id = "dropdown-panel-#{SecureRandom.hex(4)}"
|
|
20
30
|
|
|
21
|
-
src = options.delete(:src)
|
|
22
|
-
|
|
23
31
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
24
32
|
# create the Button
|
|
25
33
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
26
34
|
|
|
27
|
-
|
|
28
|
-
button_options
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
button_content = capture(&button_content) if button_content.is_a?(Proc)
|
|
32
|
-
btn = content_tag(:div, button_content, button_options)
|
|
35
|
+
button_content = capture(&panel_content_button = button_content) if button_content.is_a?(Proc)
|
|
36
|
+
button_options = options.merge(class: button_class, data: { controller: 'hotwire-svelte-helpers-dropdown', panel_id: id })
|
|
37
|
+
button_element = content_tag(:div, button_content, button_options)
|
|
33
38
|
|
|
34
39
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
35
40
|
# create the panel
|
|
36
41
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
37
42
|
|
|
38
|
-
panel_options = options.
|
|
39
|
-
panel_options[
|
|
40
|
-
panel_options[:style] = "display: none;"
|
|
41
|
-
panel_options[:id] = id
|
|
42
|
-
panel_options['data-src'] = src if src
|
|
43
|
-
close_btn_proc = StimulusOverlayHelpers.close_button_proc
|
|
43
|
+
panel_options = options.merge(class: panel_class, style: 'display: none;', id: id)
|
|
44
|
+
panel_options['data-src'] = src if src.present?
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
panel_element = content_tag(:div, panel_options) do
|
|
46
47
|
safe_join([
|
|
47
48
|
content_tag(:div, class: 'header') do
|
|
48
49
|
concat content_tag(:div, title, class: 'title')
|
|
@@ -50,18 +51,31 @@ module StimulusOverlayHelpers
|
|
|
50
51
|
end,
|
|
51
52
|
content_tag(:div, class: 'content') do
|
|
52
53
|
capture(&panel_content) if block_given?
|
|
53
|
-
end
|
|
54
|
+
end,
|
|
55
|
+
(content_tag(:div, nil, id: 'arrow') if StimulusOverlayHelpers.dropdown_arrow),
|
|
54
56
|
])
|
|
55
57
|
end
|
|
56
58
|
|
|
59
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
60
|
+
# return the result
|
|
61
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
62
|
+
|
|
57
63
|
if panel_at_place
|
|
58
|
-
|
|
64
|
+
button_element + panel_element
|
|
59
65
|
else
|
|
60
|
-
content_for(:overlays_box,
|
|
61
|
-
|
|
66
|
+
content_for(:overlays_box, panel_element)
|
|
67
|
+
button_element
|
|
62
68
|
end
|
|
63
69
|
end
|
|
64
70
|
|
|
71
|
+
#== modal helper
|
|
72
|
+
# @param [button_content] Proc or String for content of the button element
|
|
73
|
+
# @param [panel_at_place] true (default: false) => it would render the overlay into content_for(:overlays_box) on sticky parts (left-menu / top-bar) overlays should be at place for avoiding that the overlay would scroll with the content
|
|
74
|
+
# @block [panel_content] Panel Content as block
|
|
75
|
+
# what it does:
|
|
76
|
+
# * a) wraps the button_content in element like: %button{ data: { controller: 'modal', ... } } and renders it at place
|
|
77
|
+
# * b) wraps the panel_content in a full-screen overlay element and renders it to the overlays_box (because of z-index-hierarchy)
|
|
78
|
+
# * c) the stimulus controller always adds the class .modal-panel to the panel and .modal-overlay to the backdrop
|
|
65
79
|
def modal(button_content, title = nil, options = {}, &panel_content)
|
|
66
80
|
if title.is_a?(Hash)
|
|
67
81
|
options = title.dup
|
|
@@ -69,32 +83,29 @@ module StimulusOverlayHelpers
|
|
|
69
83
|
end
|
|
70
84
|
|
|
71
85
|
panel_at_place = options.delete(:panel_at_place)
|
|
86
|
+
src = options.delete(:src)
|
|
87
|
+
button_class = [options.delete(:button_class) || 'modal-button', options[:class]].compact.join(' ')
|
|
88
|
+
panel_class = [options.delete(:class), 'modal-panel'].compact.join(' ')
|
|
89
|
+
close_btn_proc = StimulusOverlayHelpers.close_button_proc
|
|
72
90
|
|
|
73
91
|
id = "modal-overlay-#{SecureRandom.hex(4)}"
|
|
74
92
|
|
|
75
|
-
src = options.delete(:src)
|
|
76
|
-
|
|
77
93
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
78
94
|
# create the Button
|
|
79
95
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
80
96
|
|
|
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
97
|
button_content = capture(&button_content) if button_content.is_a?(Proc)
|
|
86
|
-
|
|
98
|
+
button_options = options.merge(class: button_class, data: { controller: 'hotwire-svelte-helpers-modal', panel_id: id })
|
|
99
|
+
button_element = content_tag(:div, button_content, button_options)
|
|
87
100
|
|
|
88
101
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
89
102
|
# create the overlay
|
|
90
103
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
91
104
|
|
|
92
|
-
panel_options = options.
|
|
93
|
-
panel_options[
|
|
94
|
-
panel_options['data-src'] = src if src
|
|
95
|
-
close_btn_proc = StimulusOverlayHelpers.close_button_proc
|
|
105
|
+
panel_options = options.merge(class: panel_class)
|
|
106
|
+
panel_options['data-src'] = src if src.present?
|
|
96
107
|
|
|
97
|
-
|
|
108
|
+
overlay_element = content_tag(:div, class: 'modal-overlay', style: 'display:none;', id: id) do
|
|
98
109
|
content_tag(:div, panel_options) do
|
|
99
110
|
safe_join([
|
|
100
111
|
content_tag(:div, class: 'header') do
|
|
@@ -108,81 +119,70 @@ module StimulusOverlayHelpers
|
|
|
108
119
|
end
|
|
109
120
|
end
|
|
110
121
|
|
|
122
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
123
|
+
# return the result
|
|
124
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
125
|
+
|
|
111
126
|
if panel_at_place
|
|
112
|
-
|
|
127
|
+
button_element + overlay_element
|
|
113
128
|
else
|
|
114
|
-
content_for(:overlays_box,
|
|
115
|
-
|
|
129
|
+
content_for(:overlays_box, overlay_element)
|
|
130
|
+
button_element
|
|
116
131
|
end
|
|
117
132
|
end
|
|
118
133
|
|
|
119
|
-
|
|
134
|
+
#== tooltip helper
|
|
135
|
+
# @param [tip] Proc or String for the tooltip content (the panel shown on hover)
|
|
136
|
+
# @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
|
|
137
|
+
# @param [delay] Number (default: 0.4) => delay in seconds before the tooltip is shown
|
|
138
|
+
# @block [label] the visible label/element that triggers the tooltip on hover
|
|
139
|
+
# what it does:
|
|
140
|
+
# * a) wraps the label in element like: %span{ data: { controller: 'tooltip', ... } } and renders it at place
|
|
141
|
+
# * b) wraps the tip in a corresponding panel element and renders it to the overlays_box (because of z-index-hierarchy)
|
|
142
|
+
# * c) the stimulus controller always adds the class .tooltip-panel to the panel
|
|
143
|
+
def tooltip(tip, options = {}, &)
|
|
144
|
+
label = capture(&) if block_given?
|
|
145
|
+
tip = capture &tip if tip.is_a?(Proc)
|
|
146
|
+
return '' if label.blank?
|
|
147
|
+
return label if tip.blank?
|
|
120
148
|
|
|
121
149
|
panel_at_place = options.delete(:panel_at_place) || false
|
|
122
150
|
delay = options.delete(:delay) || 0.4
|
|
123
151
|
src = options.delete(:src)
|
|
124
|
-
label_class = options.delete(:label_class) || 'tooltip-label'
|
|
152
|
+
label_class = [options.delete(:label_class) || 'tooltip-label', options[:class]].compact.join(' ')
|
|
153
|
+
panel_class = [options.delete(:class), 'tooltip-panel'].compact.join(' ')
|
|
125
154
|
|
|
126
|
-
id =
|
|
127
|
-
|
|
128
|
-
lab = if label.is_a?(Proc)
|
|
129
|
-
capture &label
|
|
130
|
-
else
|
|
131
|
-
label
|
|
132
|
-
end
|
|
133
|
-
cont = capture(&content) if block_given?
|
|
155
|
+
id = "tooltip-#{SecureRandom.hex(4)}"
|
|
134
156
|
|
|
135
157
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
136
158
|
# create the Label
|
|
137
159
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
138
160
|
|
|
139
|
-
label_options = options.
|
|
140
|
-
|
|
141
|
-
label_options[:class] = [options[:class], label_class].compact.join(' ')
|
|
142
|
-
label_options = label_options.merge(data: { controller: 'hotwire-svelte-helpers-tooltip', panel_id: id, delay: delay })
|
|
143
|
-
|
|
144
|
-
label_element = if block_given? && cont.present?
|
|
145
|
-
content_tag(:span, label_options) do
|
|
146
|
-
lab
|
|
147
|
-
end
|
|
148
|
-
else
|
|
149
|
-
lab
|
|
150
|
-
end
|
|
161
|
+
label_options = options.merge(class: label_class, data: { controller: 'hotwire-svelte-helpers-tooltip', panel_id: id, delay: delay })
|
|
162
|
+
label_element = content_tag(:span, label, label_options)
|
|
151
163
|
|
|
152
164
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
153
165
|
# create the panel
|
|
154
166
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
155
167
|
|
|
156
|
-
panel_options = options.
|
|
157
|
-
panel_options[
|
|
158
|
-
panel_options[:id] = id
|
|
159
|
-
panel_options[:style] = 'display: none;'
|
|
160
|
-
panel_options['data-src'] = src if src
|
|
168
|
+
panel_options = options.merge(class: panel_class, style: 'display: none', id: id)
|
|
169
|
+
panel_options['data-src'] = src if src.present?
|
|
161
170
|
|
|
162
|
-
panel_element =
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
end
|
|
171
|
+
panel_element = content_tag(:div, panel_options) do
|
|
172
|
+
content_tag( :div, '', id: "arrow") +
|
|
173
|
+
content_tag(:div, tip, class: 'tooltip-content')
|
|
174
|
+
end
|
|
169
175
|
|
|
170
176
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
171
177
|
# return the result
|
|
172
178
|
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
|
173
179
|
|
|
174
|
-
if
|
|
175
|
-
label_element
|
|
176
|
-
elsif panel_at_place
|
|
177
|
-
r = label_element
|
|
178
|
-
r << panel_element
|
|
180
|
+
if panel_at_place
|
|
181
|
+
label_element + panel_element
|
|
179
182
|
else
|
|
180
|
-
content_for(:overlays_box)
|
|
181
|
-
panel_element
|
|
182
|
-
end
|
|
183
|
+
content_for(:overlays_box, panel_element)
|
|
183
184
|
label_element
|
|
184
185
|
end
|
|
185
|
-
|
|
186
186
|
end
|
|
187
187
|
|
|
188
188
|
end
|
metadata
CHANGED
|
@@ -1,16 +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: 3.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Christian Sedlmair
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
|
-
description:
|
|
14
12
|
email: christian@sedlmair.ch
|
|
15
13
|
executables: []
|
|
16
14
|
extensions: []
|
|
@@ -27,7 +25,6 @@ metadata:
|
|
|
27
25
|
homepage_uri: https://gitlab.com/sedl/stimulus-overlay-helpers
|
|
28
26
|
source_code_uri: https://gitlab.com/sedl/stimulus-overlay-helpers
|
|
29
27
|
changelog_uri: https://gitlab.com/sedl/stimulus-overlay-helpers
|
|
30
|
-
post_install_message:
|
|
31
28
|
rdoc_options: []
|
|
32
29
|
require_paths:
|
|
33
30
|
- lib
|
|
@@ -42,8 +39,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
42
39
|
- !ruby/object:Gem::Version
|
|
43
40
|
version: '0'
|
|
44
41
|
requirements: []
|
|
45
|
-
rubygems_version: 3.
|
|
46
|
-
signing_key:
|
|
42
|
+
rubygems_version: 3.6.7
|
|
47
43
|
specification_version: 4
|
|
48
44
|
summary: View helpers for the npm package @csedl/hotwire-svelte-helpers
|
|
49
45
|
test_files: []
|