Class: Daisy::DataDisplay::BadgeComponent

Inherits:
LocoMotion::BaseComponent show all
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

#config, #loco_parent

Instance Method Summary collapse

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.

Parameters:

  • title (String) (defaults to: nil)

    The text to display in the badge. You can also pass the title as a keyword argument or provide content via a block.

  • kwargs (Hash)

    The keyword arguments for the 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_renderObject



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

#callObject

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