Sha256: 436427295a4cef6c61944e680d0e9d1c10d50a34f4d8bd8ef353b49615b51b23

Contents?: true

Size: 1.74 KB

Versions: 10

Compression:

Stored size: 1.74 KB

Contents

require_relative '../input'

module CCS
  module Components
    module GovUK
      class Field < Base
        class Input < Field
          # = GOV.UK Textarea
          #
          # This helper is used for generating the textarea component from the
          # {https://design-system.service.gov.uk/components/textarea GDS - Components - Textarea}
          #
          # @!attribute [r] content
          #   @return [String] The content of the textarea

          class Textarea < Input
            private

            attr_reader :content

            public

            # @param (see CCS::Components::GovUK::Field::Input#initialize)
            # @param content [String] the content of the textarea
            # @param rows [Integer] the number of rows for the text area
            #
            # @option (see CCS::Components::GovUK::Field::Input#initialize)

            def initialize(attribute:, content: nil, rows: 5, **options)
              super(attribute: attribute, **options)

              @options[:attributes][:rows] ||= rows

              @content = @options[:model] ? @options[:model].send(attribute) : content
            end

            # Generates the HTML for the GOV.UK Textarea component
            #
            # @return [ActiveSupport::SafeBuffer]

            def render
              super() do
                if options[:form]
                  options[:form].text_area(attribute, **options[:attributes])
                else
                  context.text_area_tag(attribute, content, **options[:attributes])
                end
              end
            end

            # The default attributes for the textarea

            DEFAULT_ATTRIBUTES = { class: 'govuk-textarea' }.freeze
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ccs-frontend_helpers-0.3.0 lib/ccs/components/govuk/field/input/textarea.rb
ccs-frontend_helpers-0.2.0 lib/ccs/components/govuk/field/input/textarea.rb
ccs-frontend_helpers-0.1.2 lib/ccs/components/govuk/field/input/textarea.rb
ccs-frontend_helpers-0.1.1 lib/ccs/components/govuk/field/input/textarea.rb
ccs-frontend_helpers-0.1.1.rc.1 lib/ccs/components/govuk/field/input/textarea.rb
ccs-frontend_helpers-0.1.0.rc.7 lib/ccs/components/govuk/field/input/textarea.rb
ccs-frontend_helpers-0.1.0.rc.6 lib/ccs/components/govuk/field/input/textarea.rb
ccs-frontend_helpers-0.1.0.rc.5 lib/ccs/components/govuk/field/input/textarea.rb
ccs-frontend_helpers-0.1.0.rc.4 lib/ccs/components/govuk/field/input/textarea.rb
ccs-frontend_helpers-0.1.0.rc.3 lib/ccs/components/govuk/field/input/textarea.rb