Class: Yattho::Beta::AvatarStack

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

Overview

Use ‘AvatarStack` to stack multiple avatars together.

Constant Summary collapse

ALIGN_DEFAULT =
:left
ALIGN_OPTIONS =
[ALIGN_DEFAULT, :right].freeze
DEFAULT_TAG =
:div
TAG_OPTIONS =
[DEFAULT_TAG, :span].freeze
DEFAULT_BODY_TAG =
:div
BODY_TAG_OPTIONS =
[DEFAULT_BODY_TAG, :span].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: DEFAULT_TAG, align: ALIGN_DEFAULT, tooltipped: false, body_arguments: {}, **system_arguments) ⇒ AvatarStack

Returns a new instance of AvatarStack.

Examples:

Default

<%= render(Yattho::Beta::AvatarStack.new) do |component| %>
  <% component.with_avatar(src: Yattho::ExampleImage::BASE64_SRC, alt: "@kittenuser") %>
  <% component.with_avatar(src: Yattho::ExampleImage::BASE64_SRC, alt: "@kittenuser") %>
  <% component.with_avatar(src: Yattho::ExampleImage::BASE64_SRC, alt: "@kittenuser") %>
<% end  %>

Align right

<%= render(Yattho::Beta::AvatarStack.new(align: :right)) do |component| %>
  <% component.with_avatar(src: Yattho::ExampleImage::BASE64_SRC, alt: "@kittenuser") %>
  <% component.with_avatar(src: Yattho::ExampleImage::BASE64_SRC, alt: "@kittenuser") %>
  <% component.with_avatar(src: Yattho::ExampleImage::BASE64_SRC, alt: "@kittenuser") %>
<% end  %>

With tooltip

<%= render(Yattho::Beta::AvatarStack.new(tooltipped: true, body_arguments: { label: 'This is a tooltip!' })) do |component| %>
  <% component.with_avatar(src: Yattho::ExampleImage::BASE64_SRC, alt: "@kittenuser") %>
  <% component.with_avatar(src: Yattho::ExampleImage::BASE64_SRC, alt: "@kittenuser") %>
  <% component.with_avatar(src: Yattho::ExampleImage::BASE64_SRC, alt: "@kittenuser") %>
<% end  %>

Parameters:

  • tag (Symbol) (defaults to: DEFAULT_TAG)

    <%= one_of(Yattho::Beta::AvatarStack::TAG_OPTIONS) %>

  • align (Symbol) (defaults to: ALIGN_DEFAULT)

    <%= one_of(Yattho::Beta::AvatarStack::ALIGN_OPTIONS) %>

  • tooltipped (Boolean) (defaults to: false)

    Whether to add a tooltip to the stack or not.

  • body_arguments (Hash) (defaults to: {})

    Parameters to add to the Body. If ‘tooltipped` is set, has the same arguments as <%= link_to_component(Yattho::Tooltip) %>. The default tag is <%= pretty_value(Yattho::Beta::AvatarStack::DEFAULT_BODY_TAG) %> but can be changed using `tag:` to <%= one_of(Yattho::Beta::AvatarStack::BODY_TAG_OPTIONS, lower: true) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



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

def initialize(tag: DEFAULT_TAG, align: ALIGN_DEFAULT, tooltipped: false, body_arguments: {}, **system_arguments)
  @align = fetch_or_fallback(ALIGN_OPTIONS, align, ALIGN_DEFAULT)
  @system_arguments = system_arguments
  @tooltipped = tooltipped
  @body_arguments = body_arguments

  body_tag = @body_arguments[:tag] || DEFAULT_BODY_TAG
  @body_arguments[:tag] = fetch_or_fallback(BODY_TAG_OPTIONS, body_tag, DEFAULT_BODY_TAG)
  @body_arguments[:classes] = class_names(
    "AvatarStack-body",
    @body_arguments[:classes]
  )

  @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)
  @system_arguments[:classes] = class_names(
    "AvatarStack",
    system_arguments[:classes],
    "AvatarStack--right" => @align == :right
  )
end

Instance Method Details

#before_renderObject



79
80
81
82
83
84
85
# File 'app/components/yattho/beta/avatar_stack.rb', line 79

def before_render
  @system_arguments[:classes] = class_names(
    @system_arguments[:classes],
    "AvatarStack--two" => avatars.size == 2,
    "AvatarStack--three-plus" => avatars.size > 2
  )
end

#body_componentObject



71
72
73
74
75
76
77
# File 'app/components/yattho/beta/avatar_stack.rb', line 71

def body_component
  if @tooltipped
    Yattho::Tooltip.new(**@body_arguments) # rubocop:disable Yattho/ComponentNameMigration
  else
    Yattho::BaseComponent.new(**@body_arguments)
  end
end

#render?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/components/yattho/beta/avatar_stack.rb', line 87

def render?
  avatars.any?
end