Class: Primer::ButtonComponent
- Defined in:
- app/components/primer/button_component.rb
Overview
Use buttons for actions (e.g. in forms). Use links for destinations, or moving from one page to another.
Constant Summary collapse
- DEFAULT_BUTTON_TYPE =
:default- BUTTON_TYPE_MAPPINGS =
{ DEFAULT_BUTTON_TYPE => "", :primary => "btn-primary", :danger => "btn-danger", :outline => "btn-outline" }.freeze
- BUTTON_TYPE_OPTIONS =
BUTTON_TYPE_MAPPINGS.keys
- DEFAULT_VARIANT =
:medium- VARIANT_MAPPINGS =
{ :small => "btn-sm", DEFAULT_VARIANT => "", :large => "btn-large" }.freeze
- VARIANT_OPTIONS =
VARIANT_MAPPINGS.keys
- DEFAULT_TAG =
:button- TAG_OPTIONS =
[DEFAULT_TAG, :a, :summary].freeze
- DEFAULT_TYPE =
:button- TYPE_OPTIONS =
[DEFAULT_TYPE, :reset, :submit].freeze
Constants inherited from Component
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(button_type: DEFAULT_BUTTON_TYPE, variant: DEFAULT_VARIANT, tag: DEFAULT_TAG, type: DEFAULT_TYPE, group_item: false, **system_arguments) ⇒ ButtonComponent
constructor
A new instance of ButtonComponent.
Methods inherited from Component
Methods included from ViewHelper
Methods included from JoinStyleArgumentsHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean
Methods included from ClassNameHelper
Constructor Details
#initialize(button_type: DEFAULT_BUTTON_TYPE, variant: DEFAULT_VARIANT, tag: DEFAULT_TAG, type: DEFAULT_TYPE, group_item: false, **system_arguments) ⇒ ButtonComponent
Returns a new instance of ButtonComponent.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/components/primer/button_component.rb', line 45 def initialize( button_type: DEFAULT_BUTTON_TYPE, variant: DEFAULT_VARIANT, tag: DEFAULT_TAG, type: DEFAULT_TYPE, group_item: false, **system_arguments ) @system_arguments = system_arguments @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG) if @system_arguments[:tag] == :a @system_arguments[:role] = :button else @system_arguments[:type] = type end @system_arguments[:classes] = class_names( "btn", system_arguments[:classes], BUTTON_TYPE_MAPPINGS[fetch_or_fallback(BUTTON_TYPE_OPTIONS, , DEFAULT_BUTTON_TYPE)], VARIANT_MAPPINGS[fetch_or_fallback(VARIANT_OPTIONS, variant, DEFAULT_VARIANT)], "BtnGroup-item" => group_item ) end |
Instance Method Details
#call ⇒ Object
71 72 73 |
# File 'app/components/primer/button_component.rb', line 71 def call render(Primer::BaseComponent.new(**@system_arguments)) { content } end |