Class: FoxTail::ModalComponent
- Inherits:
-
BaseComponent
show all
- Includes:
- Concerns::HasStimulusController, Concerns::Identifiable
- Defined in:
- app/components/fox_tail/modal_component.rb
Defined Under Namespace
Classes: StimulusController
Instance Attribute Summary
#html_attributes
Class Method Summary
collapse
Instance Method Summary
collapse
classname_merger, #initialize, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class
Methods inherited from Base
fox_tail_config
Class Method Details
.stimulus_controller_name ⇒ Object
118
119
120
|
# File 'app/components/fox_tail/modal_component.rb', line 118
def stimulus_controller_name
:modal
end
|
.trigger_component ⇒ Object
Instance Method Details
#before_render ⇒ Object
35
36
37
38
39
40
41
42
43
|
# File 'app/components/fox_tail/modal_component.rb', line 35
def before_render
super
generate_unique_id
html_attributes[:class] = root_classes
html_attributes[:tabindex] = -1
html_attributes[:aria] ||= {}
html_attributes[:aria][:hidden] = true
end
|
#call ⇒ Object
45
46
47
48
49
50
|
# File 'app/components/fox_tail/modal_component.rb', line 45
def call
capture do
concat trigger if trigger?
concat render_modal
end
end
|
#close_action(event: :click) ⇒ Object
23
24
25
|
# File 'app/components/fox_tail/modal_component.rb', line 23
def close_action(event: :click)
stimulus_controller.action :hide, event: event
end
|
79
80
81
82
|
# File 'app/components/fox_tail/modal_component.rb', line 79
def close_button_component(options = {})
options = merge_close_action options
FoxTail::ButtonComponent.new options
end
|
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'app/components/fox_tail/modal_component.rb', line 62
def close_icon_button_component(icon_or_options = {}, options = {})
if icon_or_options.is_a? Hash
options = icon_or_options
icon_or_options = "x-mark"
end
options = merge_close_action options
options[:variant] = :modal
options[:color] = :modal
options[:size] = :modal
options[:theme] = theme.theme :close_icon_button
component = FoxTail::IconButtonComponent.new options
component.with_icon icon_or_options if icon_or_options.present?
component
end
|
#merge_close_action(attributes, event: :click) ⇒ Object
27
28
29
30
31
32
33
|
# File 'app/components/fox_tail/modal_component.rb', line 27
def merge_close_action(attributes, event: :click)
return attributes unless use_stimulus?
attributes[:data] ||= {}
attributes[:data][:action] = stimulus_merger.merge_actions attributes[:data][:action], close_action(event: event)
attributes
end
|
#stimulus_controller_options ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'app/components/fox_tail/modal_component.rb', line 52
def stimulus_controller_options
{
static: static?,
closeable: closeable?,
open: open?,
visible_classes: visible_classes,
hidden_classes: hidden_classes
}
end
|
#tag_id ⇒ Object
18
19
20
21
|
# File 'app/components/fox_tail/modal_component.rb', line 18
def tag_id
FoxTail.deprecator.deprecation_warning :tag_id, "use `id` instead"
id
end
|