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, #content_blocks, #parent_comp

Instance Method Summary collapse

Methods inherited from Compony::Component

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

Constructor Details

#initialize(label: nil, path: nil, method: nil, type: nil, enabled: nil, visible: nil, title: nil, button_params: nil, value: nil) ⇒ 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
31
32
# File 'lib/compony/components/button.rb', line 10

def initialize(*, label: nil, path: nil, method: nil, type: nil, enabled: nil, visible: nil, title: nil, button_params: nil, value: nil, **, &)
  @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]
  @button_params = button_params
  @value = value

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

  super(*, **, &)
end