Class: UI::KbdComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
KbdBehavior
Defined in:
app/view_components/ui/kbd_component.rb

Overview

KbdComponent - ViewComponent implementation

Displays textual user input from keyboard, helping users understand keyboard shortcuts and interactions within applications. Uses KbdBehavior concern for shared styling logic.

Examples:

Basic usage

<%= render UI::KbdComponent.new { "Ctrl" } %>

With custom classes

<%= render UI::KbdComponent.new(classes: "text-sm") { "⌘K" } %>

Instance Method Summary collapse

Methods included from KbdBehavior

#kbd_classes, #kbd_html_attributes

Constructor Details

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

Returns a new instance of KbdComponent.

Parameters:

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

    Additional CSS classes to merge

  • attributes (Hash) —

    Additional HTML attributes



19
20
21
22
# File 'app/view_components/ui/kbd_component.rb', line 19

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

Instance Method Details

#call ⇒ Object



24
25
26
27
28
29
30
# File 'app/view_components/ui/kbd_component.rb', line 24

def call
  attrs = kbd_html_attributes

   :kbd, **attrs.merge(@attributes) do
    content
  end
end