Class: Fluxbit::Form::UploadImageComponent
- Inherits:
-
FieldComponent
- Object
- FieldComponent
- Fluxbit::Form::UploadImageComponent
- Defined in:
- app/components/fluxbit/form/upload_image_component.rb
Overview
The ‘Fluxbit::Form::UploadImageComponent` renders a stylized image upload field with live preview, drag-and-drop UI, support for both mobile and desktop layouts, labels, helper text, and integration with Rails form builders and Active Storage attachments. It provides custom title/subtitle, placeholder, and image preview, and is fully configurable via props.
Instance Method Summary collapse
- #image_element ⇒ Object
-
#initialize(**props) ⇒ UploadImageComponent
constructor
Initializes the upload image component with the given properties.
- #input_element(input_id: nil) ⇒ Object
Constructor Details
#initialize(**props) ⇒ UploadImageComponent
Initializes the upload image component with the given properties.
27 28 29 30 31 32 33 34 35 36 |
# File 'app/components/fluxbit/form/upload_image_component.rb', line 27 def initialize(**props) super(**props) @title = @props.delete(:title) || "Change" @image_path = @props.delete(:image_path) || (if @object&.send(@attribute).respond_to?(:attached?) && @object&.send(@attribute)&.send("attached?") @object&.send(@attribute)&.variant(resize_to_fit: [ 160, 160 ]) end) || @props.delete(:image_placeholder) || "" @props["class"] = "absolute inset-0 h-full w-full cursor-pointer rounded-md border-gray-300 opacity-0" end |
Instance Method Details
#image_element ⇒ Object
45 46 47 48 49 |
# File 'app/components/fluxbit/form/upload_image_component.rb', line 45 def image_element image_tag @image_path, class: "img_photo_#{id} img_photo absolute inset-0 w-full h-full object-cover rounded-full", alt: @attribute&.to_s&.humanize end |
#input_element(input_id: nil) ⇒ Object
38 39 40 41 42 43 |
# File 'app/components/fluxbit/form/upload_image_component.rb', line 38 def input_element(input_id: nil) @props["onchange"] = "loadFile(event, '#{id}')" return file_field_tag @name, @props.merge(id: input_id || id) if @form.nil? @form.file_field(@attribute, **@props, id: input_id || id) end |