Class: SdrViewComponents::Elements::IconButtonFormComponent
- Inherits:
-
BaseComponent
- Object
- ViewComponent::Base
- BaseComponent
- SdrViewComponents::Elements::IconButtonFormComponent
- Defined in:
- app/components/sdr_view_components/elements/icon_button_form_component.rb
Overview
Component for a button which is an icon and is wrapped in a form
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #before_render ⇒ Object
- #button_icon ⇒ Object
- #call ⇒ Object
- #classes ⇒ Object
- #data ⇒ Object
-
#initialize(link:, icon:, label:, variant: :'outline-primary', classes: [], icon_classes: [], method: :get, confirm: nil, top: true, data: {}, disabled: false, params: {}) ⇒ IconButtonFormComponent
constructor
rubocop:disable Metrics/ParameterLists, Metrics/MethodLength.
Methods inherited from BaseComponent
#args_for, #mark_label_required, #merge_actions, #merge_classes
Constructor Details
#initialize(link:, icon:, label:, variant: :'outline-primary', classes: [], icon_classes: [], method: :get, confirm: nil, top: true, data: {}, disabled: false, params: {}) ⇒ IconButtonFormComponent
rubocop:disable Metrics/ParameterLists, Metrics/MethodLength
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/components/sdr_view_components/elements/icon_button_form_component.rb', line 7 def initialize(link:, icon:, label:, variant: :'outline-primary', classes: [], icon_classes: [], method: :get, # rubocop:disable Metrics/ParameterLists, Metrics/MethodLength confirm: nil, top: true, data: {}, disabled: false, params: {}) @link = link @icon = icon @label = label @variant = variant @classes = classes @icon_classes = icon_classes @method = method @confirm = confirm @top = top @data = data @disabled = disabled @params = params super() end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
28 29 30 |
# File 'app/components/sdr_view_components/elements/icon_button_form_component.rb', line 28 def label @label end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
28 29 30 |
# File 'app/components/sdr_view_components/elements/icon_button_form_component.rb', line 28 def link @link end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
28 29 30 |
# File 'app/components/sdr_view_components/elements/icon_button_form_component.rb', line 28 def params @params end |
Instance Method Details
#before_render ⇒ Object
24 25 26 |
# File 'app/components/sdr_view_components/elements/icon_button_form_component.rb', line 24 def before_render raise SdrViewComponents::Error::UnknownComponentIcon, "Unknown icon type: #{@icon}" unless end |
#button_icon ⇒ Object
51 52 53 |
# File 'app/components/sdr_view_components/elements/icon_button_form_component.rb', line 51 def helpers.public_send(:"#{@icon}_icon", classes: @icon_classes) end |
#call ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/components/sdr_view_components/elements/icon_button_form_component.rb', line 30 def call (link, method: @method, class: ComponentSupport::ButtonSupport.classes(variant: @variant, classes:, disabled: @disabled), form: { data: }, params:) do concat concat tag.span(label, class: 'visually-hidden') end end |
#classes ⇒ Object
40 41 42 |
# File 'app/components/sdr_view_components/elements/icon_button_form_component.rb', line 40 def classes merge_classes(%w[icon-button border border-0], @classes) end |
#data ⇒ Object
44 45 46 47 48 49 |
# File 'app/components/sdr_view_components/elements/icon_button_form_component.rb', line 44 def data @data.tap do |data| data[:turbo_frame] = '_top' if @top data[:turbo_confirm] = @confirm if @confirm end end |