Class: Bs5::ButtonToComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/components/bs5/button_to_component.rb

Constant Summary collapse

STYLES =
%i[primary secondary success danger warning info light dark link].freeze
DEFAULT_COLOR =
:primary
SIZES =
{ small: :sm, large: :lg }.freeze
CLASS_PREFIX =
'btn'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, options = nil, html_options = nil) ⇒ ButtonToComponent

Returns a new instance of ButtonToComponent.



16
17
18
19
20
21
22
23
24
# File 'app/components/bs5/button_to_component.rb', line 16

def initialize(name = nil, options = nil, html_options = nil)
  @name = name
  @options = options
  @html_options = html_options

  set_button_to_options
  extract_custom_options
  merge_default_options
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



10
11
12
# File 'app/components/bs5/button_to_component.rb', line 10

def size
  @size
end

Instance Method Details

#before_renderObject



26
27
28
# File 'app/components/bs5/button_to_component.rb', line 26

def before_render
  raise errors.full_messages.to_sentence if invalid?
end

#callObject



30
31
32
33
34
35
36
# File 'app/components/bs5/button_to_component.rb', line 30

def call
  if content
    button_to(@name, @options, @html_options) { content }
  else
    button_to(@name, @options, @html_options)
  end
end