Class: Daisy::DataDisplay::StatComponent

Inherits:
LocoMotion::BaseComponent show all
Includes:
LocoMotion::Concerns::IconableComponent, LocoMotion::Concerns::LinkableComponent, LocoMotion::Concerns::TippableComponent
Defined in:
app/components/daisy/data_display/stat_component.rb

Overview

Note:

Stats have a transparent background by default. Use ‘bg-base-100` if you need a background color.

The Stat component displays a statistic or metric with optional title, description, and figure. It’s perfect for dashboards, summaries, or any situation where you need to highlight important numbers or metrics.

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

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(*args, **kws, &block) ⇒ StatComponent

Creates a new stat component.

Parameters:

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • :title (String)

    The text to display in the title section. You can also provide custom title content using the title slot.

  • :description (String)

    The text to display in the description section. You can also provide custom description content using the description slot.

  • :src (String)

    URL of an image to display in the figure section.

  • :icon (String)

    Name of a heroicon to display in the figure section.

  • :tip (String)

    The tooltip text to display when hovering over the component.



87
88
89
90
91
92
93
# File 'app/components/daisy/data_display/stat_component.rb', line 87

def initialize(*args, **kws, &block)
  super

  @simple_title = config_option(:title)
  @simple_description = config_option(:description)
  @src = config_option(:src)
end

Instance Attribute Details

#simple_descriptionString (readonly)

Returns The description text when using the simple description option.

Returns:

  • (String)

    The description text when using the simple description option.



64
65
66
# File 'app/components/daisy/data_display/stat_component.rb', line 64

def simple_description
  @simple_description
end

#simple_titleString (readonly)

Returns The title text when using the simple title option.

Returns:

  • (String)

    The title text when using the simple title option.



60
61
62
# File 'app/components/daisy/data_display/stat_component.rb', line 60

def simple_title
  @simple_title
end

Instance Method Details

#before_renderObject



95
96
97
98
99
# File 'app/components/daisy/data_display/stat_component.rb', line 95

def before_render
  setup_component

  super
end

#default_icon_sizeObject



101
102
103
# File 'app/components/daisy/data_display/stat_component.rb', line 101

def default_icon_size
  "where:size-8"
end