Class: UI::AvatarFallback

Inherits:
Phlex::HTML
  • Object
show all
Includes:
AvatarFallbackBehavior
Defined in:
app/components/ui/avatar_fallback.rb

Overview

Avatar Fallback - Phlex implementation

Displays fallback content when the image hasn't loaded or fails to load. Uses AvatarFallbackBehavior module for shared styling logic.

Based on shadcn/ui Avatar: https://ui.shadcn.com/docs/components/avatar Based on Radix UI Avatar: https://www.radix-ui.com/primitives/docs/components/avatar

Examples:

Basic usage

render UI::Fallback.new { "CN" }

With custom styling

render UI::Fallback.new(classes: "bg-primary text-primary-foreground") do
  "AB"
end

Instance Method Summary collapse

Methods included from AvatarFallbackBehavior

#avatar_fallback_classes, #avatar_fallback_data_attributes, #avatar_fallback_html_attributes

Constructor Details

#initialize(classes: "", **attributes) ⇒ AvatarFallback

Returns a new instance of AvatarFallback.

Parameters:

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

    Additional CSS classes to merge

  • attributes (Hash) —

    Additional HTML attributes



23
24
25
26
# File 'app/components/ui/avatar_fallback.rb', line 23

def initialize(classes: "", **attributes)
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#view_template(&block) ⇒ Object



28
29
30
31
32
# File 'app/components/ui/avatar_fallback.rb', line 28

def view_template(&block)
  span(**avatar_fallback_html_attributes.deep_merge(@attributes)) do
    yield if block_given?
  end
end