Class: Polaris::Navigation::ItemComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/navigation/item_component.rb

Defined Under Namespace

Classes: SecondaryActionComponent

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, label:, icon: nil, badge: nil, selected: false, disabled: false, external: false, link_arguments: {}, **system_arguments) ⇒ ItemComponent

Returns a new instance of ItemComponent.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/components/polaris/navigation/item_component.rb', line 7

def initialize(
  url:,
  label:,
  icon: nil,
  badge: nil,
  selected: false,
  disabled: false,
  external: false,
  link_arguments: {},
  **system_arguments
)
  @url = url
  @label = label
  @icon = icon
  @badge = badge
  @selected = selected
  @disabled = disabled
  @external = external
  @system_arguments = system_arguments
  @link_arguments = link_arguments
end

Instance Attribute Details

#selectedObject (readonly)

Returns the value of attribute selected.



5
6
7
# File 'app/components/polaris/navigation/item_component.rb', line 5

def selected
  @selected
end

Instance Method Details



39
40
41
42
43
44
45
46
47
48
# File 'app/components/polaris/navigation/item_component.rb', line 39

def link_arguments
  @link_arguments.tap do |opts|
    opts[:class] = class_names(
      @link_arguments[:classes],
      link_classes
    )
    opts[:tabindex] = "0"
    opts[:target] = "_blank" if @external
  end
end


50
51
52
53
54
55
56
57
# File 'app/components/polaris/navigation/item_component.rb', line 50

def link_classes
  class_names(
    "Polaris-Navigation__Item",
    "Polaris-Navigation__Item--selected": @selected,
    "Polaris-Navigation--subNavigationActive": @selected || selected_sub_items?,
    "Polaris-Navigation__Item--disabled": @disabled
  )
end

#selected_sub_items?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
# File 'app/components/polaris/navigation/item_component.rb', line 59

def selected_sub_items?
  return unless sub_items.present?

  sub_items.any?(&:selected)
end

#system_argumentsObject



29
30
31
32
33
34
35
36
37
# File 'app/components/polaris/navigation/item_component.rb', line 29

def system_arguments
  @system_arguments.tap do |opts|
    opts[:tag] = "li"
    opts[:classes] = class_names(
      @system_arguments[:classes],
      "Polaris-Navigation__ListItem"
    )
  end
end