Class: Yattho::Beta::BorderBox

Inherits:
Component
  • Object
show all
Defined in:
app/components/yattho/beta/border_box.rb,
app/components/yattho/beta/border_box/header.rb

Overview

‘BorderBox` is a Box component with a border.

Defined Under Namespace

Classes: Header

Constant Summary collapse

DEFAULT_PADDING =
:default
PADDING_MAPPINGS =
{
  DEFAULT_PADDING => "",
  :condensed => "Box--condensed",
  :spacious => "Box--spacious"
}.freeze
PADDING_SUGGESTION =
"Perhaps you could consider using :padding options of #{PADDING_MAPPINGS.keys.to_sentence}?"
DEFAULT_ROW_SCHEME =
:default
ROW_SCHEME_MAPPINGS =
{
  DEFAULT_ROW_SCHEME => "",
  :neutral => "Box-row--gray",
  :info => "Box-row--blue",
  :warning => "Box-row--yellow"
}.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(padding: DEFAULT_PADDING, **system_arguments) ⇒ BorderBox

Returns a new instance of BorderBox.

Examples:

Header with title, body, rows, and footer

<%= render(Yattho::Beta::BorderBox.new) do |component| %>
  <% component.with_header do |h| %>
    <% h.title(tag: :h2) do %>
      Header
    <% end %>
  <% end %>
  <% component.with_body do %>
    Body
  <% end %>
  <% component.with_row do %>
    <% if true %>
      Row one
    <% end %>
  <% end %>
  <% component.with_row do %>
    Row two
  <% end %>
  <% component.with_footer do %>
    Footer
  <% end %>
<% end %>

Padding density

<%= render(Yattho::Beta::BorderBox.new(padding: :condensed)) do |component| %>
  <% component.with_header do %>
    Header
  <% end %>
  <% component.with_body do %>
    Body
  <% end %>
  <% component.with_row do %>
    Row two
  <% end %>
  <% component.with_footer do %>
    Footer
  <% end %>
<% end %>

Row colors

<%= render(Yattho::Beta::BorderBox.new) do |component| %>
  <% component.with_row do %>
    Default
  <% end %>
  <% component.with_row(scheme: :neutral) do %>
    Neutral
  <% end %>
  <% component.with_row(scheme: :info) do %>
    Info
  <% end %>
  <% component.with_row(scheme: :warning) do %>
    Warning
  <% end %>
<% end %>

Parameters:

  • padding (Symbol) (defaults to: DEFAULT_PADDING)

    <%= one_of(Yattho::Beta::BorderBox::PADDING_MAPPINGS.keys) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



130
131
132
133
134
135
136
137
138
139
140
# File 'app/components/yattho/beta/border_box.rb', line 130

def initialize(padding: DEFAULT_PADDING, **system_arguments)
  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = :div
  @system_arguments[:classes] = class_names(
    "Box",
    PADDING_MAPPINGS[fetch_or_fallback(PADDING_MAPPINGS.keys, padding, DEFAULT_PADDING)],
    system_arguments[:classes]
  )

  @system_arguments[:system_arguments_denylist] = { [:p, :pt, :pb, :pr, :pl] => PADDING_SUGGESTION }
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'app/components/yattho/beta/border_box.rb', line 142

def render?
  rows.any? || header.present? || body.present? || footer.present?
end