Class: Daisy::DataDisplay::BadgeComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::DataDisplay::BadgeComponent
- Includes:
- LocoMotion::Concerns::IconableComponent, LocoMotion::Concerns::LinkableComponent, LocoMotion::Concerns::TippableComponent
- Defined in:
- app/components/daisy/data_display/badge_component.rb,
app/components/daisy/data_display/badge_component.rb
Overview
The Badge component renders as a small, rounded element used to display status, labels, or notifications. It supports various background colors and can be used inline with text.
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
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
- #before_render ⇒ Object
-
#call ⇒ Object
Renders the badge component.
-
#initialize(title = nil, **kws, &block) ⇒ BadgeComponent
constructor
Create a new Badge component.
Methods included from LocoMotion::Concerns::IconableComponent
#has_icons?, #left_icon_html, #render_left_icon, #render_right_icon, #right_icon_html
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(title = nil, **kws, &block) ⇒ BadgeComponent
Create a new Badge component.
155 156 157 158 159 |
# File 'app/components/daisy/data_display/badge_component.rb', line 155 def initialize(title = nil, **kws, &block) super @simple_title = config_option(:title, title) end |
Instance Method Details
#before_render ⇒ Object
161 162 163 164 165 166 |
# File 'app/components/daisy/data_display/badge_component.rb', line 161 def before_render # Run component setup *before* super to allow LinkableComponent to override tag setup_component super end |
#call ⇒ Object
Renders the badge 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.
175 176 177 178 179 180 181 |
# File 'app/components/daisy/data_display/badge_component.rb', line 175 def call part(:component) do concat(render_left_icon) concat(content || @simple_title) concat(render_right_icon) end end |