Class: Primer::ButtonComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/button_component.rb

Overview

Use ‘Button` for actions (e.g. in forms). Use links for destinations, or moving from one page to another.

Constant Summary collapse

DEFAULT_SCHEME =
:default
:link
SCHEME_MAPPINGS =
{
  DEFAULT_SCHEME => "",
  :primary => "btn-primary",
  :danger => "btn-danger",
  :outline => "btn-outline",
  :invisible => "btn-invisible",
  LINK_SCHEME => "btn-link"
}.freeze
SCHEME_OPTIONS =
SCHEME_MAPPINGS.keys
DEFAULT_SIZE =
:medium
SIZE_MAPPINGS =
{
  :small => "btn-sm",
  DEFAULT_SIZE => ""
}.freeze
SIZE_OPTIONS =
SIZE_MAPPINGS.keys

Constants inherited from Component

Component::INVALID_ARIA_LABEL_TAGS

Constants included from Status::Dsl

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Constants included from AttributesHelper

AttributesHelper::PLURAL_ARIA_ATTRIBUTES, AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Methods included from AttributesHelper

#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes

Methods included from ExperimentalSlotHelpers

included

Methods included from ExperimentalRenderHelpers

included

Constructor Details

#initialize(scheme: DEFAULT_SCHEME, variant: nil, size: DEFAULT_SIZE, group_item: false, block: false, dropdown: false, **system_arguments) ⇒ ButtonComponent



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/components/primer/button_component.rb', line 83

def initialize(
  scheme: DEFAULT_SCHEME,
  variant: nil,
  size: DEFAULT_SIZE,
  group_item: false,
  block: false,
  dropdown: false,
  **system_arguments
)
  @scheme = scheme
  @dropdown = dropdown

  @system_arguments = system_arguments

  @id = @system_arguments[:id]

  @system_arguments[:classes] = class_names(
    system_arguments[:classes],
    SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)],
    SIZE_MAPPINGS[fetch_or_fallback(SIZE_OPTIONS, variant || size, DEFAULT_SIZE)],
    "btn" => !link?,
    "btn-block" => block,
    "BtnGroup-item" => group_item
  )
end