Class: Components::BaseButton
- Inherits:
-
Base
- Object
- Base
- Components::BaseButton
- Includes:
- Phlex::Rails::Helpers::ButtonTo
- Defined in:
- app/components/base_button.rb
Direct Known Subclasses
Instance Method Summary collapse
- #helper(*args) ⇒ Object
-
#initialize(label:, href:, variant:, icon: nil, method: nil, icon_only: false, aria_label: nil, confirm: nil, data: {}, nofollow: nil, target: nil, small: false, help: nil) ⇒ BaseButton
constructor
A new instance of BaseButton.
- #view_template ⇒ Object
Constructor Details
#initialize(label:, href:, variant:, icon: nil, method: nil, icon_only: false, aria_label: nil, confirm: nil, data: {}, nofollow: nil, target: nil, small: false, help: nil) ⇒ BaseButton
Returns a new instance of BaseButton.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/components/base_button.rb', line 6 def initialize(label:, href:, variant:, icon: nil, method: nil, icon_only: false, aria_label: nil, confirm: nil, data: {}, nofollow: nil, target: nil, small: false, help: nil) @icon = icon @label = label @href = href @variant = variant @method = method @icon_only = icon_only @aria_label = aria_label @confirm = confirm @data = data @nofollow = nofollow @target = target @small = small @help = help end |
Instance Method Details
#helper(*args) ⇒ Object
32 33 34 |
# File 'app/components/base_button.rb', line 32 def helper(*args) raise NotImplementedError end |
#view_template ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'app/components/base_button.rb', line 22 def view_template helper(@href, method: @method, class: "btn#{" btn-sm" if @small} btn-#{@variant}", rel: (@nofollow ? "nofollow" : nil), title: @help, aria: {label: @aria_label || (@icon_only ? @label : nil)}, data: {confirm: @confirm}.merge(@data), target: @target) do if @icon Icon(icon: @icon, label: @help || @label) whitespace end span(class: @icon_only ? "visually-hidden" : nil) { @label } end end |