Class: Bulmacomp::DropdownComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Bulmacomp::DropdownComponent
- Defined in:
- app/components/bulmacomp/dropdown_component.rb
Overview
Make an html structure for a bulma dropdown
Instance Method Summary collapse
-
#call ⇒ String
Generated html string for bulma dropdown.
-
#default_button_options ⇒ Object
return [Hash] default option for button tag.
-
#default_icon ⇒ String
Default content for button icon.
-
#default_opts ⇒ Hash
Default option for content tag.
-
#initialize(title: nil, elements: [], icon: default_icon, button_options: {}, **opts) {|optional| ... } ⇒ DropdownComponent
constructor
A new instance of DropdownComponent.
-
#tag_content ⇒ String
generated html for ‘.dropdown-content’ div.
-
#tag_trigger ⇒ String
generated html for ‘.dropdown-trigger’ div.
Constructor Details
#initialize(title: nil, elements: [], icon: default_icon, button_options: {}, **opts) {|optional| ... } ⇒ DropdownComponent
Returns a new instance of DropdownComponent.
72 73 74 75 76 77 78 79 |
# File 'app/components/bulmacomp/dropdown_component.rb', line 72 def initialize(title: nil, elements: [], icon: default_icon, button_options: {}, **opts) super @title = tag.span title if title.present? @elements = elements @icon = tag.span icon, class: 'icon is-small' if icon.present? @button_options = .merge() @opts = default_opts.merge(opts) end |
Instance Method Details
#call ⇒ String
Generated html string for bulma dropdown
98 99 100 |
# File 'app/components/bulmacomp/dropdown_component.rb', line 98 def call tag.div safe_join([tag_trigger, tag_content]), **@opts end |
#default_button_options ⇒ Object
return [Hash] default option for button tag
92 93 94 |
# File 'app/components/bulmacomp/dropdown_component.rb', line 92 def { class: 'button', aria: { haspopup: 'true', controls: 'dropdown-menu' } } end |
#default_icon ⇒ String
Returns default content for button icon.
82 83 84 |
# File 'app/components/bulmacomp/dropdown_component.rb', line 82 def default_icon '<i class="fas fa-angle-down" aria-hidden="true"></i>'.html_safe end |
#default_opts ⇒ Hash
Returns default option for content tag.
87 88 89 |
# File 'app/components/bulmacomp/dropdown_component.rb', line 87 def default_opts { class: 'dropdown' } end |
#tag_content ⇒ String
generated html for ‘.dropdown-content’ div. Map each content of elements in a ‘.dropdown-item’ div and add yield content
111 112 113 |
# File 'app/components/bulmacomp/dropdown_component.rb', line 111 def tag_content tag.div safe_join([@elements.map { |e| tag.div(e, class: 'dropdown-item') }, content]), class: 'dropdown-content' end |
#tag_trigger ⇒ String
generated html for ‘.dropdown-trigger’ div
104 105 106 |
# File 'app/components/bulmacomp/dropdown_component.rb', line 104 def tag_trigger tag.div tag.(safe_join([@title, @icon]), **@button_options), class: 'dropdown-trigger' end |