Class: DaisyUI::Card::Actions

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/daisy_ui/data_display/card/actions.rb

Overview

Actions component for the card, handling action buttons layout

Examples:

Basic usage

<%= render(CardComponent.new) do |component| %>
  <% component.with_body do |body| %>
    <% body.with_actions do %>
      <%= render(ButtonComponent.new(text: "Action")) %>
    <% end %>
  <% end %>
<% end %>

With multiple buttons

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

With custom buttons

<%= render(CardComponent.new) do |component| %>
  <% component.with_body do |body| %>
    <% body.with_actions(justify: :end) do %>
      <%= render(ButtonComponent.new(text: "Delete", color: :error)) %>
      <%= render(ButtonComponent.new(text: "Save", color: :primary)) %>
    <% end %>
  <% end %>
<% end %>

Constant Summary collapse

JUSTIFY_OPTIONS =

Available justification options for actions layout

{
  start: 'justify-start',
  end: 'justify-end',
  center: 'justify-center',
  between: 'justify-between',
  around: 'justify-around',
  evenly: 'justify-evenly'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(justify: nil, **system_arguments) ⇒ Actions

Returns a new instance of Actions.

Parameters:

  • justify (Symbol) (defaults to: nil)

    Justification for action buttons layout

  • system_arguments (Hash)

    Additional HTML attributes



54
55
56
57
# File 'app/components/daisy_ui/data_display/card/actions.rb', line 54

def initialize(justify: nil, **system_arguments)
  @justify = build_justify(justify)
  super(**system_arguments)
end

Instance Method Details

#callObject



59
60
61
62
63
64
65
66
67
# File 'app/components/daisy_ui/data_display/card/actions.rb', line 59

def call
  tag.div(**html_attributes) do
    if actions.any?
      safe_join(actions)
    else
      content
    end
  end
end