Class: Daisy::DataDisplay::CardComponent

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

Overview

The Card component is a flexible container for displaying content with a consistent style. It can include images, titles, text, and actions.

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

Creates a new card component.

Parameters:

  • kws (Hash)

    The keyword arguments for the component.

Options Hash (**kws):

  • title (String)

    Optional simple title text. For more complex titles, use the ‘with_title` method instead.

  • css (String)

    Additional CSS classes for styling. Common options include:

    • Image Side: ‘image-full` (image becomes background)

    • Borders: ‘card-border`

    • Sizes: ‘card-sm` (less padding)

    • Colors: ‘bg-base-100`, `bg-primary`, `bg-secondary`

  • tip (String)

    The tooltip text to display when hovering over the component.



84
85
86
87
88
# File 'app/components/daisy/data_display/card_component.rb', line 84

def initialize(**kws, &block)
  super

  @simple_title = kws[:title]
end

Instance Attribute Details

#simple_titleString (readonly)

Returns The title text when using the simple title option.

Returns:

  • (String)

    The title text when using the simple title option.



65
66
67
# File 'app/components/daisy/data_display/card_component.rb', line 65

def simple_title
  @simple_title
end

Instance Method Details

#before_renderObject



90
91
92
93
94
95
# File 'app/components/daisy/data_display/card_component.rb', line 90

def before_render
  setup_component
  super # Runs TippableComponent's setup hook

  with_title { simple_title } if simple_title && !title?
end