Class: Maquina::Application::Components::FileComponent

Inherits:
ComponentBase
  • Object
show all
Includes:
Phlex::Rails::Helpers::NumberToHumanSize, Phlex::Rails::Helpers::TokenList
Defined in:
app/views/maquina/application/components/file_component.rb

Instance Method Summary collapse

Methods inherited from ComponentBase

#initialize

Methods included from Maquina::ApplicationView

#attribute_human_name, #button_to, #image_tag, #link_to, #model_human_name, #svg_icon

Constructor Details

This class inherits a constructor from Maquina::Application::Components::ComponentBase

Instance Method Details

#view_templateObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/views/maquina/application/components/file_component.rb', line 12

def view_template
  div(**extend_control_options(control_html)) do
    @form.label attribute_name, class: "label #{label_css_class}"
    div(class: "mt-1") do
      div(data_file_target: "container") do
        @form.file_field attribute_name, **extend_input_options(input_html(no_helpers: true))
        img(class: token_list("", hidden: !attached_file?), data_file_target: "preview", src: attached_url)
        svg(viewbox: "0 0 24 24", fill: "currentColor", class: token_list("", hidden: attached_file?), aria_hidden: "true", data_action: "click->file#select", data_file_target: "placeholder") do |s|
          s.path(fill_rule: "evenodd", d: "M1.5 6a2.25 2.25 0 012.25-2.25h16.5A2.25 2.25 0 0122.5 6v12a2.25 2.25 0 01-2.25 2.25H3.75A2.25 2.25 0 011.5 18V6zM3 16.06V18c0 .414.336.75.75.75h16.5A.75.75 0 0021 18v-1.94l-2.69-2.689a1.5 1.5 0 00-2.12 0l-.88.879.97.97a.75.75 0 11-1.06 1.06l-5.16-5.159a1.5 1.5 0 00-2.12 0L3 16.061zm10.125-7.81a1.125 1.125 0 112.25 0 1.125 1.125 0 01-2.25 0z", clip_rule: "evenodd")
        end
        p(class: "text-skin-muted pb-4 pt-2 italic text-sm") { attached_info } if attached_file?
        help_template
        error_template
      end
    end
  end
end