Class: Primer::IconButton

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

Overview

Use ‘IconButton` to render Icon-only buttons without the default button styles.

Constant Summary collapse

DEFAULT_SCHEME =
:default
SCHEME_MAPPINGS =
{
  DEFAULT_SCHEME => "",
  :danger => "btn-octicon-danger"
}.freeze
SCHEME_OPTIONS =
SCHEME_MAPPINGS.keys

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(scheme: DEFAULT_SCHEME, icon:, **system_arguments) ⇒ IconButton

Returns a new instance of IconButton.

Examples:

Default


<%= render(Primer::IconButton.new(icon: :search, "aria-label": "Search")) %>

Schemes


<%= render(Primer::IconButton.new(icon: :search, "aria-label": "Search")) %>
<%= render(Primer::IconButton.new(icon: :trash, "aria-label": "Delete", scheme: :danger)) %>

Parameters:

  • scheme (Symbol) (defaults to: DEFAULT_SCHEME)

    <%= one_of(Primer::IconButton::SCHEME_OPTIONS) %>

  • icon (String)

    Name of <%= link_to_octicons %> to use.

  • tag (Symbol)

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

  • type (Symbol)

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

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/components/primer/icon_button.rb', line 29

def initialize(scheme: DEFAULT_SCHEME, icon:, **system_arguments)
  @icon = icon

  @system_arguments = system_arguments
  @system_arguments[:classes] = class_names(
    "btn-octicon",
    SCHEME_MAPPINGS[fetch_or_fallback(SCHEME_OPTIONS, scheme, DEFAULT_SCHEME)],
    system_arguments[:classes]
  )

  raise ArgumentError, "`aria-label` is required." if @system_arguments[:"aria-label"].nil? && !Rails.env.production?
end

Instance Method Details

#callObject



42
43
44
45
46
# File 'app/components/primer/icon_button.rb', line 42

def call
  render(Primer::BaseButton.new(**@system_arguments)) do
    render(Primer::OcticonComponent.new(icon: @icon))
  end
end