Sha256: d049c40d3fac95003b571345917ef38475005ad2273555aa23a746f5a016a68a

Contents?: true

Size: 1.88 KB

Versions: 14

Compression:

Stored size: 1.88 KB

Contents

require_relative 'input'

module Voom
  module Presenters
    module DSL
      module Components
        class TextField < Input

          attr_reader :required, :full_width, :password

          def initialize(**attribs_, &block)
            super(type: :text_field, **attribs_, &block)
            @required = attribs.delete(:required)
            @full_width = attribs.delete(:full_width){ true }
            @password = attribs.delete(:password)
            expand!
          end

          def label(text=nil)
            return @label if locked?
            @label = text
          end

          def icon(icon=nil, **attribs, &block)
            return @icon if locked?
            @icon = Components::Icon.new(parent: self, icon: icon,
                                         context: context,
                                         **attribs, &block)
          end

          def value(value=nil)
            return @value if locked?
            @value = value
          end

          def pattern(pattern=nil)
            return @pattern if locked?
            @pattern = json_regexp(Regexp.new(pattern))
          end

          def hint(hint=nil)
            return @hint if locked?
            @hint = hint
          end

          def error(error=nil)
            return @error if locked?
            @error = error
          end

          def readonly(readonly=nil)
            return @readonly if locked?
            @readonly = readonly
          end

          private
          def json_regexp(regexp)
            str = regexp.inspect.
                sub('\\A', '^').
                sub('\\Z', '$').
                sub('\\z', '$').
                sub(/^\//, '').
                sub(/\/[a-z]*$/, '').
                gsub(/\(\?#.+\)/, '').
                gsub(/\(\?-\w+:/, '(').
                gsub(/\s/, '')
            Regexp.new(str).source
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
voom-presenters-0.1.13 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.12 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.11 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.10 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.9 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.8 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.7 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.6 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.5 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.4 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.3 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.2 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.1 lib/voom/presenters/dsl/components/text_field.rb
voom-presenters-0.1.0 lib/voom/presenters/dsl/components/text_field.rb