Class: Panda::Core::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Panda::Core::FormBuilder
- Includes:
- ActionView::Helpers::FormTagHelper, ActionView::Helpers::TagHelper
- Defined in:
- app/builders/panda/core/form_builder.rb
Instance Method Summary collapse
- #button(value = nil, options = {}, &block) ⇒ Object
- #check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
- #collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
- #date_field(method, options = {}) ⇒ Object
- #datetime_field(method, options = {}) ⇒ Object
- #email_field(method, options = {}) ⇒ Object
- #file_field(method, options = {}) ⇒ Object
- #label(attribute, text = nil, options = {}) ⇒ Object
- #meta_text(options) ⇒ Object
- #password_field(attribute, options = {}) ⇒ Object
- #select(method, choices = nil, options = {}, html_options = {}) ⇒ Object
- #submit(value = nil, options = {}) ⇒ Object
- #text_area(method, options = {}) ⇒ Object
- #text_field(attribute, options = {}) ⇒ Object
- #time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
Instance Method Details
#button(value = nil, options = {}, &block) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/builders/panda/core/form_builder.rb', line 85 def (value = nil, = {}, &block) value ||= submit_default_value = .dup # Handle formmethod specially if [:formmethod] == "delete" [:name] = "_method" [:value] = "delete" end base_classes = [ "inline-flex items-center rounded-md", "px-3 py-2", "text-base font-semibold", "shadow-sm" ] # Only add fa-circle-check for non-block buttons base_classes << "fa-circle-check" unless block_given? [:class] = [ *base_classes, [:class] ].compact.join(" ") if block_given? @template.(, &block) else @template.(value, ) end end |
#check_box(method, options = {}, checked_value = "1", unchecked_value = "0") ⇒ Object
141 142 143 144 145 |
# File 'app/builders/panda/core/form_builder.rb', line 141 def check_box(method, = {}, checked_value = "1", unchecked_value = "0") content_tag :div, class: container_styles do label(method) + () + super(method, .reverse_merge(class: "border-gray-300 ml-2"), checked_value, unchecked_value) end end |
#collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) ⇒ Object
62 63 64 65 66 |
# File 'app/builders/panda/core/form_builder.rb', line 62 def collection_select(method, collection, value_method, text_method, = {}, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, collection, value_method, text_method, , .reverse_merge(class: input_styles)) + (method) end end |
#date_field(method, options = {}) ⇒ Object
147 148 149 150 151 |
# File 'app/builders/panda/core/form_builder.rb', line 147 def date_field(method, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, .reverse_merge(class: input_styles)) end end |
#datetime_field(method, options = {}) ⇒ Object
38 39 40 41 42 |
# File 'app/builders/panda/core/form_builder.rb', line 38 def datetime_field(method, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, .reverse_merge(class: input_styles)) + (method) end end |
#email_field(method, options = {}) ⇒ Object
32 33 34 35 36 |
# File 'app/builders/panda/core/form_builder.rb', line 32 def email_field(method, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, .reverse_merge(class: input_styles)) + (method) end end |
#file_field(method, options = {}) ⇒ Object
79 80 81 82 83 |
# File 'app/builders/panda/core/form_builder.rb', line 79 def file_field(method, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, .reverse_merge(class: "file:rounded file:border-0 file:text-sm file:bg-white file:text-gray-500 hover:file:bg-gray-50 bg-white px-2.5 hover:bg-gray-50".concat(input_styles))) end end |
#label(attribute, text = nil, options = {}) ⇒ Object
9 10 11 |
# File 'app/builders/panda/core/form_builder.rb', line 9 def label(attribute, text = nil, = {}) super(attribute, text, .reverse_merge(class: label_styles)) end |
#meta_text(options) ⇒ Object
153 154 155 156 157 |
# File 'app/builders/panda/core/form_builder.rb', line 153 def () return unless [:meta] @template.content_tag(:p, [:meta], class: "block text-black/60 text-sm mb-2") end |
#password_field(attribute, options = {}) ⇒ Object
50 51 52 53 54 |
# File 'app/builders/panda/core/form_builder.rb', line 50 def password_field(attribute, = {}) content_tag :div, class: container_styles do label(attribute) + () + super(attribute, .reverse_merge(class: input_styles)) + (attribute) end end |
#select(method, choices = nil, options = {}, html_options = {}) ⇒ Object
56 57 58 59 60 |
# File 'app/builders/panda/core/form_builder.rb', line 56 def select(method, choices = nil, = {}, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, choices, , .reverse_merge(class: select_styles)) + select_svg + (method) end end |
#submit(value = nil, options = {}) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/builders/panda/core/form_builder.rb', line 117 def submit(value = nil, = {}) value ||= submit_default_value # Use the same style logic as ButtonComponent action = object.persisted? ? :save : :create = case action when :save, :create "text-white bg-green-600 hover:bg-green-700" when :save_inactive "text-white bg-gray-400" when :secondary "text-gray-700 border-2 border-gray-500 bg-transparent hover:bg-gray-100 transition-all" else "text-gray-700 border-2 border-gray-500 bg-transparent hover:bg-gray-100 transition-all" end # Combine with common button classes classes = "inline-flex items-center rounded-md font-medium shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 px-3 py-2 #{}" [:class] = [:class] ? "#{[:class]} #{classes}" : classes super end |
#text_area(method, options = {}) ⇒ Object
44 45 46 47 48 |
# File 'app/builders/panda/core/form_builder.rb', line 44 def text_area(method, = {}) content_tag :div, class: container_styles do label(method) + () + super(method, .reverse_merge(class: input_styles)) + (method) end end |
#text_field(attribute, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/builders/panda/core/form_builder.rb', line 13 def text_field(attribute, = {}) if .dig(:data, :prefix) content_tag :div, class: container_styles do label(attribute) + () + content_tag(:div, class: "flex flex-grow") do content_tag(:span, class: "inline-flex items-center px-3 text-base border border-r-none rounded-s-md whitespace-nowrap break-keep") do .dig(:data, :prefix) end + super(attribute, .reverse_merge(class: "#{input_styles_prefix} input-prefix rounded-l-none border-l-none")) end + (attribute) end else content_tag :div, class: container_styles do label(attribute) + () + super(attribute, .reverse_merge(class: input_styles)) + (attribute) end end end |
#time_zone_select(method, priority_zones = nil, options = {}, html_options = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'app/builders/panda/core/form_builder.rb', line 68 def time_zone_select(method, priority_zones = nil, = {}, = {}) wrap_field(method, ) do super( method, priority_zones, , .reverse_merge(class: select_styles) ) end end |