Class: Yattho::Alpha::Layout::Main

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

Overview

The layout’s main content.

Constant Summary collapse

WIDTH_DEFAULT =
:full
WIDTH_OPTIONS =
[WIDTH_DEFAULT, :md, :lg, :xl].freeze
TAG_DEFAULT =
:div
TAG_OPTIONS =
[TAG_DEFAULT, :main].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(tag: TAG_DEFAULT, width: WIDTH_DEFAULT, **system_arguments) ⇒ Main

Returns a new instance of Main.

Parameters:

  • width (Symbol) (defaults to: WIDTH_DEFAULT)

    <%= one_of(Yattho::Alpha::Layout::Main::WIDTH_OPTIONS) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



235
236
237
238
239
240
241
242
243
244
# File 'app/components/yattho/alpha/layout.rb', line 235

def initialize(tag: TAG_DEFAULT, width: WIDTH_DEFAULT, **system_arguments)
  @width = fetch_or_fallback(WIDTH_OPTIONS, width, WIDTH_DEFAULT)

  @system_arguments = system_arguments
  @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT)
  @system_arguments[:classes] = class_names(
    "Layout-main",
    system_arguments[:classes]
  )
end

Instance Method Details

#callObject



246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'app/components/yattho/alpha/layout.rb', line 246

def call
  render(Yattho::BaseComponent.new(**@system_arguments)) do
    if @width == :full
      content
    else
      render(Yattho::BaseComponent.new(tag: :div, classes: "Layout-main-centered-#{@width}")) do
        render(Yattho::BaseComponent.new(tag: :div, container: @width)) do
          content
        end
      end
    end
  end
end