Class: PhlexKit::SidebarMenuSkeleton

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/sidebar/sidebar_menu_skeleton.rb

Overview

Loading placeholder for a menu item, ported from shadcn/ui's SidebarMenuSkeleton: an optional icon shimmer plus a text shimmer whose width randomises 50–90% per render (their --skeleton-width trick). show_icon: mirrors shadcn's showIcon. See sidebar.rb.

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(show_icon: false, **attrs) ⇒ SidebarMenuSkeleton

Returns a new instance of SidebarMenuSkeleton.



7
8
9
10
# File 'app/components/phlex_kit/sidebar/sidebar_menu_skeleton.rb', line 7

def initialize(show_icon: false, **attrs)
  @show_icon = show_icon
  @attrs = attrs
end

Instance Method Details

#view_templateObject



12
13
14
15
16
17
# File 'app/components/phlex_kit/sidebar/sidebar_menu_skeleton.rb', line 12

def view_template
  div(**mix({ class: "pk-sidebar-menu-skeleton" }, @attrs)) do
    render Skeleton.new(class: "icon") if @show_icon
    render Skeleton.new(class: "text", style: "--pk-skeleton-width: #{rand(50..90)}%;")
  end
end