reflex_behaviors 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +23 -19
- data/app/assets/builds/reflex_behaviors.js +35 -13
- data/app/assets/builds/reflex_behaviors.js.map +3 -3
- data/app/helpers/reflex_behaviors/application_helper.rb +1 -19
- data/app/javascript/devtools/elements/tooltip_element.js +16 -4
- data/app/javascript/devtools/toggle.js +67 -51
- data/app/javascript/elements/reflex_element.js +3 -3
- data/app/javascript/elements/toggle_target_element.js +81 -1
- data/app/javascript/elements/toggle_trigger_element.js +72 -51
- data/app/reflexes/reflex_behaviors/application_reflex.rb +16 -9
- data/app/reflexes/reflex_behaviors/toggle_reflex.rb +3 -3
- data/lib/reflex_behaviors/engine.rb +1 -0
- data/lib/reflex_behaviors/tag_builders/base_tag_builder.rb +15 -0
- data/lib/reflex_behaviors/tag_builders/toggle_tags_builder.rb +57 -20
- data/lib/reflex_behaviors/version.rb +1 -1
- data/package.json +1 -1
- data/tags +854 -809
- data/yarn.lock +140 -140
- metadata +2 -2
@@ -4,18 +4,18 @@ class ReflexBehaviors::ToggleReflex < ReflexBehaviors::ApplicationReflex
|
|
4
4
|
prevent_controller_action
|
5
5
|
|
6
6
|
def show
|
7
|
-
if element.
|
7
|
+
if element.remember == "true"
|
8
8
|
state[element.aria.controls] = true
|
9
9
|
else
|
10
10
|
state.now[element.aria.controls] = true
|
11
11
|
end
|
12
12
|
|
13
|
-
morph "##{
|
13
|
+
morph "##{element.morphs}", render(render_payload)
|
14
14
|
end
|
15
15
|
|
16
16
|
def hide
|
17
17
|
state[element.aria.controls] = false
|
18
|
-
morph "##{
|
18
|
+
morph "##{element.morphs}", render(render_payload)
|
19
19
|
end
|
20
20
|
|
21
21
|
def toggle
|
@@ -17,6 +17,21 @@ module ReflexBehaviors
|
|
17
17
|
memo << location.path[(location.path.index(prefix) + prefix.length)..]
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def dehydrate_value(value)
|
24
|
+
return value.to_s unless value.respond_to?(:to_sgid_param)
|
25
|
+
value.try(:persisted?) ? value.to_sgid_param : nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def dehydrate_hash(hash)
|
29
|
+
hash
|
30
|
+
.with_indifferent_access
|
31
|
+
.each_with_object({}.with_indifferent_access) do |(key, val), memo|
|
32
|
+
memo[key] = dehydrate_value(val)
|
33
|
+
end
|
34
|
+
end
|
20
35
|
end
|
21
36
|
end
|
22
37
|
end
|
@@ -4,50 +4,87 @@ require_relative "base_tag_builder"
|
|
4
4
|
|
5
5
|
module ReflexBehaviors::TagBuilders
|
6
6
|
class ToggleTagsBuilder < BaseTagBuilder
|
7
|
-
def trigger_tag(
|
7
|
+
def trigger_tag(
|
8
|
+
renders:, # REQUIRED - the partial path to render
|
9
|
+
morphs:, # REQUIRED - dom_id of the partial's outermost containing element
|
10
|
+
controls:, # REQUIRED - dom_id of the toggle target
|
11
|
+
assigns: {}, # assigns required to render the partial i.e. instance variables
|
12
|
+
locals: {}, # local_assigns required to render the parital
|
13
|
+
collapse_selector: nil, # CSS selector for other targets to collapse when the target is expanded
|
14
|
+
focus_selector: nil, # CSS selector for the element to focus when the target is expanded
|
15
|
+
method: :toggle, # reflex method to inovke (show, hide, toggle)
|
16
|
+
disabled: false, # disable the trigger
|
17
|
+
remember: false, # remember state between requests
|
18
|
+
**kwargs,
|
19
|
+
&block
|
20
|
+
)
|
8
21
|
kwargs = kwargs.with_indifferent_access
|
9
|
-
kwargs[:id] ||= "#{
|
22
|
+
kwargs[:id] ||= "#{controls}-toggle-trigger"
|
10
23
|
|
24
|
+
# reflex
|
25
|
+
kwargs[:data] ||= {}
|
26
|
+
kwargs[:data][:turbo_reflex] = "ReflexBehaviors::ToggleReflex##{method}" unless disabled
|
27
|
+
|
28
|
+
# target / aria
|
11
29
|
kwargs[:aria] ||= {}
|
30
|
+
kwargs[:aria][:controls] = controls
|
31
|
+
kwargs[:aria][:expanded] = target_expanded?(controls)
|
12
32
|
kwargs[:aria][:atomic] ||= true
|
13
33
|
kwargs[:aria][:relevant] ||= "all"
|
14
|
-
kwargs[:aria].merge!(controls: target, expanded: target_expanded?(target))
|
15
34
|
|
16
|
-
|
17
|
-
kwargs[:
|
18
|
-
kwargs[:
|
19
|
-
kwargs[:
|
20
|
-
kwargs[:
|
21
|
-
kwargs[:
|
35
|
+
# rendering
|
36
|
+
kwargs[:renders] = renders
|
37
|
+
kwargs[:morphs] = morphs
|
38
|
+
kwargs[:assigns] = dehydrate_hash(assigns).compact.to_json if assigns.present?
|
39
|
+
kwargs[:locals] = dehydrate_hash(locals).compact.to_json if locals.present?
|
40
|
+
kwargs[:view_stack] = view_stack.to_json if Rails.env.development?
|
22
41
|
|
23
|
-
|
42
|
+
# misc
|
43
|
+
kwargs[:collapse_selector] = collapse_selector
|
44
|
+
kwargs[:focus_selector] = focus_selector
|
45
|
+
kwargs[:remember] = !!remember
|
46
|
+
|
47
|
+
args = kwargs.select { |_, value| value.present? }
|
48
|
+
content_tag("toggle-trigger", nil, args.transform_keys(&:dasherize), &block)
|
24
49
|
end
|
25
50
|
|
26
|
-
def target_tag(
|
51
|
+
def target_tag(
|
52
|
+
id, # REQUIRED - the dom_id for the element
|
53
|
+
collapse_on: [], # list of events that trigger collapse
|
54
|
+
collapse_selector: nil, # CSS selector for other targets to collapse when this target is expanded
|
55
|
+
expanded: false, # override to force expansion
|
56
|
+
focus_selector: nil, # CSS selector for the element to focus when content is expanded
|
57
|
+
**kwargs,
|
58
|
+
&block
|
59
|
+
)
|
27
60
|
kwargs = kwargs.with_indifferent_access
|
28
61
|
kwargs[:id] = id
|
62
|
+
kwargs[:collapse_on] = collapse_on.to_json if collapse_on.present?
|
63
|
+
kwargs[:collapse_selector] = collapse_selector
|
64
|
+
kwargs[:focus_selector] = focus_selector
|
29
65
|
kwargs[:role] = "region"
|
30
66
|
|
67
|
+
# aria
|
31
68
|
kwargs[:aria] ||= {}
|
32
|
-
kwargs[:aria][:label] ||= "Dynamic Content Region"
|
33
69
|
kwargs[:aria][:live] ||= "polite"
|
34
70
|
|
35
|
-
|
36
|
-
kwargs[:
|
71
|
+
# rendering
|
72
|
+
kwargs[:view_stack] = view_stack.to_json if Rails.env.development?
|
37
73
|
|
74
|
+
args = kwargs.select { |_, value| value.present? }
|
38
75
|
if expanded || target_expanded?(id)
|
39
|
-
content_tag("toggle-target", nil,
|
76
|
+
content_tag("toggle-target", nil, args.transform_keys!(&:dasherize), &block)
|
40
77
|
else
|
41
|
-
content_tag("toggle-target", nil,
|
78
|
+
content_tag("toggle-target", nil, args.transform_keys!(&:dasherize))
|
42
79
|
end
|
43
80
|
end
|
44
81
|
|
45
|
-
def target_expanded?(
|
46
|
-
!!turbo_reflex.state[
|
82
|
+
def target_expanded?(dom_id)
|
83
|
+
!!turbo_reflex.state[dom_id]
|
47
84
|
end
|
48
85
|
|
49
|
-
def target_collapsed?(
|
50
|
-
!target_expanded?(
|
86
|
+
def target_collapsed?(dom_id)
|
87
|
+
!target_expanded?(dom_id)
|
51
88
|
end
|
52
89
|
end
|
53
90
|
end
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "reflex_behaviors",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.9",
|
4
4
|
"description": "Pre-built easy to use reactive TurboReflex behaviors for Rails/Hotwire apps.",
|
5
5
|
"main": "app/javascript/index.js",
|
6
6
|
"repository": "https://github.com/hopsoft/reflex_behaviors",
|