Class: Voom::Presenters::DSL::Components::Button

Inherits:
EventBase
  • Object
show all
Includes:
Mixins::Tooltips
Defined in:
lib/voom/presenters/dsl/components/button.rb

Constant Summary collapse

BUTTON_TYPES =
%i(raised flat fab icon)

Instance Attribute Summary collapse

Attributes inherited from EventBase

#event_parent_id

Attributes included from Mixins::Event

#events

Attributes inherited from Base

#attributes, #context, #id, #type

Instance Method Summary collapse

Methods included from Mixins::Tooltips

#tooltip

Methods included from Mixins::Event

#event

Methods inherited from Base

#expand!

Methods included from Mixins::YieldTo

#yield_to

Methods included from Serializer

#to_hash

Methods included from Lockable

#lock!, #locked?

Constructor Details

#initialize(type: nil, **attribs_, &block) ⇒ Button

Returns a new instance of Button.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/voom/presenters/dsl/components/button.rb', line 15

def initialize(type: nil, **attribs_, &block)
  @button_type = h(type) || ((attribs_[:icon]&&!attribs_[:text]) ? :icon : nil) || :flat
  super(type: :button, **attribs_, &block)
  self.icon(attribs.delete(:icon)) if attribs.key?(:icon)
  @text = attribs.delete(:text)
  @color = attribs.delete(:color)
  @disabled = attribs.delete(:disabled) || false
  @size = attribs.delete(:size)
  @position = Array(attribs.delete(:position)).compact
  expand!
  @event_parent_id = self.parent(:form)&.id || id
end

Instance Attribute Details

#button_typeObject

Returns the value of attribute button_type.



13
14
15
# File 'lib/voom/presenters/dsl/components/button.rb', line 13

def button_type
  @button_type
end

#colorObject

Returns the value of attribute color.



13
14
15
# File 'lib/voom/presenters/dsl/components/button.rb', line 13

def color
  @color
end

#disabledObject

Returns the value of attribute disabled.



13
14
15
# File 'lib/voom/presenters/dsl/components/button.rb', line 13

def disabled
  @disabled
end

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

Returns the value of attribute icon.



13
14
15
# File 'lib/voom/presenters/dsl/components/button.rb', line 13

def icon
  @icon
end

#positionObject

Returns the value of attribute position.



13
14
15
# File 'lib/voom/presenters/dsl/components/button.rb', line 13

def position
  @position
end

#sizeObject

Returns the value of attribute size.



13
14
15
# File 'lib/voom/presenters/dsl/components/button.rb', line 13

def size
  @size
end

#textObject

Returns the value of attribute text.



13
14
15
# File 'lib/voom/presenters/dsl/components/button.rb', line 13

def text
  @text
end

Instance Method Details



36
37
38
39
# File 'lib/voom/presenters/dsl/components/button.rb', line 36

def menu(**attributes, &block)
  return @menu if locked?
  @menu = Components::Menu.new(parent: self, position: menu_position, context: context, **attributes, &block)
end