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 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(icon:, scheme: DEFAULT_SCHEME, box: false, **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)) %>

In a BorderBox


<%= render(Primer::BorderBoxComponent.new) do |component| %>
  <% component.body do %>
    <%= render(Primer::Beta::Text.new(pr: 2)) { "Body" } %>
    <%= render(Primer::IconButton.new(icon: :pencil, box: true, "aria-label": "Edit")) %>
  <% end %>
<% end %>

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) %>

  • box (Boolean) (defaults to: false)

    Whether the button is in a <%= link_to_component(Primer::BorderBoxComponent) %>. If ‘true`, the button will have the `Box-btn-octicon` class.

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/components/primer/icon_button.rb', line 45

def initialize(icon:, scheme: DEFAULT_SCHEME, box: false, **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],
    "Box-btn-octicon" => box
  )

  validate_aria_label
end

Instance Method Details

#callObject



59
60
61
62
63
# File 'app/components/primer/icon_button.rb', line 59

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