Class: Railsboot::ContainerComponent

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

Overview

ViewComponent: renders the container block.

Constant Summary collapse

BREAKPOINTS =

Breakpoints.

%w[sm md lg xl xxl].freeze
DEFAULT_BREAKPOINT =

Default breakpoint.

"".freeze

Instance Method Summary collapse

Constructor Details

#initialize(breakpoint: DEFAULT_BREAKPOINT, fluid: false, **html_attributes) ⇒ ContainerComponent

Returns a new instance of ContainerComponent.

Parameters:

  • breakpoint (String) (defaults to: DEFAULT_BREAKPOINT)

    Bootstrap breakpoint for a responsive container (one of BREAKPOINTS)

  • fluid (Boolean) (defaults to: false)

    whether to render a fluid container

  • 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



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

def initialize(breakpoint: DEFAULT_BREAKPOINT, fluid: false, **html_attributes)
  @breakpoint = breakpoint
  @fluid = fluid
  @html_attributes = html_attributes

  @html_attributes[:class] = class_names(
    ("container-#{breakpoint}" if @breakpoint.in?(BREAKPOINTS)),
    ("container-fluid" if @fluid),
    ("container" if @fluid.blank? && !@breakpoint.in?(BREAKPOINTS)),
    html_attributes.delete(:class)
  )
end

Instance Method Details

#callString

Renders the container wrapper around the component content.

Returns:

  • (String)

    the rendered HTML for the container element



28
29
30
31
32
# File 'app/components/railsboot/container_component.rb', line 28

def call
  render Railsboot::BaseComponent.new(tag: "div", **@html_attributes) do
    content
  end
end