Class: Primer::Alpha::SegmentedControl::Item

Inherits:
BaseComponent show all
Defined in:
app/components/primer/alpha/segmented_control/item.rb

Overview

SegmentedControl::Item is a private component that is only used by SegmentedControl It wraps the Button and IconButton components to provide the correct styles

Constant Summary

Constants inherited from BaseComponent

BaseComponent::SELF_CLOSING_TAGS

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 Primer::AttributesHelper

Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::AttributesHelper::PLURAL_DATA_ATTRIBUTES

Instance Method Summary collapse

Methods inherited from BaseComponent

#call

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 Primer::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(label:, selected: false, icon: nil, hide_labels: false, **system_arguments) ⇒ Item



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/components/primer/alpha/segmented_control/item.rb', line 16

def initialize(
  label:,
  selected: false,
  icon: nil,
  hide_labels: false,
  **system_arguments
)
  @selected = selected

  @system_arguments = system_arguments
  @system_arguments[:"data-action"] = "click:segmented-control#select" if system_arguments[:href].nil?
  @system_arguments[:"aria-current"] = selected
  @system_arguments[:scheme] = :invisible

  if hide_labels
    @button = Primer::Beta::IconButton.new(
      icon: icon,
      "aria-label": label,
      **@system_arguments
    )
  else
    @button = Primer::Beta::Button.new(**@system_arguments)
    @button.with_leading_visual_icon(icon: icon) if icon
    @button.with_content(label)
  end
end

Instance Method Details

#with_trailing_visual_label(**system_arguments, &block) ⇒ Object

Optional trailing label.



52
53
54
# File 'app/components/primer/alpha/segmented_control/item.rb', line 52

def with_trailing_visual_label(**system_arguments, &block)
  @button.with_trailing_visual_label(**system_arguments, &block)
end