Class: Primer::LayoutComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/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::STATUSES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

status

Methods included from ViewHelper

#primer

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean

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(Primer::LayoutComponent.new) do |component| %>
  <% component.with(:sidebar) { "Sidebar" } %>
  <% component.with(:main) { "Main" } %>
<% end %>

Left sidebar

<%= render(Primer::LayoutComponent.new(side: :left)) do |component| %>
  <% component.with(:sidebar) { "Sidebar" } %>
  <% component.with(:main) { "Main" } %>
<% end %>


31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/components/primer/layout_component.rb', line 31

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

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