Class: Avo::Resources::Controls::BaseControl

Inherits:
Object
  • Object
show all
Defined in:
lib/avo/resources/controls/base_control.rb

Constant Summary collapse

CONTROL_OPTIONS =

Keys the control consumes itself, either as an option it renders from (style, icon…) or as internal plumbing merged in by execute_block (as_index_control, item…). Everything a user passes outside this list is forwarded to the rendered element as an HTML attribute, so link_to "Docs", url, rel: "noopener" reaches the <a> tag.

%i[
  label path title target data class
  style color size icon icon_class confirmation_message
  as_index_control from_custom_list item
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ BaseControl

Returns a new instance of BaseControl.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/avo/resources/controls/base_control.rb', line 20

def initialize(**args)
  @label = args[:label]
  @title = args[:title]
  @color = args[:color] || :gray
  @style = args[:style] || :text
  @icon = args[:icon]
  @icon_class = (@style == :icon) ? " text-gray-600 h-6 hover:text-gray-600" : ""
  @confirmation_message = args[:confirmation_message]
  @size = args[:size] || :md
  @as_index_control = args[:as_index_control]
end

Instance Attribute Details

#as_index_controlObject (readonly)

Returns the value of attribute as_index_control.



18
19
20
# File 'lib/avo/resources/controls/base_control.rb', line 18

def as_index_control
  @as_index_control
end

#colorObject (readonly)

Returns the value of attribute color.



18
19
20
# File 'lib/avo/resources/controls/base_control.rb', line 18

def color
  @color
end

#confirmation_messageObject (readonly)

Returns the value of attribute confirmation_message.



18
19
20
# File 'lib/avo/resources/controls/base_control.rb', line 18

def confirmation_message
  @confirmation_message
end

#iconObject (readonly)

Returns the value of attribute icon.



18
19
20
# File 'lib/avo/resources/controls/base_control.rb', line 18

def icon
  @icon
end

#icon_classObject (readonly)

Returns the value of attribute icon_class.



18
19
20
# File 'lib/avo/resources/controls/base_control.rb', line 18

def icon_class
  @icon_class
end

#labelObject (readonly)

Returns the value of attribute label.



18
19
20
# File 'lib/avo/resources/controls/base_control.rb', line 18

def label
  @label
end

#sizeObject (readonly)

Returns the value of attribute size.



18
19
20
# File 'lib/avo/resources/controls/base_control.rb', line 18

def size
  @size
end

#styleObject (readonly)

Returns the value of attribute style.



18
19
20
# File 'lib/avo/resources/controls/base_control.rb', line 18

def style
  @style
end

#titleObject (readonly)

Returns the value of attribute title.



18
19
20
# File 'lib/avo/resources/controls/base_control.rb', line 18

def title
  @title
end

Instance Method Details

#typeObject



32
33
34
# File 'lib/avo/resources/controls/base_control.rb', line 32

def type
  self.class.name.demodulize.underscore.to_sym
end