Sha256: 6a731d14967371b127796fed7bf03f0b01f1b2a0efaab0aaedf033764657293a

Contents?: true

Size: 1.18 KB

Versions: 18

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Koi
  module Form
    module Elements
      class Image < GOVUKDesignSystemFormBuilder::Base
        include FileElement

        def initialize(builder, object_name, attribute_name, hint:, label:, caption:, form_group:, mime_types:,
                       **kwargs, &)
          super(builder, object_name, attribute_name, &)

          @mime_types      = mime_types
          @label           = label
          @caption         = caption
          @hint            = hint
          @html_attributes = kwargs.merge(file_input_options)
          @form_group      = form_group
        end

        def preview
          options = {}
          add_option(options, :data, "#{stimulus_controller}_target", "preview")
          add_option(options, :class, "preview-image")
          add_option(options, :class, "hidden") unless preview?

          tag.div(**options) do
            tag.img(src: preview_url, class: "image-thumbnail") + destroy_element_trigger
          end
        end

        private

        def stimulus_controller
          "image-field"
        end

        def form_group_class
          "govuk-image-field"
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
katalyst-koi-4.14.1 lib/koi/form/elements/image.rb
katalyst-koi-4.14.0 lib/koi/form/elements/image.rb
katalyst-koi-4.13.2 lib/koi/form/elements/image.rb
katalyst-koi-4.13.0 lib/koi/form/elements/image.rb
katalyst-koi-4.12.6 lib/koi/form/elements/image.rb
katalyst-koi-4.12.5 lib/koi/form/elements/image.rb
katalyst-koi-4.12.4 lib/koi/form/elements/image.rb
katalyst-koi-4.12.3 lib/koi/form/elements/image.rb
katalyst-koi-4.12.2 lib/koi/form/elements/image.rb
katalyst-koi-4.12.1 lib/koi/form/elements/image.rb
katalyst-koi-4.12.0 lib/koi/form/elements/image.rb
katalyst-koi-4.11.2 lib/koi/form/elements/image.rb
katalyst-koi-4.11.1 lib/koi/form/elements/image.rb
katalyst-koi-4.11.0 lib/koi/form/elements/image.rb
katalyst-koi-4.10.3 lib/koi/form/elements/image.rb
katalyst-koi-4.10.2 lib/koi/form/elements/image.rb
katalyst-koi-4.10.1 lib/koi/form/elements/image.rb
katalyst-koi-4.10.0 lib/koi/form/elements/image.rb