csedl-stimulus-dropdown 0.0.1 → 0.0.2
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 +21 -0
- data/lib/stimulus-dropdown.rb +19 -0
- data/lib/stimulus_dropdown/railtie.rb +10 -0
- data/lib/stimulus_dropdown/view_helpers.rb +138 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e43016e24c2f39eed752c56dc5d4707d474e11a67175dfc7319c53f667c5f58
|
4
|
+
data.tar.gz: 195707fde4dc49ed2cf5b23f10f743a823fc130847469af071febaa72c32697c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3893b38c33472ce306304a5e781832ee371b53c65269bd212ee598e4cce6e87cda56213f66a1192a44913c6220411225f8ac0675ec478fffb568237ba9fb6704
|
7
|
+
data.tar.gz: 225631aabdc19e36cc196efec471f0930e835827a88e01e599b577f415a9699d4929bba0e584fa70c1956bc45402c50e169c66680dcba534494baf3b5e404ad5
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Stimulus Dropdown
|
2
|
+
|
3
|
+
This is nothing else than two view helpers corresponding to the npm package
|
4
|
+
[@csedl/stimulus-dropdown](https://www.npmjs.com/package/@csedl/stimulus-dropdown)
|
5
|
+
|
6
|
+
You also can just paste this [view helpers](https://gitlab.com/sedl/csedl-stimulus-dropdown/-/blob/main/lib/stimulus_dropdown/view_helpers.rb?ref_type=heads)
|
7
|
+
into your app and modify as you want.
|
8
|
+
|
9
|
+
If you work with the helpers on this gem, you can setup a initializer for a custom close-button, like:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
#=> config/initializers/stimulus_dropdown.rb
|
13
|
+
|
14
|
+
StimulusDropdown.configure do |config|
|
15
|
+
config.close_button_proc = ->(view) do
|
16
|
+
view.content_tag(:span, 'X', class: 'close-button')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
License: MIT
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "stimulus_dropdown/railtie" if defined?(Rails)
|
2
|
+
require "stimulus_dropdown/view_helpers"
|
3
|
+
|
4
|
+
module StimulusDropdown
|
5
|
+
class << self
|
6
|
+
attr_accessor :close_button_proc
|
7
|
+
|
8
|
+
def configure
|
9
|
+
yield self
|
10
|
+
end
|
11
|
+
|
12
|
+
def reset_config!
|
13
|
+
self.close_button_proc = nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Default fallback if no config is set
|
18
|
+
self.close_button_proc = nil
|
19
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
module StimulusDropdown
|
2
|
+
module ViewHelpers
|
3
|
+
#== dropdown helper
|
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(:dropdown_panels) on sticky parts (left-menu / top-bar) panels should be at place for avoiding that the panel would scroll with the content
|
6
|
+
# @block [panel_content] Panel Content as block
|
7
|
+
# what it does:
|
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 dropdown_panels-box (because of z-index-hierarchy)
|
10
|
+
# * c) the stimulus controller always adds the class .dropdown-panel to the panel
|
11
|
+
def dropdown(button_content, title = nil, options = {}, &panel_content)
|
12
|
+
if title.is_a?(Hash)
|
13
|
+
options = title.dup
|
14
|
+
title = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
panel_at_place = options.delete(:panel_at_place)
|
18
|
+
|
19
|
+
id = "dropdown-panel-#{SecureRandom.hex(4)}"
|
20
|
+
|
21
|
+
src = options.delete(:src)
|
22
|
+
|
23
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
24
|
+
# create the Button
|
25
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
26
|
+
|
27
|
+
button_options = options.dup
|
28
|
+
button_options[:class] = [options[:class], 'dropdown-button'].compact.join(' ')
|
29
|
+
button_options = button_options.merge(data: { controller: 'csedl-dropdown', toggle: id })
|
30
|
+
|
31
|
+
button_content = capture(&button_content) if button_content.is_a?(Proc)
|
32
|
+
btn = content_tag(:div, button_content, button_options)
|
33
|
+
|
34
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
35
|
+
# create the panel
|
36
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
37
|
+
|
38
|
+
panel_options = options.dup
|
39
|
+
panel_options[:class] = [options[:class], 'dropdown-panel hide'].compact.join(' ')
|
40
|
+
panel_options[:id] = id
|
41
|
+
panel_options['data-src'] = src if src
|
42
|
+
close_btn_proc = StimulusDropdown.close_button_proc
|
43
|
+
|
44
|
+
panel = content_tag(:div, panel_options) do
|
45
|
+
safe_join([
|
46
|
+
content_tag(:div, class: 'header') do
|
47
|
+
concat content_tag(:div, title, class: 'title')
|
48
|
+
concat content_tag(:div, class: 'buttons') { close_btn_proc.present? ? close_btn_proc.call(self) : 'X' }
|
49
|
+
end,
|
50
|
+
content_tag(:div, class: 'content') do
|
51
|
+
capture(&panel_content) if block_given?
|
52
|
+
end
|
53
|
+
])
|
54
|
+
end
|
55
|
+
|
56
|
+
if panel_at_place
|
57
|
+
btn + panel
|
58
|
+
else
|
59
|
+
content_for(:dropdown_panels, panel)
|
60
|
+
btn
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def tooltip(label, options = {}, &content)
|
66
|
+
|
67
|
+
panel_at_place = options.delete(:panel_at_place) || false
|
68
|
+
delay = options.delete(:delay) || 0.4
|
69
|
+
src = options.delete(:src)
|
70
|
+
label_class = options.delete(:label_class) || 'tooltip-label'
|
71
|
+
|
72
|
+
id = ['tooltip', SecureRandom.hex(4)].join('-')
|
73
|
+
|
74
|
+
lab = if label.is_a?(Proc)
|
75
|
+
capture &label
|
76
|
+
else
|
77
|
+
label
|
78
|
+
end
|
79
|
+
cont = capture(&content) if block_given?
|
80
|
+
|
81
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
82
|
+
# create the Label
|
83
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
84
|
+
|
85
|
+
label_options = options.dup
|
86
|
+
label_options[:id] = options.delete(:id)
|
87
|
+
label_options[:class] = [options[:class], label_class].compact.join(' ')
|
88
|
+
label_options = label_options.merge(data: { controller: 'csedl-tooltip', toggle: id, delay: delay })
|
89
|
+
|
90
|
+
label_element = if block_given? && cont.present?
|
91
|
+
content_tag(:span, label_options) do
|
92
|
+
lab
|
93
|
+
end
|
94
|
+
else
|
95
|
+
lab
|
96
|
+
end
|
97
|
+
|
98
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
99
|
+
# create the panel
|
100
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
101
|
+
|
102
|
+
panel_options = options.dup
|
103
|
+
panel_options[:class] = [options[:class], 'tooltip-panel hide'].compact.join(' ')
|
104
|
+
panel_options[:id] = id
|
105
|
+
panel_options['data-src'] = src if src
|
106
|
+
|
107
|
+
panel_element = if block_given? && cont.present?
|
108
|
+
content_tag(:div, panel_options) do
|
109
|
+
r2 = content_tag :div, id: "arrow-#{id}" do
|
110
|
+
; nil;
|
111
|
+
end
|
112
|
+
r2 << content_tag(:div, class: 'tooltip-content') do
|
113
|
+
cont
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
119
|
+
# return the result
|
120
|
+
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
121
|
+
|
122
|
+
|
123
|
+
if !panel_element
|
124
|
+
label_element
|
125
|
+
elsif panel_at_place
|
126
|
+
r = label_element
|
127
|
+
r << panel_element
|
128
|
+
else
|
129
|
+
content_for(:dropdown_panels) do
|
130
|
+
panel_element
|
131
|
+
end
|
132
|
+
label_element
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csedl-stimulus-dropdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Sedlmair
|
@@ -15,7 +15,11 @@ email: christian@sedlmair.ch
|
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
|
-
files:
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- lib/stimulus-dropdown.rb
|
21
|
+
- lib/stimulus_dropdown/railtie.rb
|
22
|
+
- lib/stimulus_dropdown/view_helpers.rb
|
19
23
|
homepage: https://gitlab.com/sedl/csedl-stimulus-dropdown
|
20
24
|
licenses:
|
21
25
|
- MIT
|