Class: Railsboot::RibbonComponent

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

Overview

ViewComponent: renders the ribbon block.

Constant Summary collapse

POSITIONS =

Positions.

%w[top-left top-right bottom-left bottom-right].freeze
DEFAULT_POSITION =

Default position.

"top-right".freeze
DEFAULT_FIXED =

Default fixed.

true

Instance Method Summary collapse

Constructor Details

#initialize(position: DEFAULT_POSITION, fixed: DEFAULT_FIXED, **html_attributes) ⇒ RibbonComponent

Returns a new instance of RibbonComponent.

Parameters:

  • position (String) (defaults to: DEFAULT_POSITION)

    ribbon position (one of POSITIONS)

  • fixed (Boolean) (defaults to: DEFAULT_FIXED)

    whether the ribbon is fixed (false renders it absolute)

  • 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



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

def initialize(position: DEFAULT_POSITION, fixed: DEFAULT_FIXED, **html_attributes)
  @position = fetch_or_raise(position, POSITIONS)
  @html_attributes = html_attributes

  @html_attributes[:class] = class_names(
    "ribbon",
    "ribbon--#{@position}",
    { "ribbon--absolute" => !fixed },
    html_attributes[:class]
  ).presence
end

Instance Method Details

#render?Boolean

Renders the ribbon only when content is present.

Returns:

  • (Boolean)

    true when the ribbon has content to render



30
31
32
# File 'app/components/railsboot/ribbon_component.rb', line 30

def render?
  content.present?
end