Class: Primer::Beta::AvatarStack
- Defined in:
- app/components/primer/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
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Constants included from AttributesHelper
AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES
Instance Method Summary collapse
- #before_render ⇒ Object
- #body_component ⇒ Object
-
#initialize(tag: DEFAULT_TAG, align: ALIGN_DEFAULT, tooltipped: false, body_arguments: {}, **system_arguments) ⇒ AvatarStack
constructor
A new instance of AvatarStack.
- #render? ⇒ Boolean
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Methods included from AttributesHelper
#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Methods included from ExperimentalSlotHelpers
Methods included from ExperimentalRenderHelpers
Constructor Details
#initialize(tag: DEFAULT_TAG, align: ALIGN_DEFAULT, tooltipped: false, body_arguments: {}, **system_arguments) ⇒ AvatarStack
Returns a new instance of AvatarStack.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/components/primer/beta/avatar_stack.rb', line 29 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 @direction = @body_arguments[:direction] 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 ) @body_arguments[:tabindex] = tooltipped ? 0 : nil @body_arguments[:id] = tooltipped ? @body_arguments[:id] ||= self.class.generate_id : @body_arguments[:id] @tooltip_arguments = { for_id: @body_arguments[:id], direction: @body_arguments.delete(:direction), } @tooltip_arguments[:direction] = @direction || Primer::Alpha::Tooltip::DIRECTION_DEFAULT @tooltip_arguments[:text] = @body_arguments[:label] @tooltip_arguments[:type] = :description @body_arguments[:aria] ||= {} if tooltipped && @body_arguments[:label].present? @body_arguments[:aria][:label] = @body_arguments[:label] @body_arguments[:label] = nil end end |
Instance Method Details
#before_render ⇒ Object
73 74 75 76 77 78 79 |
# File 'app/components/primer/beta/avatar_stack.rb', line 73 def before_render @system_arguments[:classes] = class_names( @system_arguments[:classes], "AvatarStack--two" => avatars.size == 2, "AvatarStack--three-plus" => avatars.size > 2 ) end |
#body_component ⇒ Object
69 70 71 |
# File 'app/components/primer/beta/avatar_stack.rb', line 69 def body_component Primer::BaseComponent.new(**@body_arguments) end |
#render? ⇒ Boolean
81 82 83 |
# File 'app/components/primer/beta/avatar_stack.rb', line 81 def render? avatars.any? end |