Class: Voom::Presenters::DSL::Components::Select

Inherits:
Input show all
Defined in:
lib/voom/presenters/dsl/components/select.rb

Direct Known Subclasses

MultiSelect

Defined Under Namespace

Classes: Option

Instance Attribute Summary collapse

Attributes inherited from Input

#dirtyable, #disabled, #name

Attributes inherited from EventBase

#event_parent_id

Attributes included from Mixins::Event

#events

Attributes inherited from Base

#attributes, #css_class, #draggable, #drop_zone, #id, #tag, #type

Instance Method Summary collapse

Methods inherited from Input

#validation_error

Methods included from Mixins::Tooltips

#tooltip

Methods included from Mixins::Event

#event

Methods inherited from Base

#expand!

Methods included from Pluggable

#include_plugins, #plugin, #plugin_module

Methods included from Mixins::YieldTo

#yield_to

Methods included from Serializer

#to_hash

Methods included from Lockable

#locked?

Constructor Details

#initialize(**attribs_, &block) ⇒ Select

Returns a new instance of Select.



9
10
11
12
13
14
15
16
# File 'lib/voom/presenters/dsl/components/select.rb', line 9

def initialize(**attribs_, &block)
  super(type: :select, **attribs_, &block)
  @required = attribs.delete(:required)
  @full_width = attribs.delete(:full_width){ true }
  @outlined = attribs.delete(:outlined){ true }
  @options = []
  expand!
end

Instance Attribute Details

#full_widthObject (readonly)

Returns the value of attribute full_width.



7
8
9
# File 'lib/voom/presenters/dsl/components/select.rb', line 7

def full_width
  @full_width
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/voom/presenters/dsl/components/select.rb', line 7

def options
  @options
end

#outlinedObject (readonly)

Returns the value of attribute outlined.



7
8
9
# File 'lib/voom/presenters/dsl/components/select.rb', line 7

def outlined
  @outlined
end

#requiredObject (readonly)

Returns the value of attribute required.



7
8
9
# File 'lib/voom/presenters/dsl/components/select.rb', line 7

def required
  @required
end

Instance Method Details

#hint(hint = nil) ⇒ Object



33
34
35
36
# File 'lib/voom/presenters/dsl/components/select.rb', line 33

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

#icon(icon = nil, **attribs, &block) ⇒ Object



38
39
40
41
42
# File 'lib/voom/presenters/dsl/components/select.rb', line 38

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

#label(text = nil) ⇒ Object



18
19
20
21
# File 'lib/voom/presenters/dsl/components/select.rb', line 18

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

#option(text = nil, **attribs, &block) ⇒ Object



23
24
25
26
27
# File 'lib/voom/presenters/dsl/components/select.rb', line 23

def option(text=nil, **attribs, &block)
  @options << Option.new(parent: self,
                         text: text,
                         **attribs, &block)
end

#valueObject



29
30
31
# File 'lib/voom/presenters/dsl/components/select.rb', line 29

def value
  @options.select(&:_selected?).first&.value
end