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

Methods included from LocoMotion::Concerns::InspectableComponent

#build_inspect_string

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

  • href (String)

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

  • target (String)

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

  • turbo_frame (String)

    The Turbo Frame to target, rendered as data-turbo-frame.

  • turbo_action (String, Symbol)

    How Turbo Drive updates the browser history for the visit, rendered as data-turbo-action (e.g. :advance or :replace).

  • turbo_method (String, Symbol)

    The HTTP method Turbo should use for the request, rendered as data-turbo-method (e.g. :delete).

  • turbo_confirm (String)

    A confirmation prompt Turbo shows before submitting, rendered as data-turbo-confirm.

  • action (String)

    A Stimulus action wired to the card via its data-action attribute. Stimulus infers the click event, so action: "my-controller#handle" works as a shorthand for action: "click->my-controller#handle".

  • 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.



116
117
118
119
120
# File 'app/components/daisy/data_display/card_component.rb', line 116

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.



68
69
70
# File 'app/components/daisy/data_display/card_component.rb', line 68

def simple_title
  @simple_title
end

Instance Method Details

#before_renderObject



122
123
124
125
126
127
# File 'app/components/daisy/data_display/card_component.rb', line 122

def before_render
  setup_component
  super # Runs the TippableComponent and LinkableComponent setup hooks

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