Class: Primer::OpenProject::SubHeader::Button

Inherits:
Component
  • Object
show all
Defined in:
app/components/primer/open_project/sub_header/button.rb

Overview

A Helper class to create a Button with required icon inside the SubHeader action slot Do not use standalone

Constant Summary

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

Returns a new instance of Button.

Parameters:

  • icon (Symbol)

    The name of an <%= link_to_octicons %> icon to use as leading visual

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



16
17
18
19
# File 'app/components/primer/open_project/sub_header/button.rb', line 16

def initialize(icon:, **system_arguments)
  @icon = icon
  @button = Primer::Beta::Button.new(**system_arguments)
end

Instance Method Details

#before_renderObject



28
29
30
31
32
33
# File 'app/components/primer/open_project/sub_header/button.rb', line 28

def before_render
  if leading_visual_icon.present?
    raise ArgumentError,
          "Do not use the leading_visual_icon slot within the SubHeader, as it is reserved. Instead provide a leading_icon within the subHeader button slot"
  end
end

#callObject



35
36
37
38
39
40
# File 'app/components/primer/open_project/sub_header/button.rb', line 35

def call
  render(@button) do |button|
    button.with_leading_visual_icon(icon: @icon)
    content
  end
end