Class: Daisy::DataDisplay::KbdComponent

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

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

Methods included from LocoMotion::Concerns::InspectableComponent

#build_inspect_string

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.



65
66
67
68
69
70
71
# File 'app/components/daisy/data_display/kbd_component.rb', line 65

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.



53
54
55
# File 'app/components/daisy/data_display/kbd_component.rb', line 53

def simple_title
  @simple_title
end

Instance Method Details

#before_renderObject



73
74
75
76
77
# File 'app/components/daisy/data_display/kbd_component.rb', line 73

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.



86
87
88
# File 'app/components/daisy/data_display/kbd_component.rb', line 86

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