Class: Yattho::LayoutComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/yattho/layout_component.rb

Overview

Use ‘Layout` to build a main/sidebar layout.

Constant Summary collapse

DEFAULT_SIDE =
:right
ALLOWED_SIDES =
[DEFAULT_SIDE, :left].freeze
MAX_COL =
12
DEFAULT_SIDEBAR_COL =
3
ALLOWED_SIDEBAR_COLS =
(1..(MAX_COL - 1)).to_a.freeze

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(responsive: false, side: DEFAULT_SIDE, sidebar_col: DEFAULT_SIDEBAR_COL, **system_arguments) ⇒ LayoutComponent

Returns a new instance of LayoutComponent.

Examples:

Default

<%= render(Yattho::LayoutComponent.new) do |component| %>
  <% component.with_sidebar { "Sidebar" } %>
  <% component.with_main { "Main" } %>
<% end %>

Left sidebar

<%= render(Yattho::LayoutComponent.new(side: :left)) do |component| %>
  <% component.with_sidebar { "Sidebar" } %>
  <% component.with_main { "Main" } %>
<% end %>

Parameters:

  • responsive (Boolean) (defaults to: false)

    Whether to collapse layout to a single column at smaller widths.

  • side (Symbol) (defaults to: DEFAULT_SIDE)

    Which side to display the sidebar on. <%= one_of(Yattho::LayoutComponent::ALLOWED_SIDES) %>

  • sidebar_col (Integer) (defaults to: DEFAULT_SIDEBAR_COL)

    Sidebar column width.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/components/yattho/layout_component.rb', line 55

def initialize(responsive: false, side: DEFAULT_SIDE, sidebar_col: DEFAULT_SIDEBAR_COL, **system_arguments)
  @system_arguments = system_arguments
  @side = fetch_or_fallback(ALLOWED_SIDES, side, DEFAULT_SIDE)
  @responsive = responsive
  @system_arguments[:classes] = class_names(
    "gutter-condensed gutter-lg",
    @system_arguments[:classes]
  )
  @system_arguments[:direction] = responsive ? [:column, nil, :row] : nil
  @system_arguments[:display] = :flex
  @system_arguments[:tag] = :div

  @sidebar_col = fetch_or_fallback(ALLOWED_SIDEBAR_COLS, sidebar_col, DEFAULT_SIDEBAR_COL)
  @main_col = MAX_COL - @sidebar_col
end