Class: Railsboot::CalloutComponent

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

Overview

ViewComponent: renders the callout block.

Constant Summary collapse

VARIANTS =

Variants.

["", "warning", "info", "danger"].freeze
DEFAULT_VARIANT =

Default variant.

"".freeze

Instance Method Summary collapse

Constructor Details

#initialize(variant: DEFAULT_VARIANT, **html_attributes) ⇒ CalloutComponent

Returns a new instance of CalloutComponent.

Parameters:

  • variant (String) (defaults to: 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



12
13
14
15
16
17
18
19
20
21
# File 'app/components/railsboot/callout_component.rb', line 12

def initialize(variant: DEFAULT_VARIANT, **html_attributes)
  @variant = fetch_or_fallback(variant, VARIANTS, DEFAULT_VARIANT)
  @html_attributes = html_attributes

  @html_attributes[:class] = class_names(
    "callout",
    { "callout-#{@variant}" => @variant.present? },
    html_attributes.delete(:class)
  )
end

Instance Method Details

#render?Boolean

Whether the component should render.

Returns:

  • (Boolean)

    true when content is present



25
26
27
# File 'app/components/railsboot/callout_component.rb', line 25

def render?
  content.present?
end