Class: Primer::ButtonGroup

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

Overview

Use ‘ButtonGroup` to render a series of buttons.

Constant Summary

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(variant: Primer::ButtonComponent::DEFAULT_VARIANT, **system_arguments) ⇒ ButtonGroup

Returns a new instance of ButtonGroup.

Examples:

Default


<%= render(Primer::ButtonGroup.new) do |component| %>
  <% component.button { "Default" } %>
  <% component.button(scheme: :primary) { "Primary" } %>
  <% component.button(scheme: :danger) { "Danger" } %>
  <% component.button(scheme: :outline) { "Outline" } %>
  <% component.button(classes: "my-class") { "Custom class" } %>
<% end %>

Variants


<%= render(Primer::ButtonGroup.new(variant: :small)) do |component| %>
  <% component.button { "Default" } %>
  <% component.button(scheme: :primary) { "Primary" } %>
  <% component.button(scheme: :danger) { "Danger" } %>
  <% component.button(scheme: :outline) { "Outline" } %>
<% end %>

<%= render(Primer::ButtonGroup.new(variant: :large)) do |component| %>
  <% component.button { "Default" } %>
  <% component.button(scheme: :primary) { "Primary" } %>
  <% component.button(scheme: :danger) { "Danger" } %>
  <% component.button(scheme: :outline) { "Outline" } %>
<% end %>

Parameters:

  • variant (Symbol) (defaults to: Primer::ButtonComponent::DEFAULT_VARIANT)

    <%= one_of(Primer::ButtonComponent::VARIANT_OPTIONS) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



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

def initialize(variant: Primer::ButtonComponent::DEFAULT_VARIANT, **system_arguments)
  @variant = variant
  @system_arguments = system_arguments
  @system_arguments[:tag] ||= :div

  @system_arguments[:classes] = class_names(
    "BtnGroup",
    system_arguments[:classes]
  )
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'app/components/primer/button_group.rb', line 57

def render?
  buttons.any?
end