Class: Railsboot::OffcanvasComponent

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

Overview

ViewComponent: renders the offcanvas block.

Constant Summary collapse

PLACEMENTS =

Placements.

%w[start end top bottom].freeze
DEFAULT_PLACEMENT =

Default placement.

"start".freeze

Instance Method Summary collapse

Constructor Details

#initialize(placement: DEFAULT_PLACEMENT, **html_attributes) ⇒ OffcanvasComponent

Returns a new instance of OffcanvasComponent.

Parameters:

  • placement (String) (defaults to: DEFAULT_PLACEMENT)

    the placement 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

  • :tag (String)

    HTML tag to render for the element



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

def initialize(placement: DEFAULT_PLACEMENT, **html_attributes)
  @placement = fetch_or_fallback(placement, PLACEMENTS, DEFAULT_PLACEMENT)
  @html_attributes = html_attributes

  @html_attributes[:tag] = "div"
  @html_attributes[:class] = class_names(
    "offcanvas",
    "offcanvas-#{@placement}",
    html_attributes.delete(:class)
  )
end