Sha256: 37390d4c54d2b5a3f4762bd14ca8eea9122734a548a405b1de0fd6119e5437d4

Contents?: true

Size: 1.67 KB

Versions: 20

Compression:

Stored size: 1.67 KB

Contents

require_relative '../text_input'

module CCS
  module Components
    module GovUK
      class Field < Base
        class Input < Field
          class TextInput < Input
            # = GOV.UK Text Input prefix/suffix
            #
            # This is used to generate the prefix/suffix HTML for a text input
            #
            # @!attribute [r] text
            #   @return [String] Text for the prefix/suffix

            class Fix < Base
              private

              attr_reader :text

              public

              # @param text [String] the text for the prefix/suffix
              # @param fix [String] either +"pre"+ or +"suf"+
              #
              # @param options [Hash] options that will be used in customising the HTML
              #
              # @option options [String] :classes additional CSS classes for the prefix/suffix HTML
              # @option options [Hash] :attributes ({}) any additional attributes that will added as part of the HTML

              def initialize(text:, fix:, **options)
                super(**options)

                @options[:attributes][:class] = "govuk-input__#{fix}fix #{@options[:attributes][:class]}".rstrip
                (@options[:attributes][:aria] ||= {})[:hidden] = true

                @text = text
              end

              # Generates the HTML for the GOV.UK Text Input prefix/suffix
              #
              # @yield (see CCS::Components::GovUK::Field#render)
              #
              # @return [ActiveSupport::SafeBuffer]

              def render
                tag.div(text, **options[:attributes])
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ccs-frontend_helpers-2.1.0 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-2.0.0 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-1.2.0 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-1.1.2 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-1.1.1 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-1.1.0 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-1.1.0.beta0 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-1.0.0 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-0.5.0.beta1 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-0.5.0.beta0 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-0.3.0 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-0.2.0 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-0.1.2 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-0.1.1 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-0.1.1.rc.1 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-0.1.0.rc.7 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-0.1.0.rc.6 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-0.1.0.rc.5 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-0.1.0.rc.4 lib/ccs/components/govuk/field/input/text_input/fix.rb
ccs-frontend_helpers-0.1.0.rc.3 lib/ccs/components/govuk/field/input/text_input/fix.rb