Class: Hero::IconComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Hero::IconComponent
- Includes:
- LocoMotion::Concerns::TippableComponent
- Defined in:
- app/components/hero/icon_component.rb
Overview
By default, icons are displayed with the ‘size-5` Tailwind class. This can be overridden without using the `!` modifier because we utilize the `:where()` pseudo-class to ensure our default classes have the lowest CSS specificity.
Creates an icon component using Heroicons, a set of free, MIT-licensed high-quality SVG icons. For a complete list of available icons, visit heroicons.com.
Direct Known Subclasses
Daisy::DataInput::CallyComponent::NextIcon, Daisy::DataInput::CallyComponent::PreviousIcon
Constant Summary
Constants inherited from LocoMotion::BaseComponent
LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS
Instance Attribute Summary
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
- #before_render ⇒ Object
-
#call ⇒ Object
Renders the icon component.
-
#initialize(*args, **kws, &block) ⇒ IconComponent
constructor
Create a new instance of the IconComponent.
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) ⇒ IconComponent
Create a new instance of the IconComponent.
50 51 52 53 54 55 56 57 58 |
# File 'app/components/hero/icon_component.rb', line 50 def initialize(*args, **kws, &block) super # Accept either the :icon keyword argument or the first positional argument @icon = config_option(:icon, args[0]) @variant = config_option(:variant) @css = config_option(:css, "") end |
Instance Method Details
#before_render ⇒ Object
60 61 62 63 64 65 |
# File 'app/components/hero/icon_component.rb', line 60 def before_render super add_html(:component, { variant: @variant }) if @variant add_css(:component, "where:size-5") unless @css.include?("size-") end |
#call ⇒ Object
Renders the icon 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.
74 75 76 |
# File 'app/components/hero/icon_component.rb', line 74 def call heroicon(@icon, **rendered_html(:component)) end |