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.

Note:

right_icon and its right_icon_* variants have no effect on Stat — the template only ever renders the left/aliased icon via render_icon inside the figure part.

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

Methods included from LocoMotion::Concerns::InspectableComponent

#build_inspect_string

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. When href is also set, this same text becomes the anchor's title HTML attribute (via LocoMotion::Concerns::LinkableComponent) in addition to the visible stat title.

  • :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 an icon to display in the figure section.

  • :icon_css (String)

    The CSS classes to apply to the icon.

  • :icon_html (Hash)

    Additional HTML attributes to apply to the icon.

  • :icon_options (Hash)

    Additional keyword arguments forwarded to the icon component (e.g. tip:).

  • :href (String)

    A path or URL to which the user will be directed when the stat is clicked. Forces the Stat to use an <a> tag.

  • :target (String)

    The HTML target attribute for the <a> tag (_blank, _parent, or a specific tab / window / iframe, etc).

  • :tip (String)

    The tooltip text to display when hovering over the component.



119
120
121
122
123
124
125
# File 'app/components/daisy/data_display/stat_component.rb', line 119

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.



76
77
78
# File 'app/components/daisy/data_display/stat_component.rb', line 76

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.



72
73
74
# File 'app/components/daisy/data_display/stat_component.rb', line 72

def simple_title
  @simple_title
end

Instance Method Details

#before_renderObject



127
128
129
130
131
# File 'app/components/daisy/data_display/stat_component.rb', line 127

def before_render
  setup_component

  super
end

#default_icon_sizeObject



133
134
135
# File 'app/components/daisy/data_display/stat_component.rb', line 133

def default_icon_size
  "where:size-8"
end