Class: Yattho::Beta::Flash

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

Overview

Use ‘Flash` to inform users of successful or pending actions.

Constant Summary collapse

DEFAULT_SCHEME =
:default
SCHEME_MAPPINGS =
{
  DEFAULT_SCHEME => "",
  :warning => "flash-warn",
  :danger => "flash-error",
  :success => "flash-success"
}.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(full: false, spacious: false, dismissible: false, icon: nil, scheme: DEFAULT_SCHEME, **system_arguments) ⇒ Flash

Returns a new instance of Flash.

Examples:

Schemes

<%= render(Yattho::Beta::Flash.new) { "This is a flash message!" } %>
<%= render(Yattho::Beta::Flash.new(scheme: :warning)) { "This is a warning flash message!" } %>
<%= render(Yattho::Beta::Flash.new(scheme: :danger)) { "This is a danger flash message!" } %>
<%= render(Yattho::Beta::Flash.new(scheme: :success)) { "This is a success flash message!" } %>

Full width

<%= render(Yattho::Beta::Flash.new(full: true)) { "This is a full width flash message!" } %>

Dismissible

<%= render(Yattho::Beta::Flash.new(dismissible: true)) { "This is a dismissible flash message!" } %>

Icon

<%= render(Yattho::Beta::Flash.new(icon: :people)) { "This is a flash message with an icon!" } %>

With actions

<%= render(Yattho::Beta::Flash.new) do |component| %>
  This is a flash message with actions!
  <% component.with_action do %>
    <%= render(Yattho::ButtonComponent.new(size: :small)) { "Take action" } %>
  <% end %>
<% end %>

Parameters:

  • full (Boolean) (defaults to: false)

    Whether the component should take up the full width of the screen.

  • spacious (Boolean) (defaults to: false)

    Whether to add margin to the bottom of the component.

  • dismissible (Boolean) (defaults to: false)

    Whether the component can be dismissed with an X button.

  • icon (Symbol) (defaults to: nil)

    Name of Octicon icon to use.

  • scheme (Symbol) (defaults to: DEFAULT_SCHEME)

    <%= one_of(Yattho::Beta::Flash::SCHEME_MAPPINGS.keys) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



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

def initialize(full: false, spacious: false, dismissible: false, icon: nil, scheme: DEFAULT_SCHEME,
               **system_arguments)
  @icon = icon
  @dismissible = dismissible
  @system_arguments = deny_tag_argument(**system_arguments)
  @system_arguments[:tag] = :div
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "flash",
    SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_MAPPINGS.keys, scheme, DEFAULT_SCHEME)],
    'flash-full': full
  )
  @system_arguments[:mb] ||= spacious ? 4 : nil
end