Class: Plushie::Widget::ComboBox

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

Overview

Combo box -- searchable dropdown with free-form text input.

Props:

  • options (array of strings) -- available choices.
  • selected (string|nil) -- currently selected value.
  • placeholder (string) -- placeholder text.
  • width (length) -- widget width.
  • padding (number|hash) -- internal padding.
  • size (number) -- text size in pixels.
  • font (string|hash) -- font specification.
  • line_height (number|hash) -- text line height.
  • menu_height (number) -- max dropdown menu height in pixels.
  • icon (hash) -- icon inside the text input.
  • on_option_hovered (boolean) -- emit option hover events.
  • on_open (boolean) -- emit open event.
  • on_close (boolean) -- emit close event.
  • shaping (symbol) -- text shaping strategy.
  • ellipsis (string) -- text ellipsis strategy.
  • menu_style (hash) -- dropdown menu style overrides.
  • style (symbol|hash) -- named style or style map.
  • a11y (hash) -- accessibility overrides.

Examples:

cb = Plushie::Widget::ComboBox.new("fruit", ["Apple", "Banana"],
  selected: "Apple", placeholder: "Search...")
node = cb.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[options selected placeholder width padding size font
line_height menu_height icon on_option_hovered on_open on_close
shaping ellipsis menu_style style a11y].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, options = [], **opts) ⇒ ComboBox

Returns a new instance of ComboBox.

Parameters:

  • id (String)

    widget identifier

  • options (Array<String>) (defaults to: [])

    available choices

  • opts (Hash)

    optional properties



45
46
47
48
49
50
# File 'lib/plushie/widget/combo_box.rb', line 45

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

Instance Attribute Details

#a11yObject (readonly)

Returns the value of attribute a11y.



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

def a11y
  @a11y
end

#ellipsisObject (readonly)

Returns the value of attribute ellipsis.



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

def ellipsis
  @ellipsis
end

#fontObject (readonly)

Returns the value of attribute font.



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

def font
  @font
end

#iconObject (readonly)

Returns the value of attribute icon.



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

def icon
  @icon
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#line_heightObject (readonly)

Returns the value of attribute line_height.



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

def line_height
  @line_height
end

Returns the value of attribute menu_height.



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

def menu_height
  @menu_height
end

Returns the value of attribute menu_style.



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

def menu_style
  @menu_style
end

#on_closeObject (readonly)

Returns the value of attribute on_close.



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

def on_close
  @on_close
end

#on_openObject (readonly)

Returns the value of attribute on_open.



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

def on_open
  @on_open
end

#on_option_hoveredObject (readonly)

Returns the value of attribute on_option_hovered.



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

def on_option_hovered
  @on_option_hovered
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#paddingObject (readonly)

Returns the value of attribute padding.



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

def padding
  @padding
end

#placeholderObject (readonly)

Returns the value of attribute placeholder.



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

def placeholder
  @placeholder
end

#selectedObject (readonly)

Returns the value of attribute selected.



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

def selected
  @selected
end

#shapingObject (readonly)

Returns the value of attribute shaping.



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

def shaping
  @shaping
end

#sizeObject (readonly)

Returns the value of attribute size.



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

def size
  @size
end

#styleObject (readonly)

Returns the value of attribute style.



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

def style
  @style
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#buildPlushie::Node

Returns:



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

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