Sha256: 9d5974ef8e2f6af214a5ac2e05b247c99c8208fd5677be7c6d347aea36ad43a9

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

module Coco
  module App
    module Elements
      class SeamlessTextarea < Coco::Component
        include TagHelper
        include Concerns::WrapsComponent
        include Concerns::AcceptsOptions

        wraps_component :textarea

        accepts_option :multiline, from: [true, false]

        attr_reader :name, :id

        def initialize(name:, value: nil, id: nil, placeholder: nil, textarea: nil, form_builder: nil, **kwargs)
          @name = name
          @value = value
          @form_builder = form_builder
          @textarea_args = textarea.to_h
          @textarea_args[:id] = id
          @textarea_args[:placeholder] = placeholder
        end

        def multiline?
          get_option_value(:multiline)
        end

        def value
          (@value.presence || content.presence || "").strip_heredoc.strip
        end

        def text_area(**html_args)
          args = @textarea_args.merge(html_args.compact)

          if @form_builder
            @form_builder.text_area(name, value: value, **args)
          else
            text_area_tag(name, value, **args)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coveragebook_components-0.5.0 app/components/coco/app/elements/seamless_textarea/seamless_textarea.rb