Class: Railsboot::Dropdown::ActionComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/railsboot/dropdown/action_component.rb

Overview

ViewComponent: renders the action block.

Constant Summary collapse

TYPES =

Types.

%w[button link].freeze
DEFAULT_TYPE =

Default type.

"button".freeze

Instance Method Summary collapse

Constructor Details

#initialize(text: "", type: DEFAULT_TYPE, variant: Railsboot::ButtonComponent::DEFAULT_VARIANT, **html_attributes) ⇒ ActionComponent

Returns a new instance of ActionComponent.

Parameters:

  • text (String) (defaults to: "")

    the text option

  • type (String) (defaults to: DEFAULT_TYPE)

    the type option

  • variant (String) (defaults to: Railsboot::ButtonComponent::DEFAULT_VARIANT)

    the variant option

  • html_attributes (Hash)

    additional HTML attributes applied to the rendered element

Options Hash (**html_attributes):

  • :class (String)

    additional CSS classes, merged with the component's own classes



14
15
16
17
18
19
20
21
22
23
24
# File 'app/components/railsboot/dropdown/action_component.rb', line 14

def initialize(text: "", type: DEFAULT_TYPE, variant: Railsboot::ButtonComponent::DEFAULT_VARIANT, **html_attributes)
  @text = text
  @variant = variant
  @type = fetch_or_raise(type, TYPES)
  @html_attributes = html_attributes

  @html_attributes[:class] = class_names(
    "dropdown-toggle",
    html_attributes.delete(:class)
  )
end

Instance Method Details

#button?Boolean

Whether the action renders as a button.

Returns:

  • (Boolean)


28
29
30
# File 'app/components/railsboot/dropdown/action_component.rb', line 28

def button?
  @type == "button"
end

#link?Boolean

Whether the action renders as a link.

Returns:

  • (Boolean)


34
35
36
# File 'app/components/railsboot/dropdown/action_component.rb', line 34

def link?
  @type == "link"
end