Class: Compony::Components::Button

Inherits:
Compony::Component show all
Defined in:
lib/compony/components/button.rb

Overview

This is the default button implementation, providing a minimal button

Constant Summary collapse

SUPPORTED_TYPES =
%i[button submit].freeze

Instance Attribute Summary

Attributes inherited from Compony::Component

#comp_opts, #parent_comp

Instance Method Summary collapse

Methods inherited from Compony::Component

#action, #add_content, #before_render, #comp_class_for, #comp_class_for!, #comp_cst, #comp_name, #content, #family_cst, #family_name, #id, #inspect, #param_name, #path, #path_hash, #render, #render_actions, #resourceful?, #root_comp, #root_comp?, setup, #skip_action, #sub_comp

Constructor Details

#initialize(*args, label: nil, path: nil, method: nil, type: nil, enabled: nil, visible: nil, title: nil, **kwargs, &block) ⇒ Button

path: If given a block, it will be evaluated in the helpers context when rendering enabled: If given a block, it will be evaluated in the helpers context when rendering



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/compony/components/button.rb', line 10

def initialize(*args, label: nil, path: nil, method: nil, type: nil, enabled: nil, visible: nil, title: nil, **kwargs, &block)
  @label = label || Compony.button_defaults[:label]
  @type = type&.to_sym || Compony.button_defaults[:type] || :button
  @path = path || Compony.button_defaults[:path] || 'javascript:void(0)'
  @method = method || Compony.button_defaults[:method]
  if @type != :button && !@method.nil?
    fail("Param `method` is only allowed for :button type buttons, but got method #{@method.inspect} for type #{@type.inspect}")
  end
  @method ||= :get
  @enabled = enabled
  @enabled = Compony.button_defaults[:enabled] if @enabled.nil?
  @enabled = true if @enabled.nil?
  @visible = visible
  @visible = Compony.button_defaults[:visible] if @visible.nil?
  @visible = true if @visible.nil?
  @title = title || Compony.button_defaults[:title]

  fail "Unsupported button type #{@type}, use on of: #{SUPPORTED_TYPES.inspect}" unless SUPPORTED_TYPES.include?(@type)

  super(*args, **kwargs, &block)
end