Class: Compony::Components::Button
- Inherits:
-
Compony::Component
- Object
- Compony::Component
- Compony::Components::Button
- 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
-
#initialize(*args, label: nil, path: nil, method: nil, type: nil, enabled: nil, visible: nil, title: nil, **kwargs, &block) ⇒ Button
constructor
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.
Methods inherited from Compony::Component
#action, #before_render, #comp_cst, #comp_name, #content, #family_cst, #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(*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.[:label] @type = type&.to_sym || Compony.[:type] || :button @path = path || Compony.[:path] || 'javascript:void(0)' @method = method || Compony.[: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.[:enabled] if @enabled.nil? @enabled = true if @enabled.nil? @visible = visible @visible = Compony.[:visible] if @visible.nil? @visible = true if @visible.nil? @title = title || Compony.[:title] fail "Unsupported button type #{@type}, use on of: #{SUPPORTED_TYPES.inspect}" unless SUPPORTED_TYPES.include?(@type) super(*args, **kwargs, &block) end |