Class: Daisy::DataDisplay::KbdComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
LocoMotion::Concerns::TippableComponent
Defined in:
app/components/daisy/data_display/kbd_component.rb

Overview

Note:

This is an inline component that renders as a ‘<span>` to avoid adding extra whitespace when used within text.

The Kbd (Keyboard) component displays keyboard inputs or shortcuts in a visually distinct way. It’s perfect for showing keyboard shortcuts, key combinations, or individual key presses in documentation or tutorials.

Includes the LocoMotion::Concerns::TippableComponent module to enable easy tooltip addition.

Constant Summary

Constants inherited from LocoMotion::BaseComponent

LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS

Instance Attribute Summary collapse

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

Methods inherited from LocoMotion::BaseComponent

build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces

Constructor Details

#initialize(*args, **kws, &block) ⇒ KbdComponent

Creates a new kbd component.

Parameters:

  • text (String)

    The text to display in the keyboard component.

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • :tip (String)

    The tooltip text to display when hovering over the component.



61
62
63
64
65
66
67
# File 'app/components/daisy/data_display/kbd_component.rb', line 61

def initialize(*args, **kws, &block)
  super

  @simple_title = args[0]

  set_tag_name(:component, :span)
end

Instance Attribute Details

#simple_titleObject (readonly)

Returns the value of attribute simple_title.



49
50
51
# File 'app/components/daisy/data_display/kbd_component.rb', line 49

def simple_title
  @simple_title
end

Instance Method Details

#before_renderObject



69
70
71
72
73
# File 'app/components/daisy/data_display/kbd_component.rb', line 69

def before_render
  super

  setup_component
end

#callObject

Renders the kbd (Keyboard) component.

Because this is an inline component which might be utlized alongside text, we utilize the ‘call` method instead of a template to ensure that no additional whitespace gets added to the output.



82
83
84
# File 'app/components/daisy/data_display/kbd_component.rb', line 82

def call
  part(:component) { content || simple_title }
end