Class: Ariadne::AvatarStackComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/ariadne/avatar_stack_component.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
DEFAULT_CLASSES =
"ariadne-flex ariadne--space-x-2 ariadne-overflow-hidden"

Constants inherited from Component

Component::BASE_HIDDEN_CLASS, Component::BASE_MAIN_CLASSES, Component::BASE_WRAPPER_CLASSES, Component::INVALID_ARIA_LABEL_TAGS

Constants included from Ariadne::ActionViewExtensions::FormHelper

Ariadne::ActionViewExtensions::FormHelper::DEFAULT_FORM_CLASSES

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::INTEGER_TYPES, FetchOrFallbackHelper::InvalidValueError, FetchOrFallbackHelper::TRUE_OR_FALSE

Instance Method Summary collapse

Methods included from Ariadne::ActionViewExtensions::FormHelper

#ariadne_form_with

Methods included from ClassNameHelper

#class_names

Methods included from LoggerHelper

#logger, #silence_deprecations?, #silence_warnings?

Methods included from FetchOrFallbackHelper

#check_incoming_attribute, #check_incoming_tag, #check_incoming_value, #fetch_or_raise, #fetch_or_raise_boolean, #fetch_or_raise_integer

Constructor Details

#initialize(tag: DEFAULT_TAG, align: ALIGN_DEFAULT, classes: "", attributes: {}) ⇒ AvatarStackComponent

Returns a new instance of AvatarStackComponent.

Examples:

Default

<%= render(Ariadne::AvatarStackComponent.new) do |c| %>
  <% c.avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
  <% c.avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
  <% c.avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
<% end  %>

Align right

<%= render(Ariadne::AvatarStackComponent.new(align: :right)) do |c| %>
  <% c.avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
  <% c.avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
  <% c.avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
<% end  %>

Parameters:

  • tag (Symbol) (defaults to: DEFAULT_TAG)

    <%= one_of(Ariadne::AvatarStackComponent::TAG_OPTIONS) %>

  • align (Symbol) (defaults to: ALIGN_DEFAULT)

    <%= one_of(Ariadne::AvatarStackComponent::ALIGN_OPTIONS) %>

  • classes (String) (defaults to: "")

    <%= link_to_classes_docs %>

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

    <%= link_to_attributes_docs %>



54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/components/ariadne/avatar_stack_component.rb', line 54

def initialize(tag: DEFAULT_TAG, align: ALIGN_DEFAULT, classes: "", attributes: {})
  @tag = check_incoming_tag(DEFAULT_TAG, tag)
  @align = fetch_or_raise(ALIGN_OPTIONS, align)
  @classes = class_names(
    DEFAULT_CLASSES,
    classes,
  )

  @attributes = attributes
  @attributes[:id] ||= "avatar-stack-#{SecureRandom.hex(4)}"
  @id = @attributes[:id]
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/components/ariadne/avatar_stack_component.rb', line 67

def render?
  avatars.any?
end

#tooltipped?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'app/components/ariadne/avatar_stack_component.rb', line 71

def tooltipped?
  tooltip.present?
end