Class: Daisy::DataDisplay::KbdComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::DataDisplay::KbdComponent
- Includes:
- LocoMotion::Concerns::TippableComponent
- Defined in:
- app/components/daisy/data_display/kbd_component.rb
Overview
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
-
#simple_title ⇒ Object
readonly
Returns the value of attribute simple_title.
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
- #before_render ⇒ Object
-
#call ⇒ Object
Renders the kbd (Keyboard) component.
-
#initialize(*args, **kws, &block) ⇒ KbdComponent
constructor
Creates a new kbd component.
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.
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_title ⇒ Object (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_render ⇒ Object
69 70 71 72 73 |
# File 'app/components/daisy/data_display/kbd_component.rb', line 69 def before_render super setup_component end |
#call ⇒ Object
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 |