Class: PartyAvatarComponent

Inherits:
ApplicationComponent show all
Defined in:
app/components/party_avatar_component.rb

Overview

Displays a party's profile image or initials fallback.
Wraps Railsboot::AvatarComponent with party-specific logic.

Examples:

Basic usage

<%= render PartyAvatarComponent.new(party: customer) %>

With custom size

<%= render PartyAvatarComponent.new(party: customer, size: :lg) %>

With link to party

<%= render PartyAvatarComponent.new(party: customer, link: true) %>

Constant Summary collapse

SIZES =
{
  xs: 24,
  sm: 32,
  md: 48,
  lg: 80,
  xl: 120
}.freeze
DEFAULT_SIZE =
:md

Instance Method Summary collapse

Methods inherited from ApplicationComponent

#cms_link, #fetch_or_fallback, #image_asset_tag, #image_tag, #number_to_currency, #number_with_delimiter, #post_path, #post_url, #strip_tags

Constructor Details

#initialize(party:, size: DEFAULT_SIZE, link: false, shape: 'circle', **html_attributes) ⇒ PartyAvatarComponent

Returns a new instance of PartyAvatarComponent.

Parameters:

  • party (Party)

    The party to display

  • size (Symbol) (defaults to: DEFAULT_SIZE)

    Size preset (:xs, :sm, :md, :lg, :xl)

  • link (Boolean) (defaults to: false)

    Whether to link to the party

  • shape (String) (defaults to: 'circle')

    Avatar shape (circle, rounded, square)

  • html_attributes (Hash)

    Additional HTML attributes



31
32
33
34
35
36
37
38
# File 'app/components/party_avatar_component.rb', line 31

def initialize(party:, size: DEFAULT_SIZE, link: false, shape: 'circle', **html_attributes)
  super()
  @party = party
  @size = SIZES[size] || size.to_i
  @link = link
  @shape = shape
  @html_attributes = html_attributes
end

Instance Method Details

#callObject



40
41
42
43
44
45
46
# File 'app/components/party_avatar_component.rb', line 40

def call
  if profile_image?
    render_with_image
  else
    render_with_initials
  end
end