Class: CCS::Components::GovUK::Field::Input::FileUpload
- Inherits:
-
CCS::Components::GovUK::Field::Input
- Object
- Base
- CCS::Components::GovUK::Field
- CCS::Components::GovUK::Field::Input
- CCS::Components::GovUK::Field::Input::FileUpload
- Defined in:
- lib/ccs/components/govuk/field/input/file_upload.rb
Overview
GOV.UK File Upload
This is used for generating the file upload component from the GDS - Components - File Upload
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
The default attributes for the file upload
{ class: 'govuk-file-upload' }.freeze
Instance Method Summary collapse
-
#initialize(attribute:, javascript: false) ⇒ FileUpload
constructor
A new instance of FileUpload.
-
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK File Upload component.
Constructor Details
#initialize(attribute:, javascript: false) ⇒ FileUpload
Returns a new instance of FileUpload.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ccs/components/govuk/field/input/file_upload.rb', line 30 def initialize(attribute:, javascript: false, **) super(attribute: attribute, **) @javascript = javascript return unless javascript @file_upload_javascript_options = { class: 'govuk-drop-zone', data: { module: 'govuk-file-upload' } } %i[choose_files_button no_file_chosen multiple_files_chosen drop_instruction entered_drop_zone left_drop_zone].each do |data_attribute| data_attribute_name = :"#{data_attribute}_text" if [data_attribute_name] if [data_attribute_name].is_a? Hash [data_attribute_name].each do |key, value| @file_upload_javascript_options[:data][:"i18n.#{data_attribute.to_s.gsub('_', '-')}.#{key}"] = value end else @file_upload_javascript_options[:data][:"i18n.#{data_attribute.to_s.gsub('_', '-')}"] = [data_attribute_name] end end end end |
Instance Method Details
#render ⇒ ActiveSupport::SafeBuffer
Generates the HTML for the GOV.UK File Upload component
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ccs/components/govuk/field/input/file_upload.rb', line 66 def render super do javascript_wrapper do if [:form] [:form].file_field(attribute, **[:attributes]) else context.file_field_tag(attribute, **[:attributes]) end end end end |