Class: Primer::BaseButton

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

Overview

Use ‘BaseButton` to render an unstyled `<button>` tag that can be customized.

Constant Summary collapse

DEFAULT_TAG =
:button
TAG_OPTIONS =
[DEFAULT_TAG, :a, :summary].freeze
DEFAULT_TYPE =
:button
TYPE_OPTIONS =
[DEFAULT_TYPE, :reset, :submit].freeze

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

Instance Method Summary collapse

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

Constructor Details

#initialize(tag: DEFAULT_TAG, type: DEFAULT_TYPE, block: false, **system_arguments) ⇒ BaseButton

Returns a new instance of BaseButton.

Examples:

Block

<%= render(Primer::BaseButton.new(block: :true)) { "Block" } %>
<%= render(Primer::BaseButton.new(block: :true, scheme: :primary)) { "Primary block" } %>

Parameters:

  • tag (Symbol) (defaults to: DEFAULT_TAG)

    <%= one_of(Primer::BaseButton::TAG_OPTIONS) %>

  • type (Symbol) (defaults to: DEFAULT_TYPE)

    <%= one_of(Primer::BaseButton::TYPE_OPTIONS) %>

  • block (Boolean) (defaults to: false)

    Whether button is full-width with ‘display: block`.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/components/primer/base_button.rb', line 22

def initialize(
  tag: DEFAULT_TAG,
  type: DEFAULT_TYPE,
  block: false,
  **system_arguments
)
  @system_arguments = system_arguments
  @system_arguments[:tag] = fetch_or_fallback(TAG_OPTIONS, tag, DEFAULT_TAG)

  @system_arguments[:type] = fetch_or_fallback(TYPE_OPTIONS, type, DEFAULT_TYPE) if @system_arguments[:tag] == :button

  @system_arguments[:classes] = class_names(
    system_arguments[:classes],
    "btn-block" => block
  )
end

Instance Method Details

#callObject



39
40
41
# File 'app/components/primer/base_button.rb', line 39

def call
  render(Primer::BaseComponent.new(**@system_arguments)) { content }
end