Class: Yattho::Beta::State

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

Overview

Use ‘State` for rendering the status of an item.

Direct Known Subclasses

StateComponent

Constant Summary collapse

SCHEME_DEFAULT =
:default
NEW_SCHEME_MAPPINGS =
{
  open: "State--open",
  closed: "State--closed",
  merged: "State--merged"
}.freeze
DEPRECATED_SCHEME_MAPPINGS =
{
  SCHEME_DEFAULT => "",
  :green => "State--open",
  :red => "State--closed",
  :purple => "State--merged"
}.freeze
SCHEME_MAPPINGS =
NEW_SCHEME_MAPPINGS.merge(DEPRECATED_SCHEME_MAPPINGS)
SCHEME_OPTIONS =
SCHEME_MAPPINGS.keys
SIZE_DEFAULT =
:default
SIZE_MAPPINGS =
{
  SIZE_DEFAULT => "",
  :small => "State--small"
}.freeze
SIZE_OPTIONS =
SIZE_MAPPINGS.keys
TAG_DEFAULT =
:span
TAG_OPTIONS =
[TAG_DEFAULT, :div].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(title:, scheme: SCHEME_DEFAULT, tag: TAG_DEFAULT, size: SIZE_DEFAULT, **system_arguments) ⇒ State

Returns a new instance of State.

Examples:

Default

<%= render(Yattho::Beta::State.new(title: "title")) { "State" } %>

Schemes

<%= render(Yattho::Beta::State.new(title: "title")) { "Default" } %>
<%= render(Yattho::Beta::State.new(title: "title", scheme: :open)) { "Open" } %>
<%= render(Yattho::Beta::State.new(title: "title", scheme: :closed)) { "Closed" } %>
<%= render(Yattho::Beta::State.new(title: "title", scheme: :merged)) { "Merged" } %>

Sizes

<%= render(Yattho::Beta::State.new(title: "title")) { "Default" } %>
<%= render(Yattho::Beta::State.new(title: "title", size: :small)) { "Small" } %>

Parameters:

  • title (String)

    ‘title` HTML attribute.

  • scheme (Symbol) (defaults to: SCHEME_DEFAULT)

    Background color. <%= one_of(Yattho::Beta::State::SCHEME_OPTIONS) %>

  • tag (Symbol) (defaults to: TAG_DEFAULT)

    HTML tag for element. <%= one_of(Yattho::Beta::State::TAG_OPTIONS) %>

  • size (Symbol) (defaults to: SIZE_DEFAULT)

    <%= one_of(Yattho::Beta::State::SIZE_OPTIONS) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



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

def initialize(
  title:,
  scheme: SCHEME_DEFAULT,
  tag: TAG_DEFAULT,
  size: SIZE_DEFAULT,
  **system_arguments
)
  @system_arguments = system_arguments
  @system_arguments[:title] = title
  @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, TAG_DEFAULT)
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "State",
    SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, SCHEME_DEFAULT)],
    SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, size, SIZE_DEFAULT)]
  )
end

Instance Method Details

#callObject



71
72
73
# File 'app/components/yattho/beta/state.rb', line 71

def call
  render(Yattho::BaseComponent.new(**@system_arguments)) { content }
end