Class: Fluxbit::SkeletonComponent

Inherits:
Component
  • Object
show all
Includes:
Config::SkeletonComponent
Defined in:
app/components/fluxbit/skeleton_component.rb

Overview

The ‘Fluxbit::SkeletonComponent` is a customizable skeleton loading component that extends `Fluxbit::Component`. It provides animated placeholders for content that is loading, supporting various types like text, images, cards, avatars, and more complex layouts.

Examples:

Basic usage

= fx_skeleton
= fx_skeleton(variant: :image)
= fx_skeleton(variant: :card)

See Also:

  • For detailed documentation.

Instance Method Summary collapse

Methods inherited from Component

#add, #add_popover_or_tooltip, #anyicon, #element_name, #fx_id, #icon, #options, #popover?, #random_id, #remove_class, #remove_class_from_props, #render_popover_or_tooltip, #target, #tooltip?

Methods included from IconHelpers

#chevron_double_left, #chevron_double_right, #chevron_down, #chevron_left, #chevron_right, #chevron_up, #close_icon, #ellipsis_horizontal, #eye_icon, #eye_slash_icon, #plus_icon

Constructor Details

#initialize(**props) ⇒ Fluxbit::SkeletonComponent

Initializes the skeleton component with the given properties.

Parameters:

  • **props (Hash)

    The properties to customize the skeleton.

  • props (Hash)

    a customizable set of options

Options Hash (**props):

  • :variant (Symbol) — default: :default

    The type of skeleton (:default, :text, :image, :video, :avatar, :card, :widget, :list, :testimonial, :button).

  • :animation (Boolean) — default: true

    Whether to show the pulse animation.

  • :rows (Integer) — default: 3

    Number of text rows for default/text variants.

  • :size (Symbol) — default: :medium

    Size for avatar, image, and video variants (:small, :medium, :large).

  • :lines (Integer) — default: nil

    Number of lines for text-based variants.

  • :remove_class (String) — default: ''

    CSS classes to remove from the default class list.

  • **props (Hash)

    Remaining options declared as HTML attributes.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/fluxbit/skeleton_component.rb', line 30

def initialize(**props)
  super
  @props = props

  @variant = options(@props.delete(:variant),
                     collection: [ :default, :text, :image, :video, :avatar, :card, :widget, :list, :testimonial, :button ],
                     default: @@variant)
  @animation = options(@props.delete(:animation), default: @@animation)
  @rows = options(@props.delete(:rows), default: @@rows).to_i
  @size = options(@props.delete(:size), collection: [ :small, :medium, :large ], default: :medium)
  @lines = @props.delete(:lines)&.to_i

  declare_classes
  @props[:class] = remove_class(@props.delete(:remove_class) || "", @props[:class])
  @props[:role] = "status"
  @props["aria-label"] = "Loading"
end

Instance Method Details

#callObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/components/fluxbit/skeleton_component.rb', line 48

def call
  tag.div(**@props) do
    case @variant
    when :default, :text
      render_text_skeleton
    when :image
      render_image_skeleton
    when :video
      render_video_skeleton
    when :avatar
      render_avatar_skeleton
    when :card
      render_card_skeleton
    when :widget
      render_widget_skeleton
    when :list
      render_list_skeleton
    when :testimonial
      render_testimonial_skeleton
    when :button
      render_button_skeleton
    end
  end
end