Class: Shadcn::Avatar::Component
- Inherits:
-
Shadcn::ApplicationViewComponent
- Object
- ViewComponent::Base
- Shadcn::ApplicationViewComponent
- Shadcn::Avatar::Component
- 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
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Attributes inherited from Shadcn::ApplicationViewComponent
Instance Method Summary collapse
- #call ⇒ Object
- #element_attributes(**defaults) ⇒ Object
-
#initialize(size: :default, **attributes) ⇒ Component
constructor
A new instance of Component.
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
#size ⇒ Object (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
#call ⇒ Object
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 |