Class: BetterUi::General::Avatar::Component
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- BetterUi::General::Avatar::Component
- Defined in:
- app/components/better_ui/general/avatar/component.rb
Constant Summary collapse
- AVATAR_BASE_CLASSES =
Classi base sempre presenti
"relative inline-flex items-center justify-center flex-shrink-0 overflow-hidden"- AVATAR_IMG_CLASSES =
Classi per elementi interni
"h-full w-full object-cover"- AVATAR_PLACEHOLDER_BASE_CLASSES =
"flex items-center justify-center h-full w-full font-medium"- AVATAR_STATUS_BASE_CLASSES =
"absolute rounded-full border-2 border-white"- AVATAR_SIZE_CLASSES =
Dimensioni container con classi Tailwind dirette
{ xxsmall: "h-5 w-5", xsmall: "h-6 w-6", small: "h-8 w-8", medium: "h-10 w-10", large: "h-12 w-12", xlarge: "h-16 w-16", xxlarge: "h-24 w-24" }
- AVATAR_PLACEHOLDER_SIZE_CLASSES =
Dimensioni testo placeholder
{ xxsmall: "text-xs", xsmall: "text-xs", small: "text-sm", medium: "text-base", large: "text-lg", xlarge: "text-xl", xxlarge: "text-2xl" }
- AVATAR_SHAPE_CLASSES =
Forme con classi Tailwind dirette
{ circle: "rounded-full", square: "rounded-none", rounded: "rounded-lg" }
- AVATAR_PLACEHOLDER_THEME_CLASSES =
Temi placeholder con classi Tailwind dirette
{ default: "bg-black text-white", white: "bg-white text-black border border-gray-300", red: "bg-red-500 text-white", rose: "bg-rose-500 text-white", orange: "bg-orange-500 text-white", green: "bg-green-500 text-white", blue: "bg-blue-500 text-white", yellow: "bg-yellow-500 text-black", violet: "bg-violet-500 text-white" }
- AVATAR_STATUS_THEME_CLASSES =
Stati online con classi Tailwind dirette
{ online: "bg-green-400", offline: "bg-gray-400", busy: "bg-red-400", away: "bg-yellow-400" }
- AVATAR_STATUS_SIZE_CLASSES =
Dimensioni indicatore stato
{ xxsmall: "h-1 w-1", xsmall: "h-1.5 w-1.5", small: "h-2 w-2", medium: "h-2.5 w-2.5", large: "h-3 w-3", xlarge: "h-3.5 w-3.5", xxlarge: "h-4 w-4" }
- AVATAR_STATUS_POSITION_CLASSES =
Posizioni dell’indicatore di stato
{ bottom_right: "bottom-0 right-0", bottom_left: "bottom-0 left-0", top_right: "top-0 right-0", top_left: "top-0 left-0" }
- AVATAR_STYLE_CLASSES =
Stili disponibili (mantenuto per compatibilità)
{ filled: "", outline: "border-2 border-gray-300", light: "opacity-75" }
Instance Attribute Summary collapse
-
#classes ⇒ Object
readonly
Returns the value of attribute classes.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#shape ⇒ Object
readonly
Returns the value of attribute shape.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#status_position ⇒ Object
readonly
Returns the value of attribute status_position.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
Instance Method Summary collapse
-
#avatar_attributes ⇒ Object
Restituisce gli attributi per l’avatar.
-
#combined_classes ⇒ Object
Combina tutte le classi per il container.
- #get_placeholder_size_class ⇒ Object
- #get_placeholder_theme_class ⇒ Object
- #get_shape_class ⇒ Object
- #get_size_class ⇒ Object
- #get_status_position_class ⇒ Object
- #get_status_size_class ⇒ Object
- #get_status_theme_class ⇒ Object
- #get_style_class ⇒ Object
-
#img_classes ⇒ Object
Classi per l’immagine.
-
#initialize(name: nil, src: nil, size: :medium, shape: :circle, status: nil, status_position: :bottom_right, theme: :white, style: :filled, classes: nil, id: nil, **html_options) ⇒ Component
constructor
A new instance of Component.
-
#initials ⇒ Object
Ottiene le iniziali dal nome.
-
#pixel_size ⇒ Object
Ottiene le dimensioni dell’avatar in pixel (per attributi width/height img).
-
#placeholder_classes ⇒ Object
Classi per il placeholder.
-
#show_image? ⇒ Boolean
Determina se mostrare l’immagine.
-
#show_status? ⇒ Boolean
Determina se mostrare l’indicatore di stato.
-
#status_indicator_classes ⇒ Object
Classi per l’indicatore di stato.
Constructor Details
#initialize(name: nil, src: nil, size: :medium, shape: :circle, status: nil, status_position: :bottom_right, theme: :white, style: :filled, classes: nil, id: nil, **html_options) ⇒ Component
Returns a new instance of Component.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/components/better_ui/general/avatar/component.rb', line 91 def initialize( name: nil, src: nil, size: :medium, shape: :circle, status: nil, status_position: :bottom_right, theme: :white, style: :filled, classes: nil, id: nil, ** ) @name = name @src = src @size = size.to_sym @shape = shape.to_sym @status = status.present? ? status.to_sym : nil @status_position = status_position.to_sym @theme = theme.to_sym @style = style.to_sym @classes = classes @id = id = validate_params end |
Instance Attribute Details
#classes ⇒ Object (readonly)
Returns the value of attribute classes.
5 6 7 |
# File 'app/components/better_ui/general/avatar/component.rb', line 5 def classes @classes end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'app/components/better_ui/general/avatar/component.rb', line 5 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'app/components/better_ui/general/avatar/component.rb', line 5 def name @name end |
#shape ⇒ Object (readonly)
Returns the value of attribute shape.
5 6 7 |
# File 'app/components/better_ui/general/avatar/component.rb', line 5 def shape @shape end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
5 6 7 |
# File 'app/components/better_ui/general/avatar/component.rb', line 5 def size @size end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
5 6 7 |
# File 'app/components/better_ui/general/avatar/component.rb', line 5 def src @src end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
5 6 7 |
# File 'app/components/better_ui/general/avatar/component.rb', line 5 def status @status end |
#status_position ⇒ Object (readonly)
Returns the value of attribute status_position.
5 6 7 |
# File 'app/components/better_ui/general/avatar/component.rb', line 5 def status_position @status_position end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
5 6 7 |
# File 'app/components/better_ui/general/avatar/component.rb', line 5 def style @style end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
5 6 7 |
# File 'app/components/better_ui/general/avatar/component.rb', line 5 def theme @theme end |
Instance Method Details
#avatar_attributes ⇒ Object
Restituisce gli attributi per l’avatar
192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'app/components/better_ui/general/avatar/component.rb', line 192 def avatar_attributes attrs = { class: combined_classes, id: @id } # Aggiungi altri attributi HTML se presenti .except(:class).each do |key, value| attrs[key] = value end attrs end |
#combined_classes ⇒ Object
Combina tutte le classi per il container
120 121 122 123 124 125 126 127 128 129 |
# File 'app/components/better_ui/general/avatar/component.rb', line 120 def combined_classes [ AVATAR_BASE_CLASSES, get_size_class, get_shape_class, get_style_class, @classes, [:class] ].compact.join(" ") end |
#get_placeholder_size_class ⇒ Object
175 176 177 |
# File 'app/components/better_ui/general/avatar/component.rb', line 175 def get_placeholder_size_class AVATAR_PLACEHOLDER_SIZE_CLASSES[@size] || AVATAR_PLACEHOLDER_SIZE_CLASSES[:medium] end |
#get_placeholder_theme_class ⇒ Object
171 172 173 |
# File 'app/components/better_ui/general/avatar/component.rb', line 171 def get_placeholder_theme_class AVATAR_PLACEHOLDER_THEME_CLASSES[@theme] || AVATAR_PLACEHOLDER_THEME_CLASSES[:white] end |
#get_shape_class ⇒ Object
163 164 165 |
# File 'app/components/better_ui/general/avatar/component.rb', line 163 def get_shape_class AVATAR_SHAPE_CLASSES[@shape] || AVATAR_SHAPE_CLASSES[:circle] end |
#get_size_class ⇒ Object
159 160 161 |
# File 'app/components/better_ui/general/avatar/component.rb', line 159 def get_size_class AVATAR_SIZE_CLASSES[@size] || AVATAR_SIZE_CLASSES[:medium] end |
#get_status_position_class ⇒ Object
187 188 189 |
# File 'app/components/better_ui/general/avatar/component.rb', line 187 def get_status_position_class AVATAR_STATUS_POSITION_CLASSES[@status_position] || AVATAR_STATUS_POSITION_CLASSES[:bottom_right] end |
#get_status_size_class ⇒ Object
183 184 185 |
# File 'app/components/better_ui/general/avatar/component.rb', line 183 def get_status_size_class AVATAR_STATUS_SIZE_CLASSES[@size] || AVATAR_STATUS_SIZE_CLASSES[:medium] end |
#get_status_theme_class ⇒ Object
179 180 181 |
# File 'app/components/better_ui/general/avatar/component.rb', line 179 def get_status_theme_class AVATAR_STATUS_THEME_CLASSES[@status] || "" end |
#get_style_class ⇒ Object
167 168 169 |
# File 'app/components/better_ui/general/avatar/component.rb', line 167 def get_style_class AVATAR_STYLE_CLASSES[@style] || AVATAR_STYLE_CLASSES[:filled] end |
#img_classes ⇒ Object
Classi per l’immagine
142 143 144 145 146 147 |
# File 'app/components/better_ui/general/avatar/component.rb', line 142 def img_classes [ AVATAR_IMG_CLASSES, get_shape_class ].compact.join(" ") end |
#initials ⇒ Object
Ottiene le iniziali dal nome
212 213 214 215 216 217 218 219 220 221 |
# File 'app/components/better_ui/general/avatar/component.rb', line 212 def initials return "" unless @name.present? words = @name.strip.split(/\s+/) if words.size >= 2 "#{words[0][0]}#{words[1][0]}".upcase else @name[0..1].upcase end end |
#pixel_size ⇒ Object
Ottiene le dimensioni dell’avatar in pixel (per attributi width/height img)
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'app/components/better_ui/general/avatar/component.rb', line 229 def pixel_size case @size when :xxsmall 20 when :xsmall 24 when :small 32 when :medium 40 when :large 48 when :xlarge 64 when :xxlarge 96 else 40 end end |
#placeholder_classes ⇒ Object
Classi per il placeholder
132 133 134 135 136 137 138 139 |
# File 'app/components/better_ui/general/avatar/component.rb', line 132 def placeholder_classes [ AVATAR_PLACEHOLDER_BASE_CLASSES, get_placeholder_theme_class, get_placeholder_size_class, get_shape_class ].compact.join(" ") end |
#show_image? ⇒ Boolean
Determina se mostrare l’immagine
224 225 226 |
# File 'app/components/better_ui/general/avatar/component.rb', line 224 def show_image? @src.present? end |
#show_status? ⇒ Boolean
Determina se mostrare l’indicatore di stato
207 208 209 |
# File 'app/components/better_ui/general/avatar/component.rb', line 207 def show_status? @status.present? && AVATAR_STATUS_THEME_CLASSES.key?(@status) end |
#status_indicator_classes ⇒ Object
Classi per l’indicatore di stato
150 151 152 153 154 155 156 157 |
# File 'app/components/better_ui/general/avatar/component.rb', line 150 def status_indicator_classes [ AVATAR_STATUS_BASE_CLASSES, get_status_theme_class, get_status_size_class, get_status_position_class ].compact.join(" ") end |