Class: DaisyUI::Card::Body

Inherits:
BaseComponent show all
Defined in:
app/components/daisy_ui/data_display/card/body.rb

Overview

Body component for the card, containing title, description and actions

Examples:

Basic usage

<%= render(CardComponent.new) do |component| %>
  <% component.with_body do |body| %>
    <% body.with_title { "Title" } %>
    <% body.with_description { "Description" } %>
  <% end %>
<% end %>

With simple button

<%= render(CardComponent.new) do |component| %>
  <% component.with_body(
    title: "Title",
    description: "Description",
    button: { text: "Action", color: :primary, justify: :end }
  ) %>
<% end %>

With multiple buttons

<%= render(CardComponent.new) do |component| %>
  <% component.with_body do |body| %>
    <% body.with_title { "Title" } %>
    <% body.with_actions(justify: :between) do |actions| %>
      <% actions.with_button(text: "Cancel", variant: :ghost) %>
      <% actions.with_bage(text: "Submit", color: :primary) %>
    <% end %>
  <% end %>
<% end %>

Instance Method Summary collapse

Constructor Details

#initialize(variant: nil, description: nil, title: nil, button: nil, **system_arguments) ⇒ Body

Returns a new instance of Body.

Parameters:

  • variant (Symbol) (defaults to: nil)

    Card variant affecting body layout

  • description (String) (defaults to: nil)

    Card description text

  • title (String) (defaults to: nil)

    Card title text

  • button (Hash) (defaults to: nil)

    Simple button configuration

  • system_arguments (Hash)

    Additional HTML attributes

Options Hash (button:):

  • :text (String)

    Button text

  • :color (Symbol)

    Button color

  • :variant (Symbol)

    Button variant

  • :size (Symbol)

    Button size

  • :justify (Symbol)

    Button justification



54
55
56
57
58
59
60
61
62
63
64
# File 'app/components/daisy_ui/data_display/card/body.rb', line 54

def initialize(variant: nil,
               description: nil,
               title: nil,
               button: nil,
               **system_arguments)
  @variant = variant
  @description = description
  @title = title
  @button = button
  super(**system_arguments)
end

Instance Method Details

#before_renderObject



76
77
78
79
80
# File 'app/components/daisy_ui/data_display/card/body.rb', line 76

def before_render
  with_title(@title) if @title && !title?
  with_description { tag.p(@description) } if @description && !description?
  setup_button if @button && !actions?
end

#callObject



66
67
68
69
70
71
72
73
74
# File 'app/components/daisy_ui/data_display/card/body.rb', line 66

def call
  tag.div(**html_attributes) do
    safe_join([
      title,
      render_description,
      actions
    ].compact)
  end
end