Class: Plushie::Widget::TextInput

Inherits:
Object
  • Object
show all
Defined in:
lib/plushie/widget/text_input.rb

Overview

Typed builder for the single-line text input widget (Layer 2 API).

Construct a TextInput, configure via fluent +set_*+ methods, then call #build to produce a Node.

PROPS: value, placeholder, padding, width, size, font, line_height, align_x, icon, on_submit, on_paste, secure, ime_purpose, style, placeholder_color, selection_color, a11y.

Examples:

TextInput.new("email", "", placeholder: "[email protected]")
  .set_size(16)
  .build

Constant Summary collapse

PROPS =

Supported property keys for the text input widget.

%i[value placeholder padding width size font line_height align_x
icon on_submit on_paste secure ime_purpose style
placeholder_color selection_color a11y].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, value = "", **opts) ⇒ TextInput

Returns a new instance of TextInput.

Parameters:

  • id (String)

    widget identifier

  • value (String) (defaults to: "")

    initial text value

  • opts (Hash)

    optional properties matching PROPS keys



31
32
33
34
35
36
# File 'lib/plushie/widget/text_input.rb', line 31

def initialize(id, value = "", **opts)
  @id = id.to_s
  @value = value
  PROPS.each { |k| instance_variable_set(:"@#{k}", opts[k]) if opts.key?(k) }
  @value = opts[:value] if opts.key?(:value)
end

Instance Attribute Details

#a11yObject (readonly)

Returns the value of attribute a11y.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def a11y
  @a11y
end

#align_xObject (readonly)

Returns the value of attribute align_x.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def align_x
  @align_x
end

#fontObject (readonly)

Returns the value of attribute font.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def font
  @font
end

#iconObject (readonly)

Returns the value of attribute icon.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def icon
  @icon
end

#idObject (readonly)

Returns the value of attribute id.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def id
  @id
end

#ime_purposeObject (readonly)

Returns the value of attribute ime_purpose.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def ime_purpose
  @ime_purpose
end

#line_heightObject (readonly)

Returns the value of attribute line_height.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def line_height
  @line_height
end

#on_pasteObject (readonly)

Returns the value of attribute on_paste.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def on_paste
  @on_paste
end

#on_submitObject (readonly)

Returns the value of attribute on_submit.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def on_submit
  @on_submit
end

#paddingObject (readonly)

Returns the value of attribute padding.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def padding
  @padding
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def placeholder
  @placeholder
end

#placeholder_colorObject (readonly)

Returns the value of attribute placeholder_color.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def placeholder_color
  @placeholder_color
end

#secureObject (readonly)

Returns the value of attribute secure.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def secure
  @secure
end

#selection_colorObject (readonly)

Returns the value of attribute selection_color.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def selection_color
  @selection_color
end

#sizeObject (readonly)

Returns the value of attribute size.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def size
  @size
end

#styleObject (readonly)

Returns the value of attribute style.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def style
  @style
end

#valueObject (readonly)

Returns the value of attribute value.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def value
  @value
end

#widthObject (readonly)

Returns the value of attribute width.



1
2
3
# File 'lib/plushie/widget/text_input.rb', line 1

def width
  @width
end

Instance Method Details

#buildPlushie::Node

Build a Node from the current property values.

Returns:



47
48
49
50
51
52
53
54
# File 'lib/plushie/widget/text_input.rb', line 47

def build
  props = {}
  PROPS.each do |key|
    val = instance_variable_get(:"@#{key}")
    Build.put_if(props, key, val)
  end
  Node.new(id: @id, type: "text_input", props: props)
end