Class: ButtonComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/ButtonComponent/button_component.rb

Constant Summary collapse

PRIMARY_CLASSES =
%w[
  zenhr-primary-button
].freeze
OUTLINE_CLASSES =
%w[
  zenhr-outline-button
].freeze
DANGER_CLASSES =
%w[
  zenhr-danger-button
].freeze
BASE_CLASSES =
%w[
  cursor-pointer
  rounded
  transition
  text-center
  whitespace-nowrap
  font-weight-bold
  zenhr-button
].freeze
BUTTON_TYPE_MAPPINGS =
{
  primary: PRIMARY_CLASSES,
  danger: DANGER_CLASSES,
  outline: OUTLINE_CLASSES
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options:, classes: '') ⇒ ButtonComponent

Returns a new instance of ButtonComponent.



31
32
33
34
# File 'app/components/ButtonComponent/button_component.rb', line 31

def initialize(options:, classes: '')
  @options = options
  @classes = classes
end

Instance Attribute Details

#typeObject

Returns the value of attribute type.



4
5
6
# File 'app/components/ButtonComponent/button_component.rb', line 4

def type
  @type
end

Instance Method Details

#classesObject



36
37
38
39
40
41
42
# File 'app/components/ButtonComponent/button_component.rb', line 36

def classes
  if @options[:button_type].nil?
    @options[:button_type] = :primary
  end

  (BUTTON_TYPE_MAPPINGS[@options[:button_type]] + BASE_CLASSES).join(' ') + " #{@classes}"
end