Class: Bs5::ButtonTagComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/components/bs5/button_tag_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(content_or_options = nil, options = nil) ⇒ ButtonTagComponent

Returns a new instance of ButtonTagComponent.



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

def initialize(content_or_options = nil, options = nil)
  if content_or_options.is_a? Hash
    self.options = content_or_options
  else
    @content_or_options = content_or_options
    self.options = options
  end

  extract_custom_options
  merge_default_options
end

Instance Attribute Details

#content_or_optionsObject (readonly)

Returns the value of attribute content_or_options.



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

def content_or_options
  @content_or_options
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

Instance Method Details

#before_renderObject



28
29
30
# File 'app/components/bs5/button_tag_component.rb', line 28

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

#callObject



32
33
34
# File 'app/components/bs5/button_tag_component.rb', line 32

def call
  button_tag(content || content_or_options, options)
end