glimmer-web-components 0.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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +20 -0
- data/README.md +92 -0
- data/VERSION +1 -0
- data/glimmer-web-components.gemspec +54 -0
- data/lib/glimmer/web/component/multi_checkbox_dropdown.rb +272 -0
- data/lib/glimmer-web-components.rb +10 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fd50603c60334cf474cca614126379cec3e53f4b6c60a61676dc7f0442fe6091
|
4
|
+
data.tar.gz: a47e9aa2c039a2f0991ac4214daf50f488ce548430f2fd08a5667abc8e11bcdd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 798423e6fb786976420d7ff6ffa5a54ed74ccb19836f0d8de40d28f0bff45455d7bb1fd4c0a5f70c478ee0e0c3ffefdf78d52184912dd7184d9704677ba1afed
|
7
|
+
data.tar.gz: 10474787dadfcb2620bc6fad046d4411ab966b04a97f929a45305a17bc4c7df79064cb53ca795a58d512f52134393a49dde273733731d3c45a3b702978324ab2
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2025 Andy Maleh
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# Glimmer Web Components
|
2
|
+
## [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=40 />Glimmer Web Components](https://github.com/AndyObtiva/glimmer-dsl-web)
|
3
|
+
[](http://badge.fury.io/rb/glimmer-web-components)
|
4
|
+
[](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
5
|
+
|
6
|
+
This is a collection of reusable Glimmer Web Components for Glimmer DSL for Web, extracted from real Rails web applications.
|
7
|
+
|
8
|
+
## Setup
|
9
|
+
|
10
|
+
```
|
11
|
+
gem install glimmer-web-components
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
### Multi Checkbox Dropdown:
|
17
|
+
|
18
|
+

|
19
|
+
|
20
|
+
Add the following at the top:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
require 'glimmer/web/component/multi_checkbox_dropdown'
|
24
|
+
```
|
25
|
+
|
26
|
+
Then use the `multi_checkbox_dropdown` Glimmer Web Component in standard Glimmer HTML DSL code:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
...
|
30
|
+
markup {
|
31
|
+
div {
|
32
|
+
...
|
33
|
+
multi_checkbox_dropdown(
|
34
|
+
values: SomePresenter::STATUS_FILTER_TYPES,
|
35
|
+
display_values: SomePresenter::STATUS_FILTER_TYPES.map { |value| I18n.t("status.#{value}") },
|
36
|
+
locale: I18n.locale,
|
37
|
+
width: 190,
|
38
|
+
translations: {
|
39
|
+
en: {select: I18n.t('form.status_filter', locale: :en)},
|
40
|
+
es: {select: I18n.t('form.status_filter', locale: :es)},
|
41
|
+
},
|
42
|
+
) {
|
43
|
+
selected_values <=> [@some_presenter, :status_filters]
|
44
|
+
}
|
45
|
+
...
|
46
|
+
}
|
47
|
+
}
|
48
|
+
...
|
49
|
+
```
|
50
|
+
|
51
|
+
## Help
|
52
|
+
|
53
|
+
## Issues
|
54
|
+
|
55
|
+
You may submit [issues](https://github.com/AndyObtiva/glimmer-dsl-web/issues) on [GitHub](https://github.com/AndyObtiva/glimmer-dsl-web/issues).
|
56
|
+
|
57
|
+
[Click here to submit an issue.](https://github.com/AndyObtiva/glimmer-dsl-web/issues)
|
58
|
+
|
59
|
+
## Chat
|
60
|
+
|
61
|
+
If you need live help, try to [](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
62
|
+
|
63
|
+
## Feature Suggestions
|
64
|
+
|
65
|
+
These features have been suggested. You might see them in a future version of Glimmer. You are welcome to contribute more feature suggestions.
|
66
|
+
|
67
|
+
[TODO.md](TODO.md)
|
68
|
+
|
69
|
+
## Change Log
|
70
|
+
|
71
|
+
[CHANGELOG.md](CHANGELOG.md)
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
[CONTRIBUTING.md](CONTRIBUTING.md)
|
76
|
+
|
77
|
+
## Contributors
|
78
|
+
|
79
|
+
* [Andy Maleh](https://github.com/AndyObtiva) (Founder)
|
80
|
+
|
81
|
+
[Click here to view contributor commits.](https://github.com/AndyObtiva/glimmer-web-components/graphs/contributors)
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
[MIT](https://opensource.org/licenses/MIT)
|
86
|
+
|
87
|
+
Copyright (c) 2025 - Andy Maleh.
|
88
|
+
See [LICENSE.txt](LICENSE.txt) for further details.
|
89
|
+
|
90
|
+
--
|
91
|
+
|
92
|
+
[<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=40 />](https://github.com/AndyObtiva/glimmer) Built for [Glimmer](https://github.com/AndyObtiva/glimmer) (DSL Framework).
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Generated by juwelier
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: glimmer-web-components 0.1.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "glimmer-web-components".freeze
|
9
|
+
s.version = "0.1.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib".freeze]
|
13
|
+
s.authors = ["Andy Maleh".freeze]
|
14
|
+
s.date = "2025-03-10"
|
15
|
+
s.description = "This is a collection of reusable Glimmer Web Components for Glimmer DSL for Web, extracted from real Rails web applications.".freeze
|
16
|
+
s.email = "andy.am@gmail.com".freeze
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"CHANGELOG.md",
|
19
|
+
"LICENSE.txt",
|
20
|
+
"README.md"
|
21
|
+
]
|
22
|
+
s.files = [
|
23
|
+
"CHANGELOG.md",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.md",
|
26
|
+
"VERSION",
|
27
|
+
"glimmer-web-components.gemspec",
|
28
|
+
"lib/glimmer-web-components.rb",
|
29
|
+
"lib/glimmer/web/component/multi_checkbox_dropdown.rb"
|
30
|
+
]
|
31
|
+
s.homepage = "https://github.com/AndyObtiva/glimmer-dsl-web".freeze
|
32
|
+
s.licenses = ["MIT".freeze]
|
33
|
+
s.rubygems_version = "3.3.26".freeze
|
34
|
+
s.summary = "Glimmer Web Components".freeze
|
35
|
+
|
36
|
+
if s.respond_to? :specification_version then
|
37
|
+
s.specification_version = 4
|
38
|
+
end
|
39
|
+
|
40
|
+
if s.respond_to? :add_runtime_dependency then
|
41
|
+
s.add_runtime_dependency(%q<glimmer-dsl-web>.freeze, [">= 0.6.0"])
|
42
|
+
s.add_development_dependency(%q<minitest>.freeze, [">= 0"])
|
43
|
+
s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
44
|
+
s.add_development_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
|
45
|
+
s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<glimmer-dsl-web>.freeze, [">= 0.6.0"])
|
48
|
+
s.add_dependency(%q<minitest>.freeze, [">= 0"])
|
49
|
+
s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
|
50
|
+
s.add_dependency(%q<juwelier>.freeze, ["~> 2.1.0"])
|
51
|
+
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,272 @@
|
|
1
|
+
require 'glimmer-dsl-web'
|
2
|
+
|
3
|
+
require 'facets/hash/deep_merge'
|
4
|
+
|
5
|
+
module Glimmer
|
6
|
+
module Web
|
7
|
+
module Component
|
8
|
+
class MultiCheckboxDropdown
|
9
|
+
include Glimmer::Web::Component
|
10
|
+
|
11
|
+
TRANSLATIONS_DEFAULT = {
|
12
|
+
en: {
|
13
|
+
select: 'Select',
|
14
|
+
items_selected: 'items selected',
|
15
|
+
},
|
16
|
+
fr: {
|
17
|
+
select: 'Sélectionnez',
|
18
|
+
items_selected: 'articles sélectionnés',
|
19
|
+
},
|
20
|
+
es: {
|
21
|
+
select: 'Seleccione',
|
22
|
+
items_selected: 'artículos seleccionados',
|
23
|
+
},
|
24
|
+
}
|
25
|
+
|
26
|
+
SELECTED_VALUES_FORMATTER_DEFAULT = ->(multi_checkbox_dropdown) {
|
27
|
+
selected_value_count = multi_checkbox_dropdown.selected_values&.size.to_i
|
28
|
+
case selected_value_count
|
29
|
+
when 0
|
30
|
+
multi_checkbox_dropdown.locale_translations[:select]
|
31
|
+
when 1, 2
|
32
|
+
multi_checkbox_dropdown.selected_display_values.join(', ')
|
33
|
+
else
|
34
|
+
items_selected_translation = multi_checkbox_dropdown.locale_translations[:items_selected]
|
35
|
+
"#{selected_value_count} #{items_selected_translation}"
|
36
|
+
end
|
37
|
+
}
|
38
|
+
|
39
|
+
REGEXP_LOCALE_COUNTRY = /-|_/
|
40
|
+
|
41
|
+
CSS_CLASS_CONTENT_HIDDEN = "#{MultiCheckboxDropdown.component_element_class}-content-hidden"
|
42
|
+
CSS_CLASS_CONTENT_UL = "#{MultiCheckboxDropdown.component_element_class}-ul"
|
43
|
+
|
44
|
+
option :values, default: []
|
45
|
+
option :display_values
|
46
|
+
option :selected_values, default: []
|
47
|
+
option :locale, default: :en
|
48
|
+
option :translations, default: {}
|
49
|
+
option :selected_values_formatter, default: SELECTED_VALUES_FORMATTER_DEFAULT
|
50
|
+
option :width, default: 175
|
51
|
+
option :height, default: 40
|
52
|
+
option :margin, default: '0 15px 0 0'
|
53
|
+
option :text_align, default: :center
|
54
|
+
option :content_z_index, default: '1000'
|
55
|
+
option :content_label_padding_px, default: 10
|
56
|
+
option :content_background, default: :white
|
57
|
+
option :content_checkbox_size, default: 20
|
58
|
+
option :content_checkbox_option_hover_color, default: 'rgb(245, 245, 245)'
|
59
|
+
option :content_label_font_size, default: 1.rem
|
60
|
+
|
61
|
+
attr_accessor :display_content
|
62
|
+
|
63
|
+
event :change # enables consumers to hook an on_change do; end listener
|
64
|
+
|
65
|
+
before_render do
|
66
|
+
self.display_values ||= values
|
67
|
+
self.translations = TRANSLATIONS_DEFAULT.deep_merge(translations)
|
68
|
+
self.display_content = false
|
69
|
+
end
|
70
|
+
|
71
|
+
after_render do
|
72
|
+
setup_observer_so_clicking_outside_displayed_content_closes_content
|
73
|
+
end
|
74
|
+
|
75
|
+
markup {
|
76
|
+
div(style: {position: :relative}) {
|
77
|
+
multi_checkbox_select
|
78
|
+
multi_checkbox_content
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
style { # static global CSS styles shared between all instances of this component
|
83
|
+
rule(".#{CSS_CLASS_CONTENT_HIDDEN}") {
|
84
|
+
display :none
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
def locale_translations
|
89
|
+
the_translations = translations[locale.to_s.downcase.to_sym]
|
90
|
+
if the_translations.nil? && locale.to_s.match(REGEXP_LOCALE_COUNTRY)
|
91
|
+
# treat fr-CA as fr, or en-US as en
|
92
|
+
partial_locale = locale.to_s.split(REGEXP_LOCALE_COUNTRY).first.downcase.to_sym
|
93
|
+
the_translations = translations[partial_locale]
|
94
|
+
end
|
95
|
+
the_translations || {}
|
96
|
+
end
|
97
|
+
|
98
|
+
def selected_indexes
|
99
|
+
selected_values.map { |selected_value| values.index(selected_value) }
|
100
|
+
end
|
101
|
+
|
102
|
+
def selected_display_values
|
103
|
+
selected_indexes.map { |selected_index| display_values[selected_index] }
|
104
|
+
end
|
105
|
+
|
106
|
+
def display_value_for(value)
|
107
|
+
display_values[values.index(value)]
|
108
|
+
end
|
109
|
+
|
110
|
+
def toggle_content(display = nil)
|
111
|
+
new_value = display.nil? ? !self.display_content : display
|
112
|
+
self.display_content = new_value
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
def multi_checkbox_select
|
118
|
+
@multi_checkbox_select = select(style: {height:, width:, margin:, text_align:}) {
|
119
|
+
content(self, :selected_values) { # re-renders automatically upon change to self.selected_values
|
120
|
+
placeholder_option_text = formatted_selected_values
|
121
|
+
option(value: placeholder_option_text) {
|
122
|
+
placeholder_option_text
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
onkeydown do |event|
|
127
|
+
case event.key_code
|
128
|
+
when 40 # down
|
129
|
+
event.prevent_default
|
130
|
+
self.display_content = true if !self.display_content
|
131
|
+
when 32 # space
|
132
|
+
event.prevent_default
|
133
|
+
toggle_content
|
134
|
+
when 27 # escape
|
135
|
+
event.prevent_default
|
136
|
+
self.display_content = false
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
onmousedown do |event|
|
141
|
+
event.prevent_default
|
142
|
+
toggle_content
|
143
|
+
end
|
144
|
+
}
|
145
|
+
end
|
146
|
+
|
147
|
+
def formatted_selected_values
|
148
|
+
selected_values_formatter.call(self)
|
149
|
+
end
|
150
|
+
|
151
|
+
def multi_checkbox_content
|
152
|
+
@multi_checkbox_content = div(style: {position: :absolute, z_index: content_z_index, width:, background: content_background, box_shadow: '0 6px 12px rgba(0, 0, 0, 0.175)'}) {
|
153
|
+
class_name(CSS_CLASS_CONTENT_HIDDEN) <= [self, :display_content, on_read: :!]
|
154
|
+
|
155
|
+
content(self, :selected_values) { # re-renders automatically upon change to self.selected_values
|
156
|
+
ul(class: CSS_CLASS_CONTENT_UL, style: {list_style_type: :none, padding_top: 10, padding_left: 0}) {
|
157
|
+
style { # dynamic CSS styles per component instance, so created before being used in li elements below
|
158
|
+
rule("ul.#{CSS_CLASS_CONTENT_UL} li:hover") {
|
159
|
+
background content_checkbox_option_hover_color
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
action_bar_li
|
164
|
+
|
165
|
+
values.each do |value|
|
166
|
+
value_checkbox_li(value)
|
167
|
+
end
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
end
|
172
|
+
|
173
|
+
def action_bar_li
|
174
|
+
are_all_values_selected = (values & selected_values) == values
|
175
|
+
|
176
|
+
li(class: "#{MultiCheckboxDropdown.component_element_class}-li-select-all-values",
|
177
|
+
style: {background: content_checkbox_option_hover_color, padding: '10px 0'}) {
|
178
|
+
button(type: 'button', class: 'p-multiselect-close p-link',
|
179
|
+
style: {float: :right, margin_top: -5, margin_right: 10},
|
180
|
+
'aria-label': 'Close', 'data-pc-section': 'closebutton') {
|
181
|
+
close_x_icon_svg
|
182
|
+
|
183
|
+
onclick do
|
184
|
+
self.display_content = false
|
185
|
+
end
|
186
|
+
}
|
187
|
+
|
188
|
+
input(type: 'checkbox', value: are_all_values_selected,
|
189
|
+
style: {width: content_checkbox_size, height: content_checkbox_size,
|
190
|
+
display: :block, vertical_align: :middle,
|
191
|
+
margin_left: content_label_padding_px*2}) { |input_object|
|
192
|
+
checked are_all_values_selected
|
193
|
+
|
194
|
+
onchange do |event|
|
195
|
+
if are_all_values_selected
|
196
|
+
self.selected_values = []
|
197
|
+
else
|
198
|
+
self.selected_values = values.dup
|
199
|
+
end
|
200
|
+
notify_listeners(:change, selected_values)
|
201
|
+
end
|
202
|
+
}
|
203
|
+
}
|
204
|
+
end
|
205
|
+
|
206
|
+
def close_x_icon_svg
|
207
|
+
svg(width: '14', height: '14', viewbox: '0 0 14 14', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', class: 'p-icon p-multiselect-close-icon', 'aria-hidden': 'true', 'data-pc-section': 'closeicon') {
|
208
|
+
path(d: 'M8.01186 7.00933L12.27 2.75116C12.341 2.68501 12.398 2.60524 12.4375 2.51661C12.4769 2.42798 12.4982 2.3323 12.4999 2.23529C12.5016 2.13827 12.4838 2.0419 12.4474 1.95194C12.4111 1.86197 12.357 1.78024 12.2884 1.71163C12.2198 1.64302 12.138 1.58893 12.0481 1.55259C11.9581 1.51625 11.8617 1.4984 11.7647 1.50011C11.6677 1.50182 11.572 1.52306 11.4834 1.56255C11.3948 1.60204 11.315 1.65898 11.2488 1.72997L6.99067 5.98814L2.7325 1.72997C2.59553 1.60234 2.41437 1.53286 2.22718 1.53616C2.03999 1.53946 1.8614 1.61529 1.72901 1.74767C1.59663 1.88006 1.5208 2.05865 1.5175 2.24584C1.5142 2.43303 1.58368 2.61419 1.71131 2.75116L5.96948 7.00933L1.71131 11.2675C1.576 11.403 1.5 11.5866 1.5 11.7781C1.5 11.9696 1.576 12.1532 1.71131 12.2887C1.84679 12.424 2.03043 12.5 2.2219 12.5C2.41338 12.5 2.59702 12.424 2.7325 12.2887L6.99067 8.03052L11.2488 12.2887C11.3843 12.424 11.568 12.5 11.7594 12.5C11.9509 12.5 12.1346 12.424 12.27 12.2887C12.4053 12.1532 12.4813 11.9696 12.4813 11.7781C12.4813 11.5866 12.4053 11.403 12.27 11.2675L8.01186 7.00933Z', fill: 'currentColor')
|
209
|
+
}
|
210
|
+
end
|
211
|
+
|
212
|
+
def value_checkbox_li(value)
|
213
|
+
is_value_selected = selected_values.include?(value)
|
214
|
+
li_class = is_value_selected ? :selected : ''
|
215
|
+
|
216
|
+
li(class: li_class) {
|
217
|
+
input_id = "#{MultiCheckboxDropdown.component_element_class}-#{object_id}-input-#{value}"
|
218
|
+
|
219
|
+
input(type: 'checkbox', id: input_id, value: is_value_selected,
|
220
|
+
style: {width: content_checkbox_size, height: content_checkbox_size,
|
221
|
+
display: :block, vertical_align: :middle, float: :left,
|
222
|
+
margin: content_label_padding_px, margin_left: content_label_padding_px*2}) { |input_object|
|
223
|
+
checked is_value_selected
|
224
|
+
|
225
|
+
onchange do |event|
|
226
|
+
selected_value_changed(value, input_object.checked)
|
227
|
+
end
|
228
|
+
}
|
229
|
+
|
230
|
+
label(for: input_id, style: {padding: content_label_padding_px, font_size: content_label_font_size,
|
231
|
+
display: :block, vertical_align: :middle, width: 100.%}) {
|
232
|
+
display_value_for(value)
|
233
|
+
}
|
234
|
+
}
|
235
|
+
end
|
236
|
+
|
237
|
+
def selected_value_changed(value, selected)
|
238
|
+
new_selected_values = selected_values.dup
|
239
|
+
if selected
|
240
|
+
new_selected_values << value
|
241
|
+
else
|
242
|
+
new_selected_values.delete(value)
|
243
|
+
end
|
244
|
+
new_selected_values.sort_by! { |value| values.index(value) }
|
245
|
+
self.selected_values = new_selected_values
|
246
|
+
notify_listeners(:change, selected_values)
|
247
|
+
end
|
248
|
+
|
249
|
+
def setup_observer_so_clicking_outside_displayed_content_closes_content
|
250
|
+
Element['body'].on('click') do |event|
|
251
|
+
x = event.page_x || event.touch_x
|
252
|
+
y = event.page_y || event.touch_y
|
253
|
+
if display_content && location_outside_element?(x, y, @multi_checkbox_select) && location_outside_element?(x, y, @multi_checkbox_content)
|
254
|
+
event.prevent_default
|
255
|
+
self.display_content = false
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def location_inside_element?(x, y, element)
|
261
|
+
element_bounding_box = element.get_bounding_client_rect
|
262
|
+
x.between?(element_bounding_box.left, element_bounding_box.left + element_bounding_box.width) &&
|
263
|
+
y.between?(element_bounding_box.top, element_bounding_box.top + element_bounding_box.height)
|
264
|
+
end
|
265
|
+
|
266
|
+
def location_outside_element?(x, y, element)
|
267
|
+
!location_inside_element?(x, y, element)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'opal'
|
2
|
+
|
3
|
+
GLIMMER_WEB_COMPONENTS_ROOT = File.expand_path('../..', __FILE__)
|
4
|
+
GLIMMER_WEB_COMPONENTS_LIB = File.join(GLIMMER_WEB_COMPONENTS_ROOT, 'lib')
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(GLIMMER_WEB_COMPONENTS_LIB)
|
7
|
+
|
8
|
+
if RUBY_ENGINE == 'opal'
|
9
|
+
require 'glimmer/web/component/multi_checkbox_dropdown'
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: glimmer-web-components
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andy Maleh
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: glimmer-dsl-web
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: juwelier
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: This is a collection of reusable Glimmer Web Components for Glimmer DSL
|
84
|
+
for Web, extracted from real Rails web applications.
|
85
|
+
email: andy.am@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files:
|
89
|
+
- CHANGELOG.md
|
90
|
+
- LICENSE.txt
|
91
|
+
- README.md
|
92
|
+
files:
|
93
|
+
- CHANGELOG.md
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- VERSION
|
97
|
+
- glimmer-web-components.gemspec
|
98
|
+
- lib/glimmer-web-components.rb
|
99
|
+
- lib/glimmer/web/component/multi_checkbox_dropdown.rb
|
100
|
+
homepage: https://github.com/AndyObtiva/glimmer-dsl-web
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubygems_version: 3.3.26
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Glimmer Web Components
|
123
|
+
test_files: []
|