Class: Plushie::Widget::TextEditor

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

Overview

Text editor -- multi-line editable text area.

Props:

  • content (string) -- initial text content.
  • placeholder (string) -- placeholder text.
  • width (length) -- editor width.
  • height (length) -- editor height.
  • min_height (number) -- minimum height in pixels.
  • max_height (number) -- maximum height in pixels.
  • font (string|hash) -- font specification.
  • size (number) -- font size in pixels.
  • line_height (number|hash) -- line height.
  • padding (number) -- uniform padding in pixels.
  • wrapping (symbol) -- text wrapping mode.
  • ime_purpose (string) -- IME input purpose: "normal", "secure", "terminal".
  • highlight_syntax (string) -- language for syntax highlighting.
  • highlight_theme (string) -- highlighter theme.
  • style (symbol|hash) -- named style or style map.
  • key_bindings (array of hashes) -- declarative key binding rules.
  • placeholder_color (string) -- placeholder text color.
  • selection_color (string) -- selection highlight color.
  • a11y (hash) -- accessibility overrides.

Examples:

ed = Plushie::Widget::TextEditor.new("editor",
  content: "Hello", placeholder: "Type here...")
node = ed.build

Constant Summary collapse

PROPS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Supported property keys for this widget.

%i[content placeholder width height min_height max_height font
size line_height padding wrapping ime_purpose highlight_syntax
highlight_theme style key_bindings placeholder_color selection_color
a11y].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, **opts) ⇒ TextEditor

Returns a new instance of TextEditor.

Parameters:

  • id (String)

    widget identifier

  • opts (Hash)

    optional properties



46
47
48
49
# File 'lib/plushie/widget/text_editor.rb', line 46

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

Instance Attribute Details

#a11yObject (readonly)

Returns the value of attribute a11y.



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

def a11y
  @a11y
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#fontObject (readonly)

Returns the value of attribute font.



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

def font
  @font
end

#heightObject (readonly)

Returns the value of attribute height.



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

def height
  @height
end

#highlight_syntaxObject (readonly)

Returns the value of attribute highlight_syntax.



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

def highlight_syntax
  @highlight_syntax
end

#highlight_themeObject (readonly)

Returns the value of attribute highlight_theme.



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

def highlight_theme
  @highlight_theme
end

#idObject (readonly)

Returns the value of attribute id.



1
2
3
# File 'lib/plushie/widget/text_editor.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_editor.rb', line 1

def ime_purpose
  @ime_purpose
end

#key_bindingsObject (readonly)

Returns the value of attribute key_bindings.



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

def key_bindings
  @key_bindings
end

#line_heightObject (readonly)

Returns the value of attribute line_height.



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

def line_height
  @line_height
end

#max_heightObject (readonly)

Returns the value of attribute max_height.



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

def max_height
  @max_height
end

#min_heightObject (readonly)

Returns the value of attribute min_height.



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

def min_height
  @min_height
end

#paddingObject (readonly)

Returns the value of attribute padding.



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

def padding
  @padding
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



1
2
3
# File 'lib/plushie/widget/text_editor.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_editor.rb', line 1

def placeholder_color
  @placeholder_color
end

#selection_colorObject (readonly)

Returns the value of attribute selection_color.



1
2
3
# File 'lib/plushie/widget/text_editor.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_editor.rb', line 1

def size
  @size
end

#styleObject (readonly)

Returns the value of attribute style.



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

def style
  @style
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

#wrappingObject (readonly)

Returns the value of attribute wrapping.



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

def wrapping
  @wrapping
end

Instance Method Details

#buildPlushie::Node

Returns:



58
59
60
61
62
63
64
65
# File 'lib/plushie/widget/text_editor.rb', line 58

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_editor", props: props)
end