Class: Shadcn::Avatar::Component

Inherits:
Shadcn::ApplicationViewComponent show all
Defined in:
app/components/shadcn/avatar/component.rb

Overview

Port of registry/new-york-v4/ui/avatar.tsx

Radix swaps the image for the fallback based on the image's loading state; the shadcn--avatar Stimulus controller does the same here.

Constant Summary

Constants inherited from Shadcn::ApplicationViewComponent

Shadcn::ApplicationViewComponent::CONTENTS_STYLE, Shadcn::ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from Shadcn::ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from Shadcn::ApplicationViewComponent

#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(size: :default, **attributes) ⇒ Component

Returns a new instance of Component.



26
27
28
29
# File 'app/components/shadcn/avatar/component.rb', line 26

def initialize(size: :default, **attributes)
  @size = size&.to_sym || :default
  super(**attributes)
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



24
25
26
# File 'app/components/shadcn/avatar/component.rb', line 24

def size
  @size
end

Instance Method Details

#callObject



38
39
40
# File 'app/components/shadcn/avatar/component.rb', line 38

def call
  render_element(body: safe_join([ image, fallback, badge, content ].compact))
end

#element_attributes(**defaults) ⇒ Object



31
32
33
34
35
36
# File 'app/components/shadcn/avatar/component.rb', line 31

def element_attributes(**defaults)
  super(**{
    "data-size" => size,
    "data-controller" => "shadcn--avatar"
  }.merge(defaults))
end