Class: Panda::Core::Admin::FormFooterComponent

Inherits:
Base
  • Object
show all
Defined in:
app/components/panda/core/admin/form_footer_component.rb

Overview

Standardized form footer component with submit button(s) and optional secondary actions.

Examples:

Basic usage

<%= render Panda::Core::Admin::FormFooterComponent.new(submit_text: "Save") %>

With icon

<%= render Panda::Core::Admin::FormFooterComponent.new(
  submit_text: "Create Page",
  icon: "fa-plus"
) %>

With cancel link

<%= render Panda::Core::Admin::FormFooterComponent.new(
  submit_text: "Update",
  cancel_path: admin_cms_pages_path
) %>

With block for custom secondary actions

<%= render Panda::Core::Admin::FormFooterComponent.new(submit_text: "Save") do %>
  <%= link_to "Preview", preview_path, class: "text-sm text-gray-600" %>
<% end %>

Constant Summary

Constants inherited from Base

Base::TAILWIND_MERGER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(submit_text: "Save", icon: nil, cancel_path: nil, submit_action: nil, **attrs) ⇒ FormFooterComponent

Returns a new instance of FormFooterComponent.



29
30
31
32
33
34
35
# File 'app/components/panda/core/admin/form_footer_component.rb', line 29

def initialize(submit_text: "Save", icon: nil, cancel_path: nil, submit_action: nil, **attrs)
  @submit_text = submit_text
  @icon = icon
  @cancel_path = cancel_path
  @submit_action = submit_action
  super(**attrs)
end

Instance Attribute Details

#cancel_pathObject (readonly)

Returns the value of attribute cancel_path.



37
38
39
# File 'app/components/panda/core/admin/form_footer_component.rb', line 37

def cancel_path
  @cancel_path
end

#iconObject (readonly)

Returns the value of attribute icon.



37
38
39
# File 'app/components/panda/core/admin/form_footer_component.rb', line 37

def icon
  @icon
end

#submit_actionObject (readonly)

Returns the value of attribute submit_action.



37
38
39
# File 'app/components/panda/core/admin/form_footer_component.rb', line 37

def submit_action
  @submit_action
end

#submit_textObject (readonly)

Returns the value of attribute submit_text.



37
38
39
# File 'app/components/panda/core/admin/form_footer_component.rb', line 37

def submit_text
  @submit_text
end

Instance Method Details



49
50
51
# File 'app/components/panda/core/admin/form_footer_component.rb', line 49

def cancel_link_classes
  "inline-flex items-center justify-center rounded-xl px-3 py-2 text-sm font-medium text-gray-600 hover:text-gray-900"
end

#computed_iconObject



53
54
55
# File 'app/components/panda/core/admin/form_footer_component.rb', line 53

def computed_icon
  @icon
end

#default_attrsObject



39
40
41
42
43
# File 'app/components/panda/core/admin/form_footer_component.rb', line 39

def default_attrs
  {
    class: "flex justify-end gap-x-3 mt-2"
  }
end

#submit_button_classesObject



45
46
47
# File 'app/components/panda/core/admin/form_footer_component.rb', line 45

def submit_button_classes
  "inline-flex items-center gap-x-2 justify-center rounded-xl bg-primary-500 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-primary-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary-600 cursor-pointer"
end

#submit_data_attrsObject



57
58
59
60
61
# File 'app/components/panda/core/admin/form_footer_component.rb', line 57

def submit_data_attrs
  attrs = {disable_with: "Saving..."}
  attrs[:action] = submit_action if submit_action
  attrs
end