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

Inherits:
BaseComponent
  • Object
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

Instance Method Summary collapse

Methods inherited from BaseComponent

#call

Constructor Details

#initialize(label:, selected: false, icon: nil, hide_labels: false, **system_arguments) ⇒ Item

Returns a new instance of Item.

Parameters:

  • label (String)

    The label to use

  • selected (Boolean) (defaults to: false)

    Whether the item is selected

  • icon (Symbol) (defaults to: nil)

    The icon to use

  • hide_labels (Symbol) (defaults to: false)

    Whether to only show the icon



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.

Parameters:

  • system_arguments (Hash)

    The arguments accepted by <%= link_to_component(Primer::Beta::Button) %>'s with_trailing_visual_label slot.



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